ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/semaphore.h
Revision: 1.2
Committed: 2005-05-14T17:32:55Z (19 years, 6 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
CVS Tags: nigel-build-19, nigel-build-17, HEAD
Changes since 1.1: +14 -0 lines
Log Message:
MacOS X doesn't implement unnamed POSIX semaphores even though their libc
defines the functions. Use Mach semaphores instead.

File Contents

# Content
1 #ifndef __SEMAPHORE_H
2 #define __SEMAPHORE_H
3
4 #define SEM_VALUE_MAX 64
5
6 #if defined(c_plusplus) || defined(__cplusplus)
7 extern "C" {
8 #endif /* c_plusplus || __cplusplus */
9
10 /* MacOS X doesn't implement unnamed POSIX semaphores, event though
11 the libc defines them! */
12 #if (defined(__MACH__) && defined(__APPLE__))
13 #include <mach/mach_init.h>
14 #include <mach/task.h>
15 #include <mach/semaphore.h>
16
17 #define sem_t semaphore_t
18 #define sem_init(SEM,UNUSED,VALUE) semaphore_create(current_task(), (SEM), SYNC_POLICY_FIFO, (VALUE))
19 #define sem_destroy(SEM) semaphore_destroy(current_task(), *(SEM))
20 #define sem_wait(SEM) semaphore_wait(*(SEM))
21 #define sem_post(SEM) semaphore_signal(*(SEM))
22 #else
23 typedef struct psem {
24 pthread_mutex_t sem_lock;
25 int sem_value;
26 int sem_waiting;
27 } sem_t;
28
29 int sem_init(sem_t* sem, int pshared, unsigned int value);
30 int sem_destroy(sem_t* sem);
31 sem_t sem_open(const char* name, int oflag, ...);
32 int sem_close(sem_t* sem);
33 int sem_unlink(const char* name);
34 int sem_wait(sem_t* sem);
35 int sem_trywait(sem_t* sem);
36 int sem_post(sem_t* sem);
37 int sem_getvalue(sem_t* sem, int* sval);
38 #endif
39
40 #if defined(c_plusplus) || defined(__cplusplus)
41 };
42 #endif /* c_plusplus || __cplusplus */
43
44 #endif /* __SEMAPHORE_H */