1/* 2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7#include <signal.h> 8 9#include <errno.h> 10#include <pthread.h> 11 12#include <syscall_utils.h> 13 14#include <errno_private.h> 15#include <syscalls.h> 16 17 18int 19sigtimedwait(const sigset_t* set, siginfo_t* info, 20 const struct timespec* timeout) 21{ 22 // make info non-NULL to simplify things 23 siginfo_t stackInfo; 24 if (info == NULL) 25 info = &stackInfo; 26 27 // translate the timeout 28 uint32 flags; 29 bigtime_t timeoutMicros; 30 if (timeout != NULL) { 31 timeoutMicros = system_time(); 32 flags = B_ABSOLUTE_TIMEOUT; 33 timeoutMicros += (bigtime_t)timeout->tv_sec * 1000000 34 + timeout->tv_nsec / 1000; 35 } else { 36 flags = 0; 37 timeoutMicros = 0; 38 } 39 40 status_t error = _kern_sigwait(set, info, flags, timeoutMicros); 41 42 pthread_testcancel(); 43 44 if (error != B_OK) 45 RETURN_AND_SET_ERRNO(error); 46 47 return info->si_signo; 48} 49