History

add hg and python

cinap_lenrek committed 15 years ago

Commit 4bb9e221 parent 987265c3706 files · +1228772 −-233Browse files

Showing the changes to sys/src/cmd/python/Python/thread_plan9.h (1 of 3706 files). Show all

Unified · Split

sys/src/cmd/python/Python/thread_plan9.h+135−0
@@ -0,0 +1,135 @@
1#define _PLAN9_SOURCE
2#include <u.h>
3#include <lib9.h>
4#include <qlock.h>
5
6/*
7 * Initialization.
8 */
9static void
10PyThread__init_thread(void)
11{
12}
13
14/*
15 * Thread support.
16 */
17long
18PyThread_start_new_thread(void (*func)(void *), void *arg)
19{
20 dprintf(("PyThread_start_new_thread called\n"));
21 if (!initialized)
22 PyThread_init_thread();
23 switch(rfork(RFPROC|RFMEM)){
24 case -1:
25 printf("rfork: %r\n");
26 return -1;
27 case 0:
28 _threadarg->fn = func;
29 _threadarg->arg = arg;
30 longjmp(_threadarg->jb, 1);
31 default:
32 return 0;
33 }
34}
35
36long
37PyThread_get_thread_ident(void)
38{
39 if (!initialized)
40 PyThread_init_thread();
41 return getpid();
42}
43
44void
45PyThread_exit_thread(void)
46{
47 if(initialized)
48 _exit(0);
49 exit(0);
50}
51
52void
53PyThread__exit_thread(void)
54{
55 _exit(0);
56}
57
58#ifndef NO_EXIT_PROG
59static
60void do_PyThread_exit_prog(int status, int no_cleanup)
61{
62 /*
63 * BUG BUG BUG
64 */
65
66 dprintf(("PyThread_exit_prog(%d) called\n", status));
67 if (!initialized)
68 if (no_cleanup)
69 _exit(status);
70 else
71 exit(status);
72}
73
74void
75PyThread_exit_prog(int status)
76{
77 do_PyThread_exit_prog(status, 0);
78}
79
80void
81PyThread__exit_prog(int status)
82{
83 do_PyThread_exit_prog(status, 1);
84}
85#endif /* NO_EXIT_PROG */
86
87/*
88 * Lock support.
89 */
90PyThread_type_lock
91PyThread_allocate_lock(void)
92{
93 QLock *lk;
94
95 dprintf(("PyThread_allocate_lock called\n"));
96 if (!initialized)
97 PyThread_init_thread();
98
99 lk = malloc(sizeof(*lk));
100 memset(lk, 0, sizeof(*lk));
101 dprintf(("PyThread_allocate_lock() -> %p\n", lk));
102 return lk;
103}
104
105void
106PyThread_free_lock(PyThread_type_lock lock)
107{
108 dprintf(("PyThread_free_lock(%p) called\n", lock));
109 free(lock);
110}
111
112int
113PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
114{
115 int success;
116
117 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
118 if(lock == nil)
119 success = 0;
120 else if(waitflag){
121 qlock(lock);
122 success = 1;
123 }else
124 success = canqlock(lock);
125 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
126 return success;
127}
128
129void
130PyThread_release_lock(PyThread_type_lock lock)
131{
132 dprintf(("PyThread_release_lock(%p) called\n", lock));
133 qunlock(lock);
134}
135

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t