-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp_sync.h
More file actions
135 lines (105 loc) · 2.52 KB
/
php_sync.h
File metadata and controls
135 lines (105 loc) · 2.52 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
Direct port of the cross platform 'sync' library: https://github.com/cubiclesoft/cross-platform-cpp
This source file is under the MIT, LGPL, or version 3.01 of the PHP license, your choice.
(C) 2014 CubicleSoft. All rights reserved.
*/
/* $Id$ */
#ifndef PHP_SYNC_H
#define PHP_SYNC_H
extern zend_module_entry sync_module_entry;
#define phpext_sync_ptr &sync_module_entry
#define PHP_SYNC_VERSION "1.0.1"
#ifdef PHP_WIN32
# define PHP_SYNC_API __declspec(dllexport)
#elif defined(__GNUC__) && __GNUC__ >= 4
# define PHP_SYNC_API __attribute__ ((visibility("default")))
#else
# define PHP_SYNC_API
#endif
#ifdef ZTS
#include "TSRM.h"
#endif
#ifdef PHP_WIN32
#include <windows.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
#include <semaphore.h>
#include <limits.h>
#endif
#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#include <mach/semaphore.h>
#endif
PHP_MINIT_FUNCTION(sync);
PHP_MSHUTDOWN_FUNCTION(sync);
PHP_MINFO_FUNCTION(sync);
#if defined(PHP_WIN32)
typedef DWORD sync_ThreadIDType;
#else
typedef pthread_t sync_ThreadIDType;
#endif
/* Mutex */
typedef struct _sync_Mutex_object {
zend_object std;
#if defined(PHP_WIN32)
CRITICAL_SECTION MxWinCritSection;
HANDLE MxWinMutex;
#else
pthread_mutex_t MxPthreadCritSection;
sem_t *MxSemMutex;
int MxAllocated;
#endif
volatile sync_ThreadIDType MxOwnerID;
volatile unsigned int MxCount;
} sync_Mutex_object;
/* Semaphore */
typedef struct _sync_Semaphore_object {
zend_object std;
#if defined(PHP_WIN32)
HANDLE MxWinSemaphore;
#else
sem_t *MxSemSemaphore;
int MxAllocated;
#endif
int MxAutoUnlock;
volatile unsigned int MxCount;
} sync_Semaphore_object;
/* Event */
typedef struct _sync_Event_object {
zend_object std;
#if defined(PHP_WIN32)
HANDLE MxWinWaitEvent;
#else
sem_t *MxSemWaitMutex, *MxSemWaitEvent, *MxSemWaitCount, *MxSemWaitStatus;
int MxAllocated;
int MxManual;
#endif
} sync_Event_object;
/* Reader-Writer */
typedef struct _sync_ReaderWriter_object {
zend_object std;
#if defined(PHP_WIN32)
HANDLE MxWinRSemMutex, MxWinRSemaphore, MxWinRWaitEvent, MxWinWWaitMutex;
#else
sem_t *MxSemRSemMutex, *MxSemRSemaphore, *MxSemRWaitEvent, *MxSemWWaitMutex;
int MxAllocated;
#endif
int MxAutoUnlock;
volatile unsigned int MxReadLocks, MxWriteLock;
} sync_ReaderWriter_object;
#endif /* PHP_SYNC_H */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/