#include <ZUtil/ZMutex.hpp>
#include <ZUtil/ZAssert.hpp>

//////////////////////////
/* ZLock Implementation */
//////////////////////////

ZMutex::ZMutex() 
: Mutex(SST_Concurrency_CreateMutex())
{
	ZASSERT_RUNTIME(Mutex != NULL, "ZMutex failed to allocate mutex from libsst-concurrency!");
}

ZMutex::~ZMutex()
{
	SST_Concurrency_DestroyMutex(Mutex);
}

void ZMutex::Acquire()
{
	SST_Concurrency_LockMutex(Mutex);
}

void ZMutex::Release()
{
	SST_Concurrency_UnlockMutex(Mutex);
}

////////////////////////////////
/* ZScopedLock Implementation */
////////////////////////////////

ZLock::ZLock( ZMutex& _mutex )
 : Mutex(_mutex)
{
	Mutex.Acquire();
}

ZLock::~ZLock()
{
	Mutex.Release();
}
