Debian Codegraph @

Modules/_multiprocessing/multiprocessing.h

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