Mercurial > cpython-lru_cache-weakref
annotate Python/thread_beos.h @ 16845:09dcf5ebcd80 legacy-trunk
Now that Jeremy is asking about this code, it looks really bogus to me,
so let's rip it out. The constructor for SyntaxError does the right
thing, so we do not need to do it again.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Wed, 28 Feb 2001 20:58:04 +0000 |
| parents | 6f6f965c5e2d |
| children | ebfd87e87884 |
| rev | line source |
|---|---|
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 #include <kernel/OS.h> |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 #include <support/SupportDefs.h> |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 #include <errno.h> |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 /* ---------------------------------------------------------------------- |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 * Fast locking mechanism described by Benoit Schillings (benoit@be.com) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 * in the Be Developer's Newsletter, Issue #26 (http://www.be.com/). |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 typedef struct benaphore { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 sem_id _sem; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 int32 _atom; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 } benaphore_t; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 static status_t benaphore_create( const char *name, benaphore_t *ben ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 static status_t benaphore_destroy( benaphore_t *ben ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 static status_t benaphore_lock( benaphore_t *ben ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 static status_t benaphore_timedlock( benaphore_t *ben, bigtime_t micros ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 static status_t benaphore_unlock( benaphore_t *ben ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 static status_t benaphore_create( const char *name, benaphore_t *ben ) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 if( ben != NULL ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 ben->_atom = 0; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 ben->_sem = create_sem( 0, name ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 if( ben->_sem < B_NO_ERROR ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 return B_BAD_SEM_ID; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 } else { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 return EFAULT; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 return EOK; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 static status_t benaphore_destroy( benaphore_t *ben ) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 if( ben->_sem >= B_NO_ERROR ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 status_t retval = benaphore_timedlock( ben, 0 ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 if( retval == EOK || retval == EWOULDBLOCK ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 status_t del_retval = delete_sem( ben->_sem ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 return del_retval; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 return B_BAD_SEM_ID; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 static status_t benaphore_lock( benaphore_t *ben ) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 int32 prev = atomic_add( &(ben->_atom), 1 ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 if( prev > 0 ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 return acquire_sem( ben->_sem ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 return EOK; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 static status_t benaphore_timedlock( benaphore_t *ben, bigtime_t micros ) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 int32 prev = atomic_add( &(ben->_atom), 1 ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 if( prev > 0 ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 status_t retval = acquire_sem_etc( ben->_sem, 1, B_TIMEOUT, micros ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 switch( retval ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 case B_WOULD_BLOCK: /* Fall through... */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 case B_TIMED_OUT: |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 return EWOULDBLOCK; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 break; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 case B_OK: |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 return EOK; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 break; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 default: |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 return retval; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 break; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 return EOK; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 static status_t benaphore_unlock( benaphore_t *ben ) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 int32 prev = atomic_add( &(ben->_atom), -1 ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 if( prev > 1 ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 return release_sem( ben->_sem ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 return EOK; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 /* ---------------------------------------------------------------------- |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 * Initialization. |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 */ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
100 static void PyThread__init_thread( void ) |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 /* Do nothing. */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 return; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 /* ---------------------------------------------------------------------- |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 * Thread support. |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 * |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 * Only ANSI C, renamed functions here; you can't use K&R on BeOS, |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 * and there's no legacy thread module to support. |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 static int32 thread_count = 0; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 int PyThread_start_new_thread( void (*func)(void *), void *arg ) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 status_t success = 0; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 thread_id tid; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 char name[B_OS_NAME_LENGTH]; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 int32 this_thread; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
122 dprintf(("PyThread_start_new_thread called\n")); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 /* We are so very thread-safe... */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
125 this_thread = atomic_add( &thread_count, 1 ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 sprintf( name, "python thread (%d)", this_thread ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
128 tid = spawn_thread( (thread_func)func, name, |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 B_NORMAL_PRIORITY, arg ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 if( tid > B_NO_ERROR ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 success = resume_thread( tid ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 return ( success == B_NO_ERROR ? 1 : 0 ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
135 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 long PyThread_get_thread_ident( void ) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 /* Presumed to return the current thread's ID... */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 thread_id tid; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 tid = find_thread( NULL ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 return ( tid != B_NAME_NOT_FOUND ? tid : -1 ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
146 static void do_PyThread_exit_thread( int no_cleanup ) |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 int32 threads; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
150 dprintf(("PyThread_exit_thread called\n")); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 /* Thread-safe way to read a variable without a mutex: */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 threads = atomic_add( &thread_count, 0 ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 if( threads == 0 ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 /* No threads around, so exit main(). */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 if( no_cleanup ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 _exit(0); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
159 } else { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 exit(0); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
161 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 } else { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 /* Oh, we're a thread, let's try to exit gracefully... */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 exit_thread( B_NO_ERROR ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
167 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
168 void PyThread_exit_thread( void ) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
169 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
170 do_PyThread_exit_thread(0); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
171 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
172 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
173 void PyThread__exit_thread( void ) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
174 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
175 do_PyThread_exit_thread(1); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
177 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
178 #ifndef NO_EXIT_PROG |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
179 static void do_PyThread_exit_prog( int status, int no_cleanup ) |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
181 dprintf(("PyThread_exit_prog(%d) called\n", status)); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
182 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
183 /* No need to do anything, the threads get torn down if main() exits. */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
184 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
185 if (no_cleanup) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 _exit(status); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 } else { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 exit(status); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
189 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
190 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
191 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
192 void PyThread_exit_prog( int status ) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
193 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
194 do_PyThread_exit_prog(status, 0); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
195 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
196 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 void PyThread__exit_prog( int status ) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
198 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
199 do_PyThread_exit_prog(status, 1); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
201 #endif /* NO_EXIT_PROG */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
202 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 /* ---------------------------------------------------------------------- |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 * Lock support. |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
205 */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 static int32 lock_count = 0; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
209 PyThread_type_lock PyThread_allocate_lock( void ) |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
210 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
211 benaphore_t *lock; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 status_t retval; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
213 char name[B_OS_NAME_LENGTH]; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 int32 this_lock; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
216 dprintf(("PyThread_allocate_lock called\n")); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
217 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
218 lock = (benaphore_t *)malloc( sizeof( benaphore_t ) ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 if( lock == NULL ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
220 /* TODO: that's bad, raise MemoryError */ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
221 return (PyThread_type_lock)NULL; |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
222 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
223 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
224 this_lock = atomic_add( &lock_count, 1 ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
225 sprintf( name, "python lock (%d)", this_lock ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
226 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 retval = benaphore_create( name, lock ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
228 if( retval != EOK ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
229 /* TODO: that's bad, raise an exception */ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
230 return (PyThread_type_lock)NULL; |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
231 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
232 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
233 dprintf(("PyThread_allocate_lock() -> %p\n", lock)); |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
234 return (PyThread_type_lock) lock; |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
235 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
236 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
237 void PyThread_free_lock( PyThread_type_lock lock ) |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
238 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
239 status_t retval; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
240 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
241 dprintf(("PyThread_free_lock(%p) called\n", lock)); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
242 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
243 retval = benaphore_destroy( (benaphore_t *)lock ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
244 if( retval != EOK ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
245 /* TODO: that's bad, raise an exception */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
246 return; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
247 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
248 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
249 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
250 int PyThread_acquire_lock( PyThread_type_lock lock, int waitflag ) |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
251 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
252 int success; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
253 status_t retval; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
254 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
255 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
256 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
257 if( waitflag ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
258 retval = benaphore_lock( (benaphore_t *)lock ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
259 } else { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
260 retval = benaphore_timedlock( (benaphore_t *)lock, 0 ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
261 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
262 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
263 if( retval == EOK ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
264 success = 1; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
265 } else { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
266 success = 0; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
267 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
268 /* TODO: that's bad, raise an exception */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
269 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
270 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
271 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
272 return success; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
273 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
274 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
275 void PyThread_release_lock( PyThread_type_lock lock ) |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
277 status_t retval; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
278 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
279 dprintf(("PyThread_release_lock(%p) called\n", lock)); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
280 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
281 retval = benaphore_unlock( (benaphore_t *)lock ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
282 if( retval != EOK ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
283 /* TODO: that's bad, raise an exception */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
284 return; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
285 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
286 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
287 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
288 /* ---------------------------------------------------------------------- |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
289 * Semaphore support. |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
290 * |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
291 * Guido says not to implement this because it's not used anywhere; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
292 * I'll do it anyway, you never know when it might be handy, and it's |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
293 * easy... |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
294 */ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
295 PyThread_type_sema PyThread_allocate_sema( int value ) |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
296 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
297 sem_id sema; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
298 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
299 dprintf(("PyThread_allocate_sema called\n")); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
301 sema = create_sem( value, "python semaphore" ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
302 if( sema < B_NO_ERROR ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 /* TODO: that's bad, raise an exception */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
304 return 0; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
305 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
307 dprintf(("PyThread_allocate_sema() -> %p\n", sema)); |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
308 return (PyThread_type_sema) sema; |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
309 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
310 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
311 void PyThread_free_sema( PyThread_type_sema sema ) |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
312 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
313 status_t retval; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
314 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
315 dprintf(("PyThread_free_sema(%p) called\n", sema)); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
316 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
317 retval = delete_sem( (sem_id)sema ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
318 if( retval != B_NO_ERROR ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
319 /* TODO: that's bad, raise an exception */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
320 return; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
321 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
323 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
324 int PyThread_down_sema( PyThread_type_sema sema, int waitflag ) |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
325 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
326 status_t retval; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
327 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
328 dprintf(("PyThread_down_sema(%p, %d) called\n", sema, waitflag)); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
329 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
330 if( waitflag ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
331 retval = acquire_sem( (sem_id)sema ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
332 } else { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
333 retval = acquire_sem_etc( (sem_id)sema, 1, B_TIMEOUT, 0 ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
334 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
335 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 if( retval != B_NO_ERROR ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
337 /* TODO: that's bad, raise an exception */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
338 return 0; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
340 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
341 dprintf(("PyThread_down_sema(%p) return\n", sema)); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
342 return -1; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
343 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
344 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
345 void PyThread_up_sema( PyThread_type_sema sema ) |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
346 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
347 status_t retval; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
348 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
349 dprintf(("PyThread_up_sema(%p)\n", sema)); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
350 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
351 retval = release_sem( (sem_id)sema ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
352 if( retval != B_NO_ERROR ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
353 /* TODO: that's bad, raise an exception */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
354 return; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
355 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
356 } |
