blob: 67491a167d61a84263fe97cf1240a93d5f841868 [file] [log] [blame]
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +00001
2/*
3 * Initialization.
4 */
Thomas Woutersf70ef4f2000-07-22 18:47:25 +00005static void
6PyThread__init_thread(void)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +00007{
8}
9
10/*
11 * Thread support.
12 */
Guido van Rossum3c288632001-10-16 21:13:49 +000013long
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000014PyThread_start_new_thread(void (*func)(void *), void *arg)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000015{
16 int success = 0; /* init not needed when SOLARIS_THREADS and */
17 /* C_THREADS implemented properly */
18
Guido van Rossum65d5b571998-12-21 19:32:43 +000019 dprintf(("PyThread_start_new_thread called\n"));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000020 if (!initialized)
Guido van Rossum65d5b571998-12-21 19:32:43 +000021 PyThread_init_thread();
Guido van Rossum3c288632001-10-16 21:13:49 +000022 return success < 0 ? -1 : 0;
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000023}
24
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000025long
26PyThread_get_thread_ident(void)
Guido van Rossume944da81994-05-23 12:43:41 +000027{
28 if (!initialized)
Guido van Rossum65d5b571998-12-21 19:32:43 +000029 PyThread_init_thread();
Guido van Rossume944da81994-05-23 12:43:41 +000030}
31
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000032static
33void do_PyThread_exit_thread(int no_cleanup)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000034{
Guido van Rossum65d5b571998-12-21 19:32:43 +000035 dprintf(("PyThread_exit_thread called\n"));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000036 if (!initialized)
37 if (no_cleanup)
38 _exit(0);
39 else
40 exit(0);
41}
42
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000043void
44PyThread_exit_thread(void)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000045{
Guido van Rossum65d5b571998-12-21 19:32:43 +000046 do_PyThread_exit_thread(0);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000047}
48
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000049void
50PyThread__exit_thread(void)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000051{
Guido van Rossum65d5b571998-12-21 19:32:43 +000052 do_PyThread_exit_thread(1);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000053}
54
55#ifndef NO_EXIT_PROG
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000056static
57void do_PyThread_exit_prog(int status, int no_cleanup)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000058{
Guido van Rossum65d5b571998-12-21 19:32:43 +000059 dprintf(("PyThread_exit_prog(%d) called\n", status));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000060 if (!initialized)
61 if (no_cleanup)
62 _exit(status);
63 else
64 exit(status);
65}
66
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000067void
68PyThread_exit_prog(int status)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000069{
Guido van Rossum65d5b571998-12-21 19:32:43 +000070 do_PyThread_exit_prog(status, 0);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000071}
72
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000073void
74PyThread__exit_prog(int status)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000075{
Guido van Rossum65d5b571998-12-21 19:32:43 +000076 do_PyThread_exit_prog(status, 1);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000077}
78#endif /* NO_EXIT_PROG */
79
80/*
81 * Lock support.
82 */
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000083PyThread_type_lock
84PyThread_allocate_lock(void)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000085{
86
Guido van Rossum65d5b571998-12-21 19:32:43 +000087 dprintf(("PyThread_allocate_lock called\n"));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000088 if (!initialized)
Guido van Rossum65d5b571998-12-21 19:32:43 +000089 PyThread_init_thread();
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000090
Fred Drakea44d3532000-06-30 15:01:00 +000091 dprintf(("PyThread_allocate_lock() -> %p\n", lock));
Guido van Rossum65d5b571998-12-21 19:32:43 +000092 return (PyThread_type_lock) lock;
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000093}
94
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000095void
96PyThread_free_lock(PyThread_type_lock lock)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000097{
Fred Drakea44d3532000-06-30 15:01:00 +000098 dprintf(("PyThread_free_lock(%p) called\n", lock));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000099}
100
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000101int
102PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000103{
104 int success;
105
Fred Drakea44d3532000-06-30 15:01:00 +0000106 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
107 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000108 return success;
109}
110
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000111void
112PyThread_release_lock(PyThread_type_lock lock)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000113{
Fred Drakea44d3532000-06-30 15:01:00 +0000114 dprintf(("PyThread_release_lock(%p) called\n", lock));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000115}