It would be really great if you could add a timedLock function to the Mutex class. Below is an idea of how it might work for the pthread world.
I don't know much about the Windows world. Maybe it's overly complex and that's why you haven't already done it.Code:inline bool Mutex::timedLock(const Time& timeout) const { timeval tv = Time::now() + timeout; timespec ts; ts.tv_sec = tv.tv_sec; ts.tv_nsec = tv.tv_usec * 1000; int rc = pthread_mutex_timedlock(&_mutex, &ts); if (rc != 0 && rc != ETIMEDOUT) { if(rc == EDEADLK) { throw ThreadLockedException(__FILE__, __LINE__); } else { throw ThreadSyscallException(__FILE__, __LINE__, rc); } } return (rc == 0); }

Reply With Quote
