diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2003-12-22 13:29:24 +0100 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2003-12-22 13:29:24 +0100 |
commit | 7ff59171e3f907a5584b72f0f8588ed65f22c0bd (patch) | |
tree | 801b1b65840c50a4f1d8abea806fa5c180051df1 /thread.c | |
parent | 84b99ea81095f421ec049dd6b5bd5f0f2fe679c1 (diff) | |
download | vdr-7ff59171e3f907a5584b72f0f8588ed65f22c0bd.tar.gz vdr-7ff59171e3f907a5584b72f0f8588ed65f22c0bd.tar.bz2 |
Changed section handling; replaced 'libdtv' with 'libsi'
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 35 |
1 files changed, 34 insertions, 1 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.c 1.28 2003/10/18 13:00:04 kls Exp $ + * $Id: thread.c 1.29 2003/12/21 15:17:24 kls Exp $ */ #include "thread.h" @@ -80,6 +80,39 @@ void cCondVar::Signal(void) } */ +// --- cRWlock --------------------------------------------------------------- + +cRWlock::cRWlock(bool PreferWriter) +{ + pthread_rwlockattr_t attr = { PreferWriter ? PTHREAD_RWLOCK_PREFER_WRITER_NP : PTHREAD_RWLOCK_PREFER_READER_NP }; + pthread_rwlock_init(&rwlock, &attr); +} + +cRWlock::~cRWlock() +{ + pthread_rwlock_destroy(&rwlock); +} + +bool cRWlock::Lock(bool Write, int TimeoutMs) +{ + int Result = 0; + struct timespec abstime; + if (TimeoutMs) { + abstime.tv_sec = TimeoutMs / 1000; + abstime.tv_nsec = (TimeoutMs % 1000) * 1000000; + } + if (Write) + Result = TimeoutMs ? pthread_rwlock_timedwrlock(&rwlock, &abstime) : pthread_rwlock_wrlock(&rwlock); + else + Result = TimeoutMs ? pthread_rwlock_timedrdlock(&rwlock, &abstime) : pthread_rwlock_rdlock(&rwlock); + return Result == 0; +} + +void cRWlock::Unlock(void) +{ + pthread_rwlock_unlock(&rwlock); +} + // --- cMutex ---------------------------------------------------------------- cMutex::cMutex(void) |