Mercurial > cpython-lru_cache-weakref
annotate Python/thread_beos.h @ 61774:55e2368f72f2 2.6
Merged revisions 81380 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81380 | brett.cannon | 2010-05-20 11:37:55 -0700 (Thu, 20 May 2010) | 8 lines
Turned out that if you used explicit relative import syntax
(e.g. from .os import sep) and it failed, import would still try the implicit
relative import semantics of an absolute import (from os import sep). That's
not right, so when level is negative, only do explicit relative import
semantics.
Fixes issue #7902. Thanks to Meador Inge for the patch.
........
| author | Brett Cannon <bcannon@gmail.com> |
|---|---|
| date | Thu, 20 May 2010 18:41:08 +0000 |
| parents | e38335d4df91 |
| children | b36cb4602e21 |
| 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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
10 sem_id _sem; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
11 int32 _atom; |
|
9603
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
22 if( ben != NULL ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
23 ben->_atom = 0; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
24 ben->_sem = create_sem( 0, name ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
25 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
26 if( ben->_sem < B_NO_ERROR ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
27 return B_BAD_SEM_ID; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
28 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
29 } else { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
30 return EFAULT; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
31 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
32 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
33 return EOK; |
|
9603
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
38 if( ben->_sem >= B_NO_ERROR ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
39 status_t retval = benaphore_timedlock( ben, 0 ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
40 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
41 if( retval == EOK || retval == EWOULDBLOCK ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
42 status_t del_retval = delete_sem( ben->_sem ); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
44 return del_retval; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
45 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
46 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
47 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
48 return B_BAD_SEM_ID; |
|
9603
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
53 int32 prev = atomic_add( &(ben->_atom), 1 ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
54 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
55 if( prev > 0 ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
56 return acquire_sem( ben->_sem ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
57 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
58 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
59 return EOK; |
|
9603
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
64 int32 prev = atomic_add( &(ben->_atom), 1 ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
65 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
66 if( prev > 0 ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
67 status_t retval = acquire_sem_etc( ben->_sem, 1, B_TIMEOUT, micros ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
68 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
69 switch( retval ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
70 case B_WOULD_BLOCK: /* Fall through... */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
71 case B_TIMED_OUT: |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
72 return EWOULDBLOCK; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
73 break; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
74 case B_OK: |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
75 return EOK; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
76 break; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
77 default: |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
78 return retval; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
79 break; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
80 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
81 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
82 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
83 return EOK; |
|
9603
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
88 int32 prev = atomic_add( &(ben->_atom), -1 ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
89 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
90 if( prev > 1 ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
91 return release_sem( ben->_sem ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
92 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
93 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
94 return EOK; |
|
9603
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
102 /* Do nothing. */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
103 return; |
|
9603
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 |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
115 long PyThread_start_new_thread( void (*func)(void *), void *arg ) |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
117 status_t success = 0; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
118 thread_id tid; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
119 char name[B_OS_NAME_LENGTH]; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
120 int32 this_thread; |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
124 /* We are so very thread-safe... */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
125 this_thread = atomic_add( &thread_count, 1 ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
126 PyOS_snprintf(name, sizeof(name), |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
127 "python thread (%d)", this_thread ); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
128 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
129 tid = spawn_thread( (thread_func)func, name, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
130 B_NORMAL_PRIORITY, arg ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
131 if( tid > B_NO_ERROR ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
132 success = resume_thread( tid ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
133 } |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
135 return ( success == B_NO_ERROR ? tid : -1 ); |
|
9603
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 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 long PyThread_get_thread_ident( void ) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
140 /* Presumed to return the current thread's ID... */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
141 thread_id tid; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
142 tid = find_thread( NULL ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
143 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
144 return ( tid != B_NAME_NOT_FOUND ? tid : -1 ); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
147 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
|
148 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
149 int32 threads; |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
151 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
|
152 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
153 /* Thread-safe way to read a variable without a mutex: */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
154 threads = atomic_add( &thread_count, 0 ); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
156 if( threads == 0 ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
157 /* No threads around, so exit main(). */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
158 if( no_cleanup ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
159 _exit(0); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
160 } else { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
161 exit(0); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
162 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
163 } else { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
164 /* Oh, we're a thread, let's try to exit gracefully... */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
165 exit_thread( B_NO_ERROR ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
166 } |
|
9603
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 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
169 void PyThread_exit_thread( void ) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
170 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
171 do_PyThread_exit_thread(0); |
|
9603
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 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
174 void PyThread__exit_thread( void ) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
176 do_PyThread_exit_thread(1); |
|
9603
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 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
179 #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
|
180 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
|
181 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
182 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
|
183 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
184 /* No need to do anything, the threads get torn down if main() exits. */ |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
185 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
186 if (no_cleanup) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
187 _exit(status); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
188 } else { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
189 exit(status); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
190 } |
|
9603
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 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
193 void PyThread_exit_prog( int status ) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
194 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
195 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
|
196 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
198 void PyThread__exit_prog( int status ) |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
199 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
200 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
|
201 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
202 #endif /* NO_EXIT_PROG */ |
|
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 /* ---------------------------------------------------------------------- |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
205 * Lock support. |
|
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 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 static int32 lock_count = 0; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
209 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
210 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
|
211 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
212 benaphore_t *lock; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
213 status_t retval; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
214 char name[B_OS_NAME_LENGTH]; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
215 int32 this_lock; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
216 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
217 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
|
218 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
219 lock = (benaphore_t *)malloc( sizeof( benaphore_t ) ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
220 if( lock == NULL ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
221 /* TODO: that's bad, raise MemoryError */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
222 return (PyThread_type_lock)NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
223 } |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
224 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
225 this_lock = atomic_add( &lock_count, 1 ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
226 PyOS_snprintf(name, sizeof(name), "python lock (%d)", this_lock); |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
228 retval = benaphore_create( name, lock ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
229 if( retval != EOK ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
230 /* TODO: that's bad, raise an exception */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
231 return (PyThread_type_lock)NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
232 } |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
234 dprintf(("PyThread_allocate_lock() -> %p\n", lock)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
235 return (PyThread_type_lock) lock; |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
236 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
237 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
238 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
|
239 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
240 status_t retval; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
241 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
242 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
|
243 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
244 retval = benaphore_destroy( (benaphore_t *)lock ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
245 if( retval != EOK ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
246 /* TODO: that's bad, raise an exception */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
247 return; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
248 } |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
249 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
250 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
251 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
|
252 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
253 int success; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
254 status_t retval; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
255 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
256 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
|
257 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
258 if( waitflag ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
259 retval = benaphore_lock( (benaphore_t *)lock ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
260 } else { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
261 retval = benaphore_timedlock( (benaphore_t *)lock, 0 ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
262 } |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
263 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
264 if( retval == EOK ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
265 success = 1; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
266 } else { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
267 success = 0; |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
268 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
269 /* TODO: that's bad, raise an exception */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
270 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
271 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
272 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
273 return success; |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
274 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
275 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
diff
changeset
|
276 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
|
277 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
278 status_t retval; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
279 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
280 dprintf(("PyThread_release_lock(%p) called\n", lock)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
281 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
282 retval = benaphore_unlock( (benaphore_t *)lock ); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
283 if( retval != EOK ) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
284 /* TODO: that's bad, raise an exception */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
285 return; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
21766
diff
changeset
|
286 } |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
287 } |
