From 6c76785bef595b1b4e15a13831d57005f0b274c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20G=C3=BCnther?= Date: Tue, 27 Oct 2009 17:09:53 +0000 Subject: [PATCH] Using the add_timer() function as proposed by alexd. Thanks. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33791 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/libs/compat/freebsd_network/clock.c | 62 +++++++------------------ 1 file changed, 18 insertions(+), 44 deletions(-) diff --git a/src/libs/compat/freebsd_network/clock.c b/src/libs/compat/freebsd_network/clock.c index 2543ac8a4b..4637ca4603 100644 --- a/src/libs/compat/freebsd_network/clock.c +++ b/src/libs/compat/freebsd_network/clock.c @@ -12,61 +12,38 @@ int ticks; -static sem_id sHardClockSem; -static thread_id sHardClockThread; +static timer sHardClockTimer; /*! * Implementation of FreeBSD's hardclock timer. + */ +static status_t +hardClock(timer* hardClockTimer) +{ + atomic_add((vint32*)&ticks, 1); + return B_OK; +} + + +/*! + * Initialization of the hardclock timer. * * Note: We are not using the FreeBSD variable hz as the invocation frequency * as it is the case in FreeBSD's hardclock function. This is due to lower * system load. The hz (see compat/sys/kernel.h) variable in the compat layer is * set to 1000000 Hz, whereas it is usually set to 1000 Hz for FreeBSD. */ -static status_t -hard_clock_thread(void* data) -{ - status_t status = B_OK; - const bigtime_t duration - = CONVERT_HZ_TO_USECS(FREEBSD_CLOCK_FREQUENCY_IN_HZ); - - do { - bigtime_t timeout = system_time() + duration; - status = acquire_sem_etc(sHardClockSem, 1, B_ABSOLUTE_TIMEOUT, timeout); - - if (system_time() >= timeout) { - atomic_add((vint32*)&ticks, 1); - } - } while (status != B_BAD_SEM_ID); - - return status; -} - - status_t init_hard_clock() { - status_t status = B_OK; + status_t status; - sHardClockSem = create_sem(0, "hard clock wait"); - if (sHardClockSem < B_OK) { - status = sHardClockSem; - goto error1; - } + ticks = 0; + status = add_timer(&sHardClockTimer, hardClock, + CONVERT_HZ_TO_USECS(FREEBSD_CLOCK_FREQUENCY_IN_HZ), + B_PERIODIC_TIMER); - sHardClockThread = spawn_kernel_thread(hard_clock_thread, "hard clock", - B_NORMAL_PRIORITY, NULL); - if (sHardClockThread < B_OK) { - status = sHardClockThread; - goto error2; - } - - return resume_thread(sHardClockThread); - -error2: - delete_sem(sHardClockSem); -error1: return status; } @@ -74,8 +51,5 @@ error1: void uninit_hard_clock() { - status_t status; - - delete_sem(sHardClockSem); - wait_for_thread(sHardClockThread, &status); + cancel_timer(&sHardClockTimer); }