Author: jhb
Date: Sat Dec 28 03:21:15 2013
New Revision: 259997
URL: http://svnweb.freebsd.org/changeset/base/259997

Log:
  Use pthread_once() to replace a static integer initted flag.
  
  Reviewed by:  neel

Modified:
  head/usr.sbin/bhyve/pmtmr.c

Modified: head/usr.sbin/bhyve/pmtmr.c
==============================================================================
--- head/usr.sbin/bhyve/pmtmr.c Sat Dec 28 03:11:09 2013        (r259996)
+++ head/usr.sbin/bhyve/pmtmr.c Sat Dec 28 03:21:15 2013        (r259997)
@@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$");
 #define PMTMR_FREQ     3579545  /* 3.579545MHz */
 
 static pthread_mutex_t pmtmr_mtx;
+static pthread_once_t pmtmr_once = PTHREAD_ONCE_INIT;
 
 static uint64_t        pmtmr_old;
 
@@ -123,6 +124,7 @@ pmtmr_init(void)
                pmtmr_uptime_old = tsnew;
                pmtmr_old = timespec_to_pmtmr(&tsnew, &tsold);
        }
+       pthread_mutex_init(&pmtmr_mtx, NULL);
 }
 
 static uint32_t
@@ -133,13 +135,7 @@ pmtmr_val(void)
        uint64_t        pmtmr_new;
        int             error;
 
-       static int      inited = 0;
-
-       if (!inited) {
-               pthread_mutex_init(&pmtmr_mtx, NULL);
-               pmtmr_init();
-               inited = 1;
-       }
+       pthread_once(&pmtmr_once, pmtmr_init);
 
        pthread_mutex_lock(&pmtmr_mtx);
 
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to