[haiku-commits] r41825 - haiku/branches/developer/bonefish/signals/src/system/libroot/os

  • From: ingo_weinhold@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 30 May 2011 00:49:22 +0200 (CEST)

Author: bonefish
Date: 2011-05-30 00:49:21 +0200 (Mon, 30 May 2011)
New Revision: 41825
Changeset: https://dev.haiku-os.org/changeset/41825

Modified:
   haiku/branches/developer/bonefish/signals/src/system/libroot/os/time.cpp
Log:
set_alarm(): Reimplemented using _kern_set_timer() instead of
_kern_set_alarm().


Modified: 
haiku/branches/developer/bonefish/signals/src/system/libroot/os/time.cpp
===================================================================
--- haiku/branches/developer/bonefish/signals/src/system/libroot/os/time.cpp    
2011-05-29 22:47:23 UTC (rev 41824)
+++ haiku/branches/developer/bonefish/signals/src/system/libroot/os/time.cpp    
2011-05-29 22:49:21 UTC (rev 41825)
@@ -15,6 +15,7 @@
 #include <commpage_defs.h>
 #include <libroot_private.h>
 #include <real_time_data.h>
+#include <user_timer_defs.h>
 #include <syscalls.h>
 
 
@@ -78,5 +79,42 @@
 bigtime_t
 set_alarm(bigtime_t when, uint32 mode)
 {
-       return _kern_set_alarm(when, mode);
+       bigtime_t baseTime = system_time();
+
+       // init the info to be passed to the kernel
+       user_timer_info info;
+       if (when == B_INFINITE_TIMEOUT) {
+               info.next_time = B_INFINITE_TIMEOUT;
+               info.interval = 0;
+       } else {
+               switch (mode) {
+                       case B_PERIODIC_ALARM:
+                               info.next_time = baseTime + when;
+                               info.interval = when;
+                               break;
+                       case B_ONE_SHOT_ABSOLUTE_ALARM:
+                               info.next_time = when;
+                               info.interval = 0;
+                               break;
+                       case B_ONE_SHOT_RELATIVE_ALARM:
+                       default:
+                               info.next_time = baseTime + when;
+                               info.interval = 0;
+                               break;
+               }
+       }
+
+       // set the timer
+       user_timer_info oldInfo;
+       status_t error = _kern_set_timer(USER_TIMER_REAL_TIME_ID, 
find_thread(NULL),
+               &info, &oldInfo);
+
+       // compute the return value, the time remaining for the previously 
scheduled
+       // timer
+       bigtime_t oldTime = oldInfo.next_time;
+       if (oldTime == B_INFINITE_TIMEOUT)
+               return 0;
+
+       oldTime -= baseTime;
+       return oldTime < 0 ? 0 : oldTime;
 }


Other related posts:

  • » [haiku-commits] r41825 - haiku/branches/developer/bonefish/signals/src/system/libroot/os - ingo_weinhold