2 Copyright © 2008-2012, The AROS Development Team. All rights reserved.
5 POSIX.1-2008 function nanosleep().
8 #include <proto/exec.h>
9 #include <devices/timer.h>
13 /*****************************************************************************
21 const struct timespec
* req
, struct timespec
*rem
)
24 Suspends program execution for a given number of nanoseconds.
28 rem - remaining time, if nanosleep was interrupted by a signal
31 0 on success, -1 on error
34 Currently at most a resolution of milliseconds is supported.
44 ******************************************************************************/
46 struct MsgPort
*timerMsgPort
;
47 struct timerequest
*timerIO
;
50 /* FIXME: share TimerBase with gettimeofday and don't open/close it for each usleep call */
51 if((timerMsgPort
= CreateMsgPort()))
53 timerIO
= (struct timerequest
*) CreateIORequest(timerMsgPort
, sizeof (struct timerequest
));
56 if(OpenDevice("timer.device", UNIT_MICROHZ
, (struct IORequest
*) timerIO
, 0) == 0)
58 timerIO
->tr_node
.io_Command
= TR_ADDREQUEST
;
59 timerIO
->tr_time
.tv_secs
= req
->tv_sec
;
60 timerIO
->tr_time
.tv_micro
= (req
->tv_nsec
+500)/1000;
62 DoIO((struct IORequest
*) timerIO
);
71 CloseDevice((struct IORequest
*) timerIO
);
73 DeleteIORequest((struct IORequest
*) timerIO
);
75 DeleteMsgPort(timerMsgPort
);