blob: e3de9baf1b3c98ececa242cae3758647789fcc72 [file] [log] [blame]
Benjamin Petersonfa268032008-06-13 19:28:21 +00001#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 Pitrouf95a1b32010-05-09 15:52:27 +000018# include <process.h> /* getpid() */
Jesse Noller4b413d32009-04-01 20:51:28 +000019# ifdef Py_DEBUG
20# include <crtdbg.h>
21# endif
Benjamin Petersonfa268032008-06-13 19:28:21 +000022# define SEM_HANDLE HANDLE
23# define SEM_VALUE_MAX LONG_MAX
24#else
25# include <fcntl.h> /* O_CREAT and O_EXCL */
Mark Dickinsona614f042009-11-28 12:48:43 +000026# if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED)
Benjamin Petersonfa268032008-06-13 19:28:21 +000027# 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 Noller338f5782008-09-03 18:22:19 +000041 * Issue 3110 - Solaris does not define SEM_VALUE_MAX
42 */
43#ifndef SEM_VALUE_MAX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000044 #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 Noller338f5782008-09-03 18:22:19 +000053#endif
54
Benjamin Peterson965ce872009-04-05 21:24:58 +000055
Jesse Noller338f5782008-09-03 18:22:19 +000056/*
Benjamin Petersonfa268032008-06-13 19:28:21 +000057 * 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 Petersonfa268032008-06-13 19:28:21 +000084/*
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 Pitrou87cf2202011-05-09 17:04:27 +020091#define MP_SOCKET_ERROR (-1002)
92#define MP_EXCEPTION_HAS_BEEN_SET (-1003)
Benjamin Petersonfa268032008-06-13 19:28:21 +000093
94PyObject *mp_SetError(PyObject *Type, int num);
95
96/*
97 * Externs - not all will really exist on all platforms
98 */
99
Benjamin Petersonfa268032008-06-13 19:28:21 +0000100extern PyObject *BufferTooShort;
101extern PyTypeObject SemLockType;
Benjamin Petersonfa268032008-06-13 19:28:21 +0000102extern PyTypeObject PipeConnectionType;
Benjamin Petersonfa268032008-06-13 19:28:21 +0000103
104/*
Benjamin Petersonfa268032008-06-13 19:28:21 +0000105 * Miscellaneous
106 */
107
Benjamin Petersonfa268032008-06-13 19:28:21 +0000108#ifndef MIN
109# define MIN(x, y) ((x) < (y) ? x : y)
110# define MAX(x, y) ((x) > (y) ? x : y)
111#endif
112
113#endif /* MULTIPROCESSING_H */