muimaster.library: support Listview_List in List
[AROS.git] / compiler / posixc / nanosleep.c
bloba77d96808faec3b7962a20a34715c5fd026767aa
1 /*
2 Copyright © 2008-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX.1-2008 function nanosleep().
6 */
7 #include <exec/exec.h>
8 #include <proto/exec.h>
9 #include <devices/timer.h>
11 #include <unistd.h>
13 /*****************************************************************************
15 NAME */
16 #include <time.h>
18 int nanosleep (
20 /* SYNOPSIS */
21 const struct timespec * req, struct timespec *rem)
23 /* FUNCTION
24 Suspends program execution for a given number of nanoseconds.
26 INPUTS
27 req - time to wait
28 rem - remaining time, if nanosleep was interrupted by a signal
30 RESULT
31 0 on success, -1 on error
33 NOTES
34 Currently at most a resolution of milliseconds is supported.
36 EXAMPLE
38 BUGS
40 SEE ALSO
42 INTERNALS
44 ******************************************************************************/
46 struct MsgPort *timerMsgPort;
47 struct timerequest *timerIO;
48 int retval = -1;
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));
54 if(timerIO)
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);
63 retval = 0;
65 if (rem)
67 rem->tv_sec = 0;
68 rem->tv_nsec = 0;
71 CloseDevice((struct IORequest *) timerIO);
73 DeleteIORequest((struct IORequest *) timerIO);
75 DeleteMsgPort(timerMsgPort);
77 return retval;
78 } /* nanosleep() */