medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 254fbf9211def7bc29fed5c2b7aec5011d10fc1e
parent c9d24c3479f64a6b34c087763461fef454655708
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Thu Jan 19 22:56:24 +0200

Add locked.h

Diffstat:
locked.h | 33+++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+), 0 deletions(-)
diff --git a/locked.h b/locked.h @@ -0,0 +1,33 @@ +#pragma once + +#include "intrinsics.h" +#include "platform_mutex.h" + +template< typename T > +class Locked { +public: + NONCOPYABLE( Locked ); + + Locked() { + mutex_init( &mutex ); + } + + ~Locked() { + mutex_destroy( &mutex ); + } + + T * acquire() { + mutex_lock( &mutex ); + return &data; + } + + void release() { + mutex_unlock( &mutex ); + } + +private: + T data; + Mutex mutex; +}; + +#define SCOPED_LOCKED( locked ) locked.acquire(); SCOPE_EXIT( locked.release(); )