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

ZReadWriteLock::ZReadWriteLock()
: Lock(SST_Concurrency_CreateReadWriteLock())
{
	ZASSERT_RUNTIME(Lock != NULL, "ZReadWriteLock failed to allocate lock from libsst-concurrency!");
}

ZReadWriteLock::~ZReadWriteLock()
{
	SST_Concurrency_DestroyReadWriteLock(Lock);
}

bool ZReadWriteLock::LockForReading( uint32_t ticks ) const
{
	return SST_Concurrency_LockForReading(Lock, ticks) != 0;
}

bool ZReadWriteLock::LockForWriting( uint32_t ticks )
{
	return SST_Concurrency_LockForWriting(Lock, ticks) != 0;
}

void ZReadWriteLock::EndReading( ) const
{
	SST_Concurrency_EndReading(Lock);
}

void ZReadWriteLock::EndWriting( )
{
	SST_Concurrency_EndWriting(Lock);
}
