]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Force usage of virThreadCreate
authorJiri Denemark <jdenemar@redhat.com>
Fri, 20 Mar 2015 15:25:15 +0000 (16:25 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 25 Mar 2015 09:00:53 +0000 (10:00 +0100)
We want all threads to be set as workers or to have a job assigned to
them, which can easily be achieved in virThreadCreate wrapper to
pthread_create. Let's make sure we always use the wrapper.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
cfg.mk
src/nwfilter/nwfilter_learnipaddr.c
src/nwfilter/nwfilter_learnipaddr.h

diff --git a/cfg.mk b/cfg.mk
index 6885f9e0f3781fa7346a90b30abf2e61303153f1..661cccc8fa6d855329ada0b7165c84ff2d40613d 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -999,6 +999,12 @@ sc_prohibit_sysconf_pagesize:
        halt='use virGetSystemPageSize[KB] instead of sysconf(_SC_PAGESIZE)' \
          $(_sc_search_regexp)
 
+sc_prohibit_pthread_create:
+       @prohibit='\bpthread_create\b' \
+       exclude='sc_prohibit_pthread_create' \
+       halt="avoid using 'pthread_create', use 'virThreadCreate' instead" \
+         $(_sc_search_regexp)
+
 # We don't use this feature of maint.mk.
 prev_version_file = /dev/null
 
@@ -1192,3 +1198,6 @@ exclude_file_name_regexp--sc_prohibit_virXXXFree = \
 
 exclude_file_name_regexp--sc_prohibit_sysconf_pagesize = \
   ^(cfg\.mk|src/util/virutil\.c)$$
+
+exclude_file_name_regexp--sc_prohibit_pthread_create = \
+  ^(cfg\.mk|src/util/virthread\.c|tests/.*)$$
index 1b875c3ebede552a94d08ce379475e63a2afef34..5b5505538f430bd6e31d6353ba8b3c073e654f8c 100644 (file)
@@ -374,7 +374,7 @@ procDHCPOpts(struct dhcp *dhcp, int dhcp_opts_len,
  * will require that the IP address was taken from an ARP packet or an IPv4
  * packet. Both flags can be set at the same time.
  */
-static void *
+static void
 learnIPAddressThread(void *arg)
 {
     char errbuf[PCAP_ERRBUF_SIZE] = {0};
@@ -638,8 +638,6 @@ learnIPAddressThread(void *arg)
         techdriver->applyDropAllRules(req->ifname);
     }
 
-    memset(&req->thread, 0x0, sizeof(req->thread));
-
     VIR_DEBUG("pcap thread terminating for interface %s\n", req->ifname);
 
     virNWFilterUnlockIface(req->ifname);
@@ -648,8 +646,6 @@ learnIPAddressThread(void *arg)
     virNWFilterDeregisterLearnReq(req->ifindex);
 
     virNWFilterIPAddrLearnReqFree(req);
-
-    return 0;
 }
 
 
@@ -686,6 +682,7 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
                           enum howDetect howDetect)
 {
     int rc;
+    virThread thread;
     virNWFilterIPAddrLearnReqPtr req = NULL;
     virNWFilterHashTablePtr ht = NULL;
 
@@ -742,10 +739,10 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
     if (rc < 0)
         goto err_free_req;
 
-    if (pthread_create(&req->thread,
-                       NULL,
-                       learnIPAddressThread,
-                       req) != 0)
+    if (virThreadCreate(&thread,
+                        false,
+                        learnIPAddressThread,
+                        req) != 0)
         goto err_dereg_req;
 
     return 0;
index 1cc881a7820057da91957e54ddd8c4f10b292563..b93ed38cff11854662ba8debe6f6fa8dc1915d93 100644 (file)
@@ -49,7 +49,6 @@ struct _virNWFilterIPAddrLearnReq {
     enum howDetect howDetect;
 
     int status;
-    pthread_t thread;
     volatile bool terminate;
 };