]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
host: convert use_cnt to a atomic var (like in flow).
authorVictor Julien <victor@inliniac.net>
Fri, 30 Mar 2012 12:47:45 +0000 (14:47 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 30 Mar 2012 12:47:45 +0000 (14:47 +0200)
src/host-timeout.c
src/host.c
src/host.h

index 21b33c168325de207529adce911892ac45876092..a544f10b68ef8fd34a20a73a54f7dd8d0395b862 100644 (file)
@@ -50,7 +50,7 @@ static int HostHostTimedOut(Host *h, struct timeval *ts) {
 
     /** never prune a host that is used by a packet
      *  we are currently processing in one of the threads */
-    if (h->use_cnt > 0) {
+    if (SC_ATOMIC_GET(h->use_cnt) > 0) {
         return 0;
     }
 
index d1694d9c4222f781e047f3246bdea1663333dd16..8fc9fe55471a34ec19dba6c9069c8dceafe6d00e 100644 (file)
@@ -68,6 +68,7 @@ Host *HostAlloc(void) {
     memset(h, 0x00, sizeof(Host));
 
     SCMutexInit(&h->m, NULL);
+    SC_ATOMIC_INIT(h->use_cnt);
     return h;
 
 error:
@@ -107,6 +108,7 @@ void HostClearMemory(Host *h) {
         ThresholdListFree(h->threshold);
         h->threshold = NULL;
     }
+    SC_ATOMIC_DESTROY(h->use_cnt);
 }
 
 #define HOST_DEFAULT_HASHSIZE 4096
@@ -248,7 +250,7 @@ void HostShutdown(void)
 
     /* free spare queue */
     while((h = HostDequeue(&host_spare_q))) {
-        BUG_ON(h->use_cnt > 0);
+        BUG_ON(SC_ATOMIC_GET(h->use_cnt) > 0);
         HostFree(h);
     }
 
@@ -361,9 +363,9 @@ static Host *HostGetNew(Address *a) {
 }
 
 #define HostIncrUsecnt(h) \
-    (h)->use_cnt++
+    SC_ATOMIC_ADD((h)->use_cnt, 1)
 #define HostDecrUsecnt(h) \
-    (h)->use_cnt--
+    SC_ATOMIC_SUB((h)->use_cnt, 1)
 
 void HostInit(Host *h, Address *a) {
     COPY_ADDRESS(a, &h->a);
@@ -584,7 +586,7 @@ static Host *HostGetUsedHost(void) {
 
         /** never prune a host that is used by a packets
          *  we are currently processing in one of the threads */
-        if (h->use_cnt > 0) {
+        if (SC_ATOMIC_GET(h->use_cnt) > 0) {
             HRLOCK_UNLOCK(hb);
             SCMutexUnlock(&h->m);
             continue;
index e3610b81294509d2c98ea6abb34a273273a9cee3..a4634bf49937de401bd79051045c10465364ea3c 100644 (file)
@@ -62,7 +62,7 @@ typedef struct Host_ {
     Address a;
 
     /** use cnt, reference counter */
-    uint16_t use_cnt;
+    SC_ATOMIC_DECLARE(unsigned short, use_cnt);
 
     /** pointers to tag and threshold storage */
     void *tag;