-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsem.h
66 lines (56 loc) · 1.3 KB
/
sem.h
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef BWAPI_SEM_H
#define BWAPI_SEM_H
#ifndef _WIN32
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <semaphore.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/stat.h>
static sem_t * arch_id;
static void lockArchive()
{
const char* file = "archivelock44";
arch_id=sem_open(file, O_CREAT, 0600, 1);
if(arch_id == SEM_FAILED) {
perror("parent sem_open");
return;
}
//printf("waiting for process\n");
if(sem_wait(arch_id) < 0) {
//perror("sem_wait");
}
}
static void releaseArchive()
{
//arch_id=sem_open("mysem", O_CREAT, 0600, 0);
if(arch_id == SEM_FAILED) {
//perror("child sem_open");
return;
}
//printf("Posting for parent\n");
if(sem_post(arch_id) < 0) {
//perror("sem_post");
}
if ( sem_close(arch_id) < 0 )
{
//perror("sem_close");
}
}
#endif
/*
struct semaphore {
pthread_mutex_t lock;
pthread_cond_t nonzero;
unsigned count;
};
typedef struct semaphore semaphore_t;
semaphore_t *semaphore_create(const char *semaphore_name);
semaphore_t *semaphore_open(const char *semaphore_name);
void semaphore_post(semaphore_t *semap);
void semaphore_wait(semaphore_t *semap);
void semaphore_close(semaphore_t *semap);
*/
#endif //BWAPI_SEM_H