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