| 1 |
#ifndef __Semaphore_h |
| 2 |
#define __Semaphore_h |
| 3 |
|
| 4 |
|
| 5 |
#ifdef linux
|
| 6 |
|
| 7 |
#include <iostream.h> |
| 8 |
/*
|
| 9 |
#include <unistd.h> //sleep |
| 10 |
#include <signal.h> |
| 11 |
#include <stdio.h> |
| 12 |
#include <stdlib.h> //exit |
| 13 |
*/
|
| 14 |
#include <errno.h> |
| 15 |
|
| 16 |
#include <sys/ipc.h> //ftok() |
| 17 |
#include <sys/types.h> //key ??? |
| 18 |
#include <sys/sem.h> //semget |
| 19 |
|
| 20 |
#endif |
| 21 |
|
| 22 |
class Semaphore |
| 23 |
{ |
| 24 |
public: |
| 25 |
|
| 26 |
Semaphore(); |
| 27 |
Semaphore(char* path, char id, unsigned int permissions); |
| 28 |
~Semaphore(); |
| 29 |
int create(); |
| 30 |
void attach(char* path, char id, unsigned int permissions); |
| 31 |
int destroy(); |
| 32 |
void wait(); |
| 33 |
void signal(); |
| 34 |
int semset(int i); |
| 35 |
|
| 36 |
private: |
| 37 |
|
| 38 |
union semun
|
| 39 |
{
|
| 40 |
int val; //value for SETVAL
|
| 41 |
struct semid_ds *buf; //buffer for IPC_STAT, IPC_SET
|
| 42 |
unsigned short int *array; //array for GETALL, SETALL
|
| 43 |
struct seminfo *__buf; //buffer for IPC_INFO
|
| 44 |
};
|
| 45 |
|
| 46 |
int needs_attach; |
| 47 |
int semid; |
| 48 |
int proc_id; |
| 49 |
|
| 50 |
semun arg; |
| 51 |
}; |
| 52 |
|
| 53 |
#endif |