From 390422241efc917545c9acc9ddda8c55499c5f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 21 Nov 2006 23:20:41 +0000 Subject: [PATCH] Small optimization of the timer mechanism: the timeout is no longer updated if not really necessary; ie. you can now add timers without an extra performance hit if it's not really required. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19354 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/network/stack/utility.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/add-ons/kernel/network/stack/utility.cpp b/src/add-ons/kernel/network/stack/utility.cpp index 75c32368fb..dcc54f2b01 100644 --- a/src/add-ons/kernel/network/stack/utility.cpp +++ b/src/add-ons/kernel/network/stack/utility.cpp @@ -21,6 +21,7 @@ static struct list sTimers; static benaphore sTimerLock; static sem_id sTimerWaitSem; static thread_id sTimerThread; +static bigtime_t sTimerTimeout; uint16 @@ -256,6 +257,7 @@ timer_thread(void * /*data*/) } } + sTimerTimeout = timeout; benaphore_unlock(&sTimerLock); } @@ -307,10 +309,11 @@ set_timer(net_timer *timer, bigtime_t delay) // add this timer timer->due = system_time() + delay; list_add_item(&sTimers, timer); - } - // notify timer about the change - release_sem(sTimerWaitSem); + // notify timer about the change if necessary + if (sTimerTimeout > timer->due) + release_sem(sTimerWaitSem); + } } @@ -318,6 +321,7 @@ status_t init_timers(void) { list_init(&sTimers); + sTimerTimeout = B_INFINITE_TIMEOUT; status_t status = benaphore_init(&sTimerLock, "net timer"); if (status < B_OK)