Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Modules/_multiprocessing/multiprocessing.h
12 views
1
#ifndef MULTIPROCESSING_H
2
#define MULTIPROCESSING_H
3
4
#include "Python.h"
5
#include "structmember.h"
6
#include "pythread.h"
7
8
/*
9
* Platform includes and definitions
10
*/
11
12
#ifdef MS_WINDOWS
13
# ifndef WIN32_LEAN_AND_MEAN
14
# define WIN32_LEAN_AND_MEAN
15
# endif
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
# define HAVE_MP_SEMAPHORE
25
#else
26
# include <fcntl.h> /* O_CREAT and O_EXCL */
27
# if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED)
28
# define HAVE_MP_SEMAPHORE
29
# include <semaphore.h>
30
typedef sem_t *SEM_HANDLE;
31
# endif
32
#endif
33
34
/*
35
* Issue 3110 - Solaris does not define SEM_VALUE_MAX
36
*/
37
#ifndef SEM_VALUE_MAX
38
#if defined(HAVE_SYSCONF) && defined(_SC_SEM_VALUE_MAX)
39
# define SEM_VALUE_MAX sysconf(_SC_SEM_VALUE_MAX)
40
#elif defined(_SEM_VALUE_MAX)
41
# define SEM_VALUE_MAX _SEM_VALUE_MAX
42
#elif defined(_POSIX_SEM_VALUE_MAX)
43
# define SEM_VALUE_MAX _POSIX_SEM_VALUE_MAX
44
#else
45
# define SEM_VALUE_MAX INT_MAX
46
#endif
47
#endif
48
49
50
/*
51
* Format codes
52
*/
53
54
#if SIZEOF_VOID_P == SIZEOF_LONG
55
# define F_POINTER "k"
56
# define T_POINTER T_ULONG
57
#elif SIZEOF_VOID_P == SIZEOF_LONG_LONG
58
# define F_POINTER "K"
59
# define T_POINTER T_ULONGLONG
60
#else
61
# error "can't find format code for unsigned integer of same size as void*"
62
#endif
63
64
#ifdef MS_WINDOWS
65
# define F_HANDLE F_POINTER
66
# define T_HANDLE T_POINTER
67
# define F_SEM_HANDLE F_HANDLE
68
# define T_SEM_HANDLE T_HANDLE
69
#else
70
# define F_HANDLE "i"
71
# define T_HANDLE T_INT
72
# define F_SEM_HANDLE F_POINTER
73
# define T_SEM_HANDLE T_POINTER
74
#endif
75
76
/*
77
* Error codes which can be returned by functions called without GIL
78
*/
79
80
#define MP_SUCCESS (0)
81
#define MP_STANDARD_ERROR (-1)
82
#define MP_MEMORY_ERROR (-1001)
83
#define MP_SOCKET_ERROR (-1002)
84
#define MP_EXCEPTION_HAS_BEEN_SET (-1003)
85
86
PyObject *_PyMp_SetError(PyObject *Type, int num);
87
88
/*
89
* Externs - not all will really exist on all platforms
90
*/
91
92
extern PyType_Spec _PyMp_SemLockType_spec;
93
extern PyObject *_PyMp_sem_unlink(const char *name);
94
95
#endif /* MULTIPROCESSING_H */
96
97