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
This commit is contained in:
@@ -12,61 +12,38 @@
|
|||||||
|
|
||||||
|
|
||||||
int ticks;
|
int ticks;
|
||||||
static sem_id sHardClockSem;
|
static timer sHardClockTimer;
|
||||||
static thread_id sHardClockThread;
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Implementation of FreeBSD's hardclock timer.
|
* 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
|
* 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
|
* 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
|
* 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.
|
* 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
|
status_t
|
||||||
init_hard_clock()
|
init_hard_clock()
|
||||||
{
|
{
|
||||||
status_t status = B_OK;
|
status_t status;
|
||||||
|
|
||||||
sHardClockSem = create_sem(0, "hard clock wait");
|
ticks = 0;
|
||||||
if (sHardClockSem < B_OK) {
|
status = add_timer(&sHardClockTimer, hardClock,
|
||||||
status = sHardClockSem;
|
CONVERT_HZ_TO_USECS(FREEBSD_CLOCK_FREQUENCY_IN_HZ),
|
||||||
goto error1;
|
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;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,8 +51,5 @@ error1:
|
|||||||
void
|
void
|
||||||
uninit_hard_clock()
|
uninit_hard_clock()
|
||||||
{
|
{
|
||||||
status_t status;
|
cancel_timer(&sHardClockTimer);
|
||||||
|
|
||||||
delete_sem(sHardClockSem);
|
|
||||||
wait_for_thread(sHardClockThread, &status);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user