pthread_mutex_timedlock.c

00001 int pthread_mutex_timedlock(pthread_mutex_t *restrict mutex, const struct timespec *restrict abs_timeout)
00002 {
00003 int result;
00004 do
00005 {
00006 result = pthread_mutex_trylock(&mutex);
00007 if (result == EBUSY)
00008 {
00009 timespec ts;
00010 ts.tv_sec = 0;
00011 ts.tv_sec = 10000000;
00012 
00013 /* Sleep for 10,000,000 nanoseconds before trying again. */
00014 int status = -1;
00015 while (status == -1)
00016 status = nanosleep(&ts, &ts);
00017 }
00018 else
00019 break;
00020 }
00021 while (result != 0 and (abs_timeout is 0 or the timeout time has passed));
00022 
00023     return result;
00024 }

mcslogo

MCS (My Customizable Server) ver. 0.3.3-alpha3
Documentation generated on Thu Mar 22 13:22:23 UTC 2012