diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2012-09-22 11:52:33 +0200 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2012-09-22 11:52:33 +0200 |
commit | 72c03260d77a0de52ed57992e374f26211fe2063 (patch) | |
tree | ea61de60ff2567caee18e1b4a2afbb563de56e6f /thread.c | |
parent | e898a28258ac97cc15f875fb8fa9b274266f6d01 (diff) | |
download | vdr-72c03260d77a0de52ed57992e374f26211fe2063.tar.gz vdr-72c03260d77a0de52ed57992e374f26211fe2063.tar.bz2 |
The new class cIoThrottle is used to allow I/O intense threads to temporarily suspend their activities in case buffers run full
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 44 |
1 files changed, 43 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 2.4 2012/05/08 11:15:57 kls Exp $ + * $Id: thread.c 2.5 2012/09/20 09:05:50 kls Exp $ */ #include "thread.h" @@ -398,6 +398,48 @@ bool cThreadLock::Lock(cThread *Thread) return false; } +// --- cIoThrottle ----------------------------------------------------------- + +cMutex cIoThrottle::mutex; +int cIoThrottle::count = 0; + +cIoThrottle::cIoThrottle(void) +{ + active = false; +} + +cIoThrottle::~cIoThrottle() +{ + Release(); +} + +void cIoThrottle::Activate(void) +{ + if (!active) { + mutex.Lock(); + count++; + active = true; + dsyslog("i/o throttle activated, count = %d (tid=%d)", count, cThread::ThreadId()); + mutex.Unlock(); + } +} + +void cIoThrottle::Release(void) +{ + if (active) { + mutex.Lock(); + count--; + active = false; + dsyslog("i/o throttle released, count = %d (tid=%d)", count, cThread::ThreadId()); + mutex.Unlock(); + } +} + +bool cIoThrottle::Engaged(void) +{ + return count > 0; +} + // --- cPipe ----------------------------------------------------------------- // cPipe::Open() and cPipe::Close() are based on code originally received from |