Home | History | Annotate | Download | only in _multiprocessing
      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>
     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 #else
     25 #  include <fcntl.h>                 /* O_CREAT and O_EXCL */
     26 #  if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED)
     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 /*
     41  * Issue 3110 - Solaris does not define SEM_VALUE_MAX
     42  */
     43 #ifndef SEM_VALUE_MAX
     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
     53 #endif
     54 
     55 
     56 /*
     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 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 
     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)
     91 #define MP_SOCKET_ERROR (-1002)
     92 #define MP_EXCEPTION_HAS_BEEN_SET (-1003)
     93 
     94 PyObject *_PyMp_SetError(PyObject *Type, int num);
     95 
     96 /*
     97  * Externs - not all will really exist on all platforms
     98  */
     99 
    100 extern PyTypeObject _PyMp_SemLockType;
    101 extern PyObject *_PyMp_sem_unlink(PyObject *ignore, PyObject *args);
    102 
    103 #endif /* MULTIPROCESSING_H */
    104