Skip to content
Snippets Groups Projects
ReadWriteLock.hpp 516 B
Newer Older
#ifndef READ_WRITE_LOCK
#define READ_WRITE_LOCK

#include <pthread.h>

namespace nbody {
	class ReadWriteLock {
	protected:
		pthread_mutex_t mutex;
		pthread_rwlock_t rwlock;
		pthread_t* owner;
	public:
		ReadWriteLock();
		virtual ~ReadWriteLock();
		virtual bool readLock(pthread_t* myThread);
		virtual bool writeLock(pthread_t* myThread);
		virtual bool upgradeToWriteLock(pthread_t* myThread);
		virtual bool downgradeToReadLock(pthread_t* myThread);
		virtual bool unLock(pthread_t* myThread);
	};
}

#endif