blob: fe78135d4669ece63ecd0e3c110dce17e7bf86ab [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
Benjamin Petersonfa268032008-06-13 19:28:21 +000030#endif
31
32/*
Jesse Noller338f5782008-09-03 18:22:19 +000033 * Issue 3110 - Solaris does not define SEM_VALUE_MAX
34 */
35#ifndef SEM_VALUE_MAX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000036 #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
Jesse Noller338f5782008-09-03 18:22:19 +000045#endif
46
Benjamin Peterson965ce872009-04-05 21:24:58 +000047
Jesse Noller338f5782008-09-03 18:22:19 +000048/*
Benjamin Petersonfa268032008-06-13 19:28:21 +000049 * Format codes
50 */
51
52#if SIZEOF_VOID_P == SIZEOF_LONG
53# define F_POINTER "k"
54# define T_POINTER T_ULONG
Benjamin Petersoned4aa832016-09-05 17:44:18 -070055#elif SIZEOF_VOID_P == SIZEOF_LONG_LONG
Benjamin Petersonfa268032008-06-13 19:28:21 +000056# 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
Benjamin Petersonfa268032008-06-13 19:28:21 +000067#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
Benjamin Petersonfa268032008-06-13 19:28:21 +000074/*
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)
Antoine Pitrou87cf2202011-05-09 17:04:27 +020081#define MP_SOCKET_ERROR (-1002)
82#define MP_EXCEPTION_HAS_BEEN_SET (-1003)
Benjamin Petersonfa268032008-06-13 19:28:21 +000083
Richard Oudkerk8fb9f4c2012-10-07 18:08:47 +010084PyObject *_PyMp_SetError(PyObject *Type, int num);
Benjamin Petersonfa268032008-06-13 19:28:21 +000085
86/*
87 * Externs - not all will really exist on all platforms
88 */
89
Richard Oudkerk8fb9f4c2012-10-07 18:08:47 +010090extern PyTypeObject _PyMp_SemLockType;
Richard Oudkerk84ed9a62013-08-14 15:35:41 +010091extern PyObject *_PyMp_sem_unlink(PyObject *ignore, PyObject *args);
Benjamin Petersonfa268032008-06-13 19:28:21 +000092
Benjamin Petersonfa268032008-06-13 19:28:21 +000093#endif /* MULTIPROCESSING_H */