blob: ff8fdd269417cdf90c5efeffdf28f62a0ca342be [file] [log] [blame]
Guido van Rossum1984f1e1992-08-04 12:41:02 +00001
Fred Drake3cf4d2b2000-07-09 00:55:06 +00002#ifndef Py_PYTHREAD_H
3#define Py_PYTHREAD_H
4
Guido van Rossum65d5b571998-12-21 19:32:43 +00005typedef void *PyThread_type_lock;
6typedef void *PyThread_type_sema;
Sjoerd Mullenderd10d8291992-09-11 15:19:27 +00007
8#ifdef __cplusplus
9extern "C" {
10#endif
11
Mark Hammond91a681d2002-08-12 07:21:58 +000012PyAPI_FUNC(void) PyThread_init_thread(void);
13PyAPI_FUNC(long) PyThread_start_new_thread(void (*)(void *), void *);
14PyAPI_FUNC(void) PyThread_exit_thread(void);
Mark Hammond91a681d2002-08-12 07:21:58 +000015PyAPI_FUNC(long) PyThread_get_thread_ident(void);
Guido van Rossum1984f1e1992-08-04 12:41:02 +000016
Mark Hammond91a681d2002-08-12 07:21:58 +000017PyAPI_FUNC(PyThread_type_lock) PyThread_allocate_lock(void);
18PyAPI_FUNC(void) PyThread_free_lock(PyThread_type_lock);
19PyAPI_FUNC(int) PyThread_acquire_lock(PyThread_type_lock, int);
Guido van Rossum1984f1e1992-08-04 12:41:02 +000020#define WAIT_LOCK 1
21#define NOWAIT_LOCK 0
Antoine Pitrou7c3e5772010-04-14 15:44:10 +000022
23/* PY_TIMEOUT_T is the integral type used to specify timeouts when waiting
24 on a lock (see PyThread_acquire_lock_timed() below).
25 PY_TIMEOUT_MAX is the highest usable value (in microseconds) of that
26 type, and depends on the system threading API.
27
28 NOTE: this isn't the same value as `_thread.TIMEOUT_MAX`. The _thread
29 module exposes a higher-level API, with timeouts expressed in seconds
30 and floating-point numbers allowed.
31*/
32#if defined(HAVE_LONG_LONG)
33#define PY_TIMEOUT_T PY_LONG_LONG
34#define PY_TIMEOUT_MAX PY_LLONG_MAX
35#else
36#define PY_TIMEOUT_T long
37#define PY_TIMEOUT_MAX LONG_MAX
38#endif
39
40/* In the NT API, the timeout is a DWORD and is expressed in milliseconds */
41#if defined (NT_THREADS)
Hirokazu Yamamotof13c6d82010-09-11 22:35:24 +000042#if (Py_LL(0xFFFFFFFF) * 1000 < PY_TIMEOUT_MAX)
Antoine Pitrou7c3e5772010-04-14 15:44:10 +000043#undef PY_TIMEOUT_MAX
Hirokazu Yamamotof13c6d82010-09-11 22:35:24 +000044#define PY_TIMEOUT_MAX (Py_LL(0xFFFFFFFF) * 1000)
Antoine Pitrou7c3e5772010-04-14 15:44:10 +000045#endif
46#endif
47
48/* If microseconds == 0, the call is non-blocking: it returns immediately
49 even when the lock can't be acquired.
50 If microseconds > 0, the call waits up to the specified duration.
51 If microseconds < 0, the call waits until success (or abnormal failure)
52
53 microseconds must be less than PY_TIMEOUT_MAX. Behaviour otherwise is
54 undefined. */
55PyAPI_FUNC(int) PyThread_acquire_lock_timed(PyThread_type_lock,
56 PY_TIMEOUT_T microseconds);
Mark Hammond91a681d2002-08-12 07:21:58 +000057PyAPI_FUNC(void) PyThread_release_lock(PyThread_type_lock);
Guido van Rossum1984f1e1992-08-04 12:41:02 +000058
Thomas Wouters0e3f5912006-08-11 14:57:12 +000059PyAPI_FUNC(size_t) PyThread_get_stacksize(void);
60PyAPI_FUNC(int) PyThread_set_stacksize(size_t);
61
Mark Hammond8d98d2c2003-04-19 15:41:53 +000062/* Thread Local Storage (TLS) API */
Mark Hammond91a681d2002-08-12 07:21:58 +000063PyAPI_FUNC(int) PyThread_create_key(void);
64PyAPI_FUNC(void) PyThread_delete_key(int);
65PyAPI_FUNC(int) PyThread_set_key_value(int, void *);
66PyAPI_FUNC(void *) PyThread_get_key_value(int);
Mark Hammond8d98d2c2003-04-19 15:41:53 +000067PyAPI_FUNC(void) PyThread_delete_key_value(int key);
Guido van Rossuma027efa1997-05-05 20:56:21 +000068
Benjamin Petersone68df0f2008-06-13 00:26:50 +000069/* Cleanup after a fork */
70PyAPI_FUNC(void) PyThread_ReInitTLS(void);
71
Sjoerd Mullenderd10d8291992-09-11 15:19:27 +000072#ifdef __cplusplus
73}
74#endif
75
Guido van Rossumd023a781999-03-24 19:02:09 +000076#endif /* !Py_PYTHREAD_H */