This page was last modified 07:31, 26 November 2007.
Implementing recursive mutexes
From Forum Nokia Wiki
If you come from a POSIX environment, you'll find Symbian's support for synchronization primitives rather simplistic. This is in some way due to Symbian's preference for single threaded applications using the Active object idiom, thus making the use of multithreading often unnecessary. Sometimes, the need for recursive (reentrant) mutexes arises (note though that POSIX mutexes aren't recursive by default). Here is a possible implementation of a wrapper class over a RMutex:
class TRecursiveMutex { public: TRecursiveMutex(); ~TRecursiveMutex(); void Acquire(); void Release(); private: RMutex iMutex; TThreadId iOwner; TInt iCount; }; TRecursiveMutex::TRecursiveMutex() : iCount(0) { iMutex.CreateLocal(); } TRecursiveMutex::~TRecursiveMutex() { iMutex.Close(); } void TRecursiveMutex::Acquire() { TThreadId id = RThread().Id(); if (iOwner == id) { ++iCount; } else { iMutex.Wait(); iCount = 1; iOwner = id; } } void TRecursiveMutex::Release() { if (--iCount == 0) { iOwner = 0; iMutex.Signal(); } }
Note:You'll notice this is a bare bones implementation. Potential things to be added (at least on debug builds) could be checking thread ownership and iCount being 0 upon destruction
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Implementing transion effects | zivgr | Mobile Java Media (Graphics & Sounds) | 0 | 2003-09-03 13:50 |
| 3D Game engine for MIDP/M3G | mcwo | Mobile Java General | 4 | 2007-03-30 11:53 |
| RTSP implementation | barkatv | Mobile Java Media (Graphics & Sounds) | 3 | 2006-01-09 16:53 |
| How to use a 6820 as a Bluetooth keyboard | pbasch | Bluetooth Technology | 2 | 2006-09-13 10:30 |
| How to run app in background | nayani | Symbian User Interface | 3 | 2005-06-03 10:18 |
