Mercurial > cpython-lru_cache-weakref
annotate Python/thread_beos.h @ 42466:3fc3cedc49ca
Merged revisions 56753-56781 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
................
r56760 | neal.norwitz | 2007-08-05 18:55:39 -0700 (Sun, 05 Aug 2007) | 178 lines
Merged revisions 56477-56759 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r56485 | facundo.batista | 2007-07-21 17:13:00 -0700 (Sat, 21 Jul 2007) | 5 lines
Selectively enable tests for asyncore.readwrite based on the presence
of poll support in the select module (since this is the only case in
which readwrite can be called). [GSoC - Alan McIntyre]
........
r56488 | nick.coghlan | 2007-07-22 03:18:07 -0700 (Sun, 22 Jul 2007) | 1 line
Add explicit relative import tests for runpy.run_module
........
r56509 | nick.coghlan | 2007-07-23 06:41:45 -0700 (Mon, 23 Jul 2007) | 5 lines
Correctly cleanup sys.modules after executing runpy relative import
tests
Restore Python 2.4 ImportError when attempting to execute a package
(as imports cannot be guaranteed to work properly if you try it)
........
r56519 | nick.coghlan | 2007-07-24 06:07:38 -0700 (Tue, 24 Jul 2007) | 1 line
Tweak runpy test to do a better job of confirming that sys has been manipulated correctly
........
r56520 | nick.coghlan | 2007-07-24 06:58:28 -0700 (Tue, 24 Jul 2007) | 1 line
Fix an incompatibility between the -i and -m command line switches as reported on python-dev by PJE - runpy.run_module now leaves any changes it makes to the sys module intact after the function terminates
........
r56523 | nick.coghlan | 2007-07-24 07:39:23 -0700 (Tue, 24 Jul 2007) | 1 line
Try to get rid of spurious failure in test_resource on the Debian buildbots by changing the file size limit before attempting to close the file
........
r56533 | facundo.batista | 2007-07-24 14:20:42 -0700 (Tue, 24 Jul 2007) | 7 lines
New tests for basic behavior of smtplib.SMTP and
smtpd.DebuggingServer. Change to use global host & port number
variables. Modified the 'server' to take a string to send back in
order to vary test server responses. Added a test for the reaction of
smtplib.SMTP to a non-200 HELO response. [GSoC - Alan McIntyre]
........
r56538 | nick.coghlan | 2007-07-25 05:57:48 -0700 (Wed, 25 Jul 2007) | 1 line
More buildbot cleanup - let the OS assign the port for test_urllib2_localnet
........
r56539 | nick.coghlan | 2007-07-25 06:18:58 -0700 (Wed, 25 Jul 2007) | 1 line
Add a temporary diagnostic message before a strange failure on the alpha Debian buildbot
........
r56543 | martin.v.loewis | 2007-07-25 09:24:23 -0700 (Wed, 25 Jul 2007) | 2 lines
Change location of the package index to pypi.python.org/pypi
........
r56551 | georg.brandl | 2007-07-26 02:36:25 -0700 (Thu, 26 Jul 2007) | 2 lines
tabs, newlines and crs are valid XML characters.
........
r56553 | nick.coghlan | 2007-07-26 07:03:00 -0700 (Thu, 26 Jul 2007) | 1 line
Add explicit test for a misbehaving math.floor
........
r56561 | mark.hammond | 2007-07-26 21:52:32 -0700 (Thu, 26 Jul 2007) | 3 lines
In consultation with Kristjan Jonsson, only define WINVER and _WINNT_WIN32
if (a) we are building Python itself and (b) no one previously defined them
........
r56562 | mark.hammond | 2007-07-26 22:08:54 -0700 (Thu, 26 Jul 2007) | 2 lines
Correctly detect AMD64 architecture on VC2003
........
r56566 | nick.coghlan | 2007-07-27 03:36:30 -0700 (Fri, 27 Jul 2007) | 1 line
Make test_math error messages more meaningful for small discrepancies in results
........
r56588 | martin.v.loewis | 2007-07-27 11:28:22 -0700 (Fri, 27 Jul 2007) | 2 lines
Bug #978833: Close https sockets by releasing the _ssl object.
........
r56601 | martin.v.loewis | 2007-07-28 00:03:05 -0700 (Sat, 28 Jul 2007) | 3 lines
Bug #1704793: Return UTF-16 pair if unicodedata.lookup cannot
represent the result in a single character.
........
r56604 | facundo.batista | 2007-07-28 07:21:22 -0700 (Sat, 28 Jul 2007) | 9 lines
Moved all of the capture_server socket setup code into the try block
so that the event gets set if a failure occurs during server setup
(otherwise the test will block forever). Changed to let the OS assign
the server port number, and client side of test waits for port number
assignment before proceeding. The test data in DispatcherWithSendTests
is also sent in multiple send() calls instead of one to make sure this
works properly. [GSoC - Alan McIntyre]
........
r56611 | georg.brandl | 2007-07-29 01:26:10 -0700 (Sun, 29 Jul 2007) | 2 lines
Clarify PEP 343 description.
........
r56614 | georg.brandl | 2007-07-29 02:11:15 -0700 (Sun, 29 Jul 2007) | 2 lines
try-except-finally is new in 2.5.
........
r56617 | facundo.batista | 2007-07-29 07:23:08 -0700 (Sun, 29 Jul 2007) | 9 lines
Added tests for asynchat classes simple_producer & fifo, and the
find_prefix_at_end function. Check behavior of a string given as a
producer. Added tests for behavior of asynchat.async_chat when given
int, long, and None terminator arguments. Added usepoll attribute to
TestAsynchat to allow running the asynchat tests with poll support
chosen whether it's available or not (improves coverage of asyncore
code). [GSoC - Alan McIntyre]
........
r56620 | georg.brandl | 2007-07-29 10:38:35 -0700 (Sun, 29 Jul 2007) | 2 lines
Bug #1763149: use proper slice syntax in docstring.
(backport)
........
r56624 | mark.hammond | 2007-07-29 17:45:29 -0700 (Sun, 29 Jul 2007) | 4 lines
Correct use of Py_BUILD_CORE - now make sure it is defined before it is
referenced, and also fix definition of _WIN32_WINNT.
Resolves patch 1761803.
........
r56632 | facundo.batista | 2007-07-30 20:03:34 -0700 (Mon, 30 Jul 2007) | 8 lines
When running asynchat tests on OS X (darwin), the test client now
overrides asyncore.dispatcher.handle_expt to do nothing, since
select.poll gives a POLLHUP error at the completion of these tests.
Added timeout & count arguments to several asyncore.loop calls to
avoid the possibility of a test hanging up a build. [GSoC - Alan
McIntyre]
........
r56633 | nick.coghlan | 2007-07-31 06:38:01 -0700 (Tue, 31 Jul 2007) | 1 line
Eliminate RLock race condition reported in SF bug #1764059
........
r56636 | martin.v.loewis | 2007-07-31 12:57:56 -0700 (Tue, 31 Jul 2007) | 2 lines
Define _BSD_SOURCE, to get access to POSIX extensions on OpenBSD 4.1+.
........
r56653 | facundo.batista | 2007-08-01 16:18:36 -0700 (Wed, 01 Aug 2007) | 9 lines
Allow the OS to select a free port for each test server. For
DebuggingServerTests, construct SMTP objects with a localhost argument
to avoid abysmally long FQDN lookups (not relevant to items under
test) on some machines that would cause the test to fail. Moved server
setup code in the server function inside the try block to avoid the
possibility of setup failure hanging the test. Minor edits to conform
to PEP 8. [GSoC - Alan McIntyre]
........
r56681 | matthias.klose | 2007-08-02 14:33:13 -0700 (Thu, 02 Aug 2007) | 2 lines
- Allow Emacs 22 for building the documentation in info format.
........
r56689 | neal.norwitz | 2007-08-02 23:46:29 -0700 (Thu, 02 Aug 2007) | 1 line
Py_ssize_t is defined regardless of HAVE_LONG_LONG. Will backport
........
r56727 | hyeshik.chang | 2007-08-03 21:10:18 -0700 (Fri, 03 Aug 2007) | 3 lines
Fix gb18030 codec's bug that doesn't map two-byte characters on
GB18030 extension in encoding. (bug reported by Bjorn Stabell)
........
r56751 | neal.norwitz | 2007-08-04 20:23:31 -0700 (Sat, 04 Aug 2007) | 7 lines
Handle errors when generating a warning.
The value is always written to the returned pointer if getting it was
successful, even if a warning causes an error. (This probably doesn't matter
as the caller will probably discard the value.)
Will backport.
........
................
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 06 Aug 2007 23:33:07 +0000 |
| parents | 8b116a8449bd |
| children | e38335d4df91 df5719c298db |
| 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 |
|
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 { |
|
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 ); |
|
21094
c2150313d9d1
More sprintf -> PyOS_snprintf.
Tim Peters <tim.peters@gmail.com>
parents:
20468
diff
changeset
|
126 PyOS_snprintf(name, sizeof(name), |
|
c2150313d9d1
More sprintf -> PyOS_snprintf.
Tim Peters <tim.peters@gmail.com>
parents:
20468
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 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 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
|
130 B_NORMAL_PRIORITY, arg ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 if( tid > B_NO_ERROR ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 success = resume_thread( tid ); |
|
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 |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
14375
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 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 /* 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
|
141 thread_id tid; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 tid = find_thread( NULL ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 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
|
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 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 int32 threads; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
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 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 /* 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
|
154 threads = atomic_add( &thread_count, 0 ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 if( threads == 0 ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 /* No threads around, so exit main(). */ |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 if( no_cleanup ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
159 _exit(0); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 } else { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
161 exit(0); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 } else { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 /* 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
|
165 exit_thread( B_NO_ERROR ); |
|
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 |
|
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 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
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 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
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 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
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 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
184 /* 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
|
185 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 if (no_cleanup) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 _exit(status); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 } else { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
189 exit(status); |
|
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 |
|
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 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
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 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
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 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 benaphore_t *lock; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
213 status_t retval; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 char name[B_OS_NAME_LENGTH]; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 int32 this_lock; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9603
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 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 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
|
220 if( lock == NULL ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
221 /* 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
|
222 return (PyThread_type_lock)NULL; |
|
9603
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 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
225 this_lock = atomic_add( &lock_count, 1 ); |
|
21094
c2150313d9d1
More sprintf -> PyOS_snprintf.
Tim Peters <tim.peters@gmail.com>
parents:
20468
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 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
228 retval = benaphore_create( name, lock ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
229 if( retval != EOK ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 /* 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
|
231 return (PyThread_type_lock)NULL; |
|
9603
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
232 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
234 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
|
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 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
240 status_t retval; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
241 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
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 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
244 retval = benaphore_destroy( (benaphore_t *)lock ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
245 if( retval != EOK ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
246 /* 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
|
247 return; |
|
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 } |
|
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 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
253 int success; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
254 status_t retval; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
255 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
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 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
258 if( waitflag ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
259 retval = benaphore_lock( (benaphore_t *)lock ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
260 } else { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
261 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
|
262 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
263 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
264 if( retval == EOK ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
265 success = 1; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
266 } else { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
267 success = 0; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
268 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
269 /* 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
|
270 } |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
271 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
272 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
|
273 return success; |
|
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 { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
278 status_t retval; |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
279 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
280 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
|
281 |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
282 retval = benaphore_unlock( (benaphore_t *)lock ); |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
283 if( retval != EOK ) { |
|
c4e2da477949
Adding thread support for BeOS by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
284 /* 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
|
285 return; |
|
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 } |
