Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 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> |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 18 | # include <process.h> /* getpid() */ |
Jesse Noller | 4b413d3 | 2009-04-01 20:51:28 +0000 | [diff] [blame] | 19 | # ifdef Py_DEBUG |
| 20 | # include <crtdbg.h> |
| 21 | # endif |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 22 | # define SEM_HANDLE HANDLE |
| 23 | # define SEM_VALUE_MAX LONG_MAX |
| 24 | #else |
| 25 | # include <fcntl.h> /* O_CREAT and O_EXCL */ |
Mark Dickinson | a614f04 | 2009-11-28 12:48:43 +0000 | [diff] [blame] | 26 | # if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED) |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 27 | # include <semaphore.h> |
| 28 | typedef sem_t *SEM_HANDLE; |
| 29 | # endif |
| 30 | # define HANDLE int |
| 31 | # define SOCKET int |
| 32 | # define BOOL int |
| 33 | # define UINT32 uint32_t |
| 34 | # define INT32 int32_t |
| 35 | # define TRUE 1 |
| 36 | # define FALSE 0 |
| 37 | # define INVALID_HANDLE_VALUE (-1) |
| 38 | #endif |
| 39 | |
| 40 | /* |
Jesse Noller | 338f578 | 2008-09-03 18:22:19 +0000 | [diff] [blame] | 41 | * Issue 3110 - Solaris does not define SEM_VALUE_MAX |
| 42 | */ |
| 43 | #ifndef SEM_VALUE_MAX |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 44 | #if defined(HAVE_SYSCONF) && defined(_SC_SEM_VALUE_MAX) |
| 45 | # define SEM_VALUE_MAX sysconf(_SC_SEM_VALUE_MAX) |
| 46 | #elif defined(_SEM_VALUE_MAX) |
| 47 | # define SEM_VALUE_MAX _SEM_VALUE_MAX |
| 48 | #elif defined(_POSIX_SEM_VALUE_MAX) |
| 49 | # define SEM_VALUE_MAX _POSIX_SEM_VALUE_MAX |
| 50 | #else |
| 51 | # define SEM_VALUE_MAX INT_MAX |
| 52 | #endif |
Jesse Noller | 338f578 | 2008-09-03 18:22:19 +0000 | [diff] [blame] | 53 | #endif |
| 54 | |
Benjamin Peterson | 965ce87 | 2009-04-05 21:24:58 +0000 | [diff] [blame] | 55 | |
Jesse Noller | 338f578 | 2008-09-03 18:22:19 +0000 | [diff] [blame] | 56 | /* |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 57 | * Format codes |
| 58 | */ |
| 59 | |
| 60 | #if SIZEOF_VOID_P == SIZEOF_LONG |
| 61 | # define F_POINTER "k" |
| 62 | # define T_POINTER T_ULONG |
| 63 | #elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P == SIZEOF_LONG_LONG) |
| 64 | # define F_POINTER "K" |
| 65 | # define T_POINTER T_ULONGLONG |
| 66 | #else |
| 67 | # error "can't find format code for unsigned integer of same size as void*" |
| 68 | #endif |
| 69 | |
| 70 | #ifdef MS_WINDOWS |
| 71 | # define F_HANDLE F_POINTER |
| 72 | # define T_HANDLE T_POINTER |
| 73 | # define F_SEM_HANDLE F_HANDLE |
| 74 | # define T_SEM_HANDLE T_HANDLE |
| 75 | # define F_DWORD "k" |
| 76 | # define T_DWORD T_ULONG |
| 77 | #else |
| 78 | # define F_HANDLE "i" |
| 79 | # define T_HANDLE T_INT |
| 80 | # define F_SEM_HANDLE F_POINTER |
| 81 | # define T_SEM_HANDLE T_POINTER |
| 82 | #endif |
| 83 | |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 84 | /* |
| 85 | * Error codes which can be returned by functions called without GIL |
| 86 | */ |
| 87 | |
| 88 | #define MP_SUCCESS (0) |
| 89 | #define MP_STANDARD_ERROR (-1) |
| 90 | #define MP_MEMORY_ERROR (-1001) |
Antoine Pitrou | 87cf220 | 2011-05-09 17:04:27 +0200 | [diff] [blame] | 91 | #define MP_SOCKET_ERROR (-1002) |
| 92 | #define MP_EXCEPTION_HAS_BEEN_SET (-1003) |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 93 | |
| 94 | PyObject *mp_SetError(PyObject *Type, int num); |
| 95 | |
| 96 | /* |
| 97 | * Externs - not all will really exist on all platforms |
| 98 | */ |
| 99 | |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 100 | extern PyObject *BufferTooShort; |
| 101 | extern PyTypeObject SemLockType; |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 102 | extern PyTypeObject PipeConnectionType; |
| 103 | extern HANDLE sigint_event; |
| 104 | |
| 105 | /* |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 106 | * Miscellaneous |
| 107 | */ |
| 108 | |
Benjamin Peterson | fa26803 | 2008-06-13 19:28:21 +0000 | [diff] [blame] | 109 | #ifndef MIN |
| 110 | # define MIN(x, y) ((x) < (y) ? x : y) |
| 111 | # define MAX(x, y) ((x) > (y) ? x : y) |
| 112 | #endif |
| 113 | |
| 114 | #endif /* MULTIPROCESSING_H */ |