#include "iresource_lock.hpp"
#include <pthread.h>
#include <memory>
#include <iostream>

//
// POSIX implementation
//

class ResourceLock::ResourceLock_Impl
{
	public:
		ResourceLock_Impl() : 
			mutex(PTHREAD_MUTEX_INITIALIZER)
		{

		}

		void lock()
		{
			pthread_mutex_lock(&mutex);
			std::cout << "locked" << std::endl;	
		}

		void unlock()
		{
			pthread_mutex_unlock(&mutex);	
			std::cout << "unlocked" << std::endl;
		}

	private:
	pthread_mutex_t mutex;
};


//
// information relay
//

ResourceLock::ResourceLock() :
	impl{std::make_unique<ResourceLock_Impl>()}
{

}

ResourceLock::~ResourceLock()
{

}

void ResourceLock::lock()
{
	impl->lock();
}

void ResourceLock::unlock()
{
	impl->unlock();
}

