1 #ifndef MULTIPROCESSING_H
2 #define MULTIPROCESSING_H
3
4 #define PY_SSIZE_T_CLEAN
5
6 #include "Python.h"
7 #include "structmember.h"
8 #include "pythread.h"
9
10 /*
11 * Platform includes and definitions
12 */
13
14 #ifdef MS_WINDOWS
15 # ifndef WIN32_LEAN_AND_MEAN
16 # define WIN32_LEAN_AND_MEAN
17 # endif
18 # include <windows.h>
19 # include <winsock2.h>
20 # include <process.h> /* getpid() */
21 # ifdef Py_DEBUG
22 # include <crtdbg.h>
23 # endif
24 # define SEM_HANDLE HANDLE
25 # define SEM_VALUE_MAX LONG_MAX
26 # define HAVE_MP_SEMAPHORE
27 #else
28 # include <fcntl.h> /* O_CREAT and O_EXCL */
29 # if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED)
30 # define HAVE_MP_SEMAPHORE
31 # include <semaphore.h>
32 typedef sem_t *SEM_HANDLE;
33 # endif
34 #endif
35
36 /*
37 * Issue 3110 - Solaris does not define SEM_VALUE_MAX
38 */
39 #ifndef SEM_VALUE_MAX
40 #if defined(HAVE_SYSCONF) && defined(_SC_SEM_VALUE_MAX)
41 # define SEM_VALUE_MAX sysconf(_SC_SEM_VALUE_MAX)
42 #elif defined(_SEM_VALUE_MAX)
43 # define SEM_VALUE_MAX _SEM_VALUE_MAX
44 #elif defined(_POSIX_SEM_VALUE_MAX)
45 # define SEM_VALUE_MAX _POSIX_SEM_VALUE_MAX
46 #else
47 # define SEM_VALUE_MAX INT_MAX
48 #endif
49 #endif
50
51
52 /*
53 * Format codes
54 */
55
56 #if SIZEOF_VOID_P == SIZEOF_LONG
57 # define F_POINTER "k"
58 # define T_POINTER T_ULONG
59 #elif SIZEOF_VOID_P == SIZEOF_LONG_LONG
60 # define F_POINTER "K"
61 # define T_POINTER T_ULONGLONG
62 #else
63 # error "can't find format code for unsigned integer of same size as void*"
64 #endif
65
66 #ifdef MS_WINDOWS
67 # define F_HANDLE F_POINTER
68 # define T_HANDLE T_POINTER
69 # define F_SEM_HANDLE F_HANDLE
70 # define T_SEM_HANDLE T_HANDLE
71 #else
72 # define F_HANDLE "i"
73 # define T_HANDLE T_INT
74 # define F_SEM_HANDLE F_POINTER
75 # define T_SEM_HANDLE T_POINTER
76 #endif
77
78 /*
79 * Error codes which can be returned by functions called without GIL
80 */
81
82 #define MP_SUCCESS (0)
83 #define MP_STANDARD_ERROR (-1)
84 #define MP_MEMORY_ERROR (-1001)
85 #define MP_SOCKET_ERROR (-1002)
86 #define MP_EXCEPTION_HAS_BEEN_SET (-1003)
87
88 PyObject *_PyMp_SetError(PyObject *Type, int num);
89
90 /*
91 * Externs - not all will really exist on all platforms
92 */
93
94 extern PyType_Spec _PyMp_SemLockType_spec;
95 extern PyObject *_PyMp_sem_unlink(const char *name);
96
97 #endif /* MULTIPROCESSING_H */