From bb65f0fc2176b2ebf0f1be682008609e8bd2cb0a Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Wed, 3 Oct 2012 16:26:24 +0200 Subject: simplified mutex locking idiom by introducing Mutex class (wrapper around SDL_mutex) * can be instantiated * can derive from class Mutex to inherit the lock()/unlock() methods also fixed LayerList destructor --- src/layer.h | 38 ++++---------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) (limited to 'src/layer.h') diff --git a/src/layer.h b/src/layer.h index 21fab50..378acbd 100644 --- a/src/layer.h +++ b/src/layer.h @@ -5,7 +5,6 @@ #include #include -#include #include @@ -14,9 +13,7 @@ extern OSCServer osc_server; -class Layer { - SDL_mutex *mutex; - +class Layer : public Mutex { public: /* * Every derived class must have a static CtorInfo struct "ctor_info" @@ -34,17 +31,6 @@ public: Layer(const char *name); virtual ~Layer(); - inline void - lock() - { - SDL_LockMutex(mutex); - } - inline void - unlock() - { - SDL_UnlockMutex(mutex); - } - /* * Frame render method */ @@ -91,31 +77,15 @@ private: } }; -class LayerList { +class LayerList : Mutex { LIST_HEAD(layers_head, Layer) head; - SDL_mutex *mutex; - - inline void - lock() - { - SDL_LockMutex(mutex); - } - inline void - unlock() - { - SDL_UnlockMutex(mutex); - } - public: - LayerList() : mutex(SDL_CreateMutex()) + LayerList() : Mutex() { LIST_INIT(&head); } - ~LayerList() - { - SDL_DestroyMutex(mutex); - } + ~LayerList(); void insert(int pos, Layer *layer); void delete_layer(Layer *layer); -- cgit v1.2.3