73 lines
1.3 KiB
C++
73 lines
1.3 KiB
C++
//
|
|
// Linux Daemon
|
|
//
|
|
|
|
/* prevent multiple inclusions */
|
|
#ifndef __Mutex__
|
|
#define __Mutex__
|
|
|
|
/* includes *****************************************************************/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <errno.h>
|
|
#include <memory.h>
|
|
#include <string.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
/* defines ******************************************************************/
|
|
|
|
/* macros *******************************************************************/
|
|
|
|
/* structs & typedefs *******************************************************/
|
|
|
|
/* c class definitions ******************************************************/
|
|
|
|
class Mutex {
|
|
// public data
|
|
public:
|
|
|
|
// protected data
|
|
protected:
|
|
pthread_mutexattr_t m_attr;
|
|
pthread_mutex_t m_mutex;
|
|
|
|
// private data
|
|
private:
|
|
|
|
// public methods
|
|
public:
|
|
// constructors
|
|
Mutex();
|
|
|
|
// destructor
|
|
virtual ~Mutex();
|
|
|
|
Mutex( const Mutex& );
|
|
const Mutex& operator=( const Mutex& );
|
|
|
|
// public methods
|
|
void Init( void );
|
|
int Lock( void );
|
|
int TryLock( void );
|
|
int Unlock( void );
|
|
|
|
// virtual functions
|
|
|
|
// exceptions
|
|
class MutexException
|
|
{
|
|
char *toString(void) { return strerror(errno); };
|
|
};
|
|
|
|
// static methods to override
|
|
|
|
// private methods
|
|
private:
|
|
};
|
|
|
|
#endif
|