source: python/trunk/Python/thread_cthread.h

Last change on this file was 391, checked in by dmik, 11 years ago

python: Merge vendor 2.7.6 to trunk.

  • Property svn:eol-style set to native
File size: 2.3 KB
RevLine 
[2]1
2#ifdef MACH_C_THREADS
3#include <mach/cthreads.h>
4#endif
5
6#ifdef HURD_C_THREADS
7#include <cthreads.h>
8#endif
9
10/*
11 * Initialization.
12 */
13static void
14PyThread__init_thread(void)
15{
16#ifndef HURD_C_THREADS
[391]17 /* Roland McGrath said this should not be used since this is
18 done while linking to threads */
19 cthread_init();
[2]20#else
21/* do nothing */
[391]22 ;
[2]23#endif
24}
25
26/*
27 * Thread support.
28 */
29long
30PyThread_start_new_thread(void (*func)(void *), void *arg)
31{
[391]32 int success = 0; /* init not needed when SOLARIS_THREADS and */
33 /* C_THREADS implemented properly */
[2]34
[391]35 dprintf(("PyThread_start_new_thread called\n"));
36 if (!initialized)
37 PyThread_init_thread();
38 /* looks like solaris detaches the thread to never rejoin
39 * so well do it here
40 */
41 cthread_detach(cthread_fork((cthread_fn_t) func, arg));
42 return success < 0 ? -1 : 0;
[2]43}
44
45long
46PyThread_get_thread_ident(void)
47{
[391]48 if (!initialized)
49 PyThread_init_thread();
50 return (long) cthread_self();
[2]51}
52
53void
54PyThread_exit_thread(void)
55{
[391]56 dprintf(("PyThread_exit_thread called\n"));
57 if (!initialized)
58 exit(0);
59 cthread_exit(0);
[2]60}
61
62/*
63 * Lock support.
64 */
65PyThread_type_lock
66PyThread_allocate_lock(void)
67{
[391]68 mutex_t lock;
[2]69
[391]70 dprintf(("PyThread_allocate_lock called\n"));
71 if (!initialized)
72 PyThread_init_thread();
[2]73
[391]74 lock = mutex_alloc();
75 if (mutex_init(lock)) {
76 perror("mutex_init");
77 free((void *) lock);
78 lock = 0;
79 }
80 dprintf(("PyThread_allocate_lock() -> %p\n", lock));
81 return (PyThread_type_lock) lock;
[2]82}
83
84void
85PyThread_free_lock(PyThread_type_lock lock)
86{
[391]87 dprintf(("PyThread_free_lock(%p) called\n", lock));
88 mutex_free(lock);
[2]89}
90
91int
92PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
93{
[391]94 int success = FALSE;
[2]95
[391]96 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
97 if (waitflag) { /* blocking */
98 mutex_lock((mutex_t)lock);
99 success = TRUE;
100 } else { /* non blocking */
101 success = mutex_try_lock((mutex_t)lock);
102 }
103 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
104 return success;
[2]105}
106
107void
108PyThread_release_lock(PyThread_type_lock lock)
109{
[391]110 dprintf(("PyThread_release_lock(%p) called\n", lock));
111 mutex_unlock((mutex_t )lock);
[2]112}
Note: See TracBrowser for help on using the repository browser.