diff options
| author | John Baldwin <jhb@FreeBSD.org> | 2013-12-28 03:21:15 +0000 |
|---|---|---|
| committer | John Baldwin <jhb@FreeBSD.org> | 2013-12-28 03:21:15 +0000 |
| commit | cf952fe8418a858be13f0e7a41dba62b69dc258e (patch) | |
| tree | bf52cc409287d909df2c8adca96a4fb8863c39c6 | |
| parent | 93f7e978f6f161443d8af3afa9aef5e052cd52d9 (diff) | |
Notes
| -rw-r--r-- | usr.sbin/bhyve/pmtmr.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/usr.sbin/bhyve/pmtmr.c b/usr.sbin/bhyve/pmtmr.c index c8fbd623d0a1..187a4dd8ede8 100644 --- a/usr.sbin/bhyve/pmtmr.c +++ b/usr.sbin/bhyve/pmtmr.c @@ -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); |
