You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
716 B
61 lines
716 B
#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();
|
|
}
|
|
|