svn commit: r259997 - head/usr.sbin/bhyve

John Baldwin jhb at FreeBSD.org
Sat Dec 28 03:21:16 UTC 2013


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);
 


More information about the svn-src-head mailing list