resource_locker.hpp 516 Bytes
Newer Older
Swann Perarnau's avatar
Swann Perarnau committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#ifndef __RESOURCE_LOCKER_HPP__
#define __RESOURCE_LOCKER_HPP__

#include <stdio.h>
#include <string>
using std::string;

class Resource_locker
{
	private:
		int _fd;
		bool _locked;
		int _pid;

		Resource_locker(const Resource_locker& orig){}
		Resource_locker& operator = (const Resource_locker& orig){return *this;}
	public:
		Resource_locker(const string& filename, const string& path = "/var/lock/");
		~Resource_locker();
		void lock();
		void unlock();
		bool trylock();
};

#endif //__RESOURCE_LOCKER_HPP__