multiprocessing.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef MULTIPROCESSING_H
  2. #define MULTIPROCESSING_H
  3. #define PY_SSIZE_T_CLEAN
  4. #include "Python.h"
  5. #include "structmember.h"
  6. #include "pythread.h"
  7. /*
  8. * Platform includes and definitions
  9. */
  10. #ifdef MS_WINDOWS
  11. # ifndef WIN32_LEAN_AND_MEAN
  12. # define WIN32_LEAN_AND_MEAN
  13. # endif
  14. # include <windows.h>
  15. # include <winsock2.h>
  16. # include <process.h> /* getpid() */
  17. # ifdef Py_DEBUG
  18. # include <crtdbg.h>
  19. # endif
  20. # define SEM_HANDLE HANDLE
  21. # define SEM_VALUE_MAX LONG_MAX
  22. # define HAVE_MP_SEMAPHORE
  23. #else
  24. # include <fcntl.h> /* O_CREAT and O_EXCL */
  25. # if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED)
  26. # define HAVE_MP_SEMAPHORE
  27. # include <semaphore.h>
  28. typedef sem_t *SEM_HANDLE;
  29. # endif
  30. #endif
  31. /*
  32. * Issue 3110 - Solaris does not define SEM_VALUE_MAX
  33. */
  34. #ifndef SEM_VALUE_MAX
  35. #if defined(HAVE_SYSCONF) && defined(_SC_SEM_VALUE_MAX)
  36. # define SEM_VALUE_MAX sysconf(_SC_SEM_VALUE_MAX)
  37. #elif defined(_SEM_VALUE_MAX)
  38. # define SEM_VALUE_MAX _SEM_VALUE_MAX
  39. #elif defined(_POSIX_SEM_VALUE_MAX)
  40. # define SEM_VALUE_MAX _POSIX_SEM_VALUE_MAX
  41. #else
  42. # define SEM_VALUE_MAX INT_MAX
  43. #endif
  44. #endif
  45. /*
  46. * Format codes
  47. */
  48. #if SIZEOF_VOID_P == SIZEOF_LONG
  49. # define F_POINTER "k"
  50. # define T_POINTER T_ULONG
  51. #elif SIZEOF_VOID_P == SIZEOF_LONG_LONG
  52. # define F_POINTER "K"
  53. # define T_POINTER T_ULONGLONG
  54. #else
  55. # error "can't find format code for unsigned integer of same size as void*"
  56. #endif
  57. #ifdef MS_WINDOWS
  58. # define F_HANDLE F_POINTER
  59. # define T_HANDLE T_POINTER
  60. # define F_SEM_HANDLE F_HANDLE
  61. # define T_SEM_HANDLE T_HANDLE
  62. #else
  63. # define F_HANDLE "i"
  64. # define T_HANDLE T_INT
  65. # define F_SEM_HANDLE F_POINTER
  66. # define T_SEM_HANDLE T_POINTER
  67. #endif
  68. /*
  69. * Error codes which can be returned by functions called without GIL
  70. */
  71. #define MP_SUCCESS (0)
  72. #define MP_STANDARD_ERROR (-1)
  73. #define MP_MEMORY_ERROR (-1001)
  74. #define MP_SOCKET_ERROR (-1002)
  75. #define MP_EXCEPTION_HAS_BEEN_SET (-1003)
  76. PyObject *_PyMp_SetError(PyObject *Type, int num);
  77. /*
  78. * Externs - not all will really exist on all platforms
  79. */
  80. extern PyType_Spec _PyMp_SemLockType_spec;
  81. extern PyObject *_PyMp_sem_unlink(const char *name);
  82. #endif /* MULTIPROCESSING_H */