NetBSD-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
sem_timedwait()
Hi,
I´m having trouble because sem_timedwait() isn´t part of NetBSD. I
found a patch* as a workaround from the glusterfs port. Has someone
scheduled this function for a later NetBSD release?
Regards,
Stephan
*
+#ifdef __NetBSD__
+static inline int sem_timedwait(sem_t *sem, struct timespec *ts) {
+ struct timespec onems = { 0, 1000000 };
+ struct timespec total = { 0, 0 };
+ struct timespec unslept;
+ struct timespec elapsed;
+ struct timespec tmp;
+
+ while (timespeccmp(ts, &total, >)) {
+ if (sem_trywait(sem) == 0)
+ return 0;
+
+ if (errno != EAGAIN)
+ return -1;
+
+ (void)nanosleep(&onems, &unslept);
+
+ timespecsub(&onems, &unslept, &elapsed);
+ timespecadd(&total, &elapsed, &tmp);
+ total.tv_sec = tmp.tv_sec;
+ total.tv_nsec = tmp.tv_nsec;
+ }
+
+ errno = ETIMEDOUT;
+ return -1;
+}
+#endif /* __NetBSD__ */
Home |
Main Index |
Thread Index |
Old Index