Mercurial > cpython-lru_cache-weakref
annotate Python/thread_nt.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 | 00c02c4488ce |
| children | 2b2707ff8bb7 |
| rev | line source |
|---|---|
| 2152 | 1 |
| 2 /* This code implemented by Dag.Gruneau@elsa.preseco.comm.se */ | |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
3 /* Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru */ |
|
22092
7a3e03b541ff
SF patch 522961: Leak in Python/thread_nt.h, from Gerald S. Williams.
Tim Peters <tim.peters@gmail.com>
parents:
21766
diff
changeset
|
4 /* Eliminated some memory leaks, gsw@agere.com */ |
| 2152 | 5 |
|
6029
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
6 #include <windows.h> |
|
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
7 #include <limits.h> |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
8 #ifdef HAVE_PROCESS_H |
|
6029
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
9 #include <process.h> |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
10 #endif |
| 2152 | 11 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
12 typedef struct NRMUTEX { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
13 LONG owned ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
14 DWORD thread_id ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
15 HANDLE hevent ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
16 } NRMUTEX, *PNRMUTEX ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
17 |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
18 |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
19 BOOL |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
20 InitializeNonRecursiveMutex(PNRMUTEX mutex) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
21 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
22 mutex->owned = -1 ; /* No threads have entered NonRecursiveMutex */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
23 mutex->thread_id = 0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
24 mutex->hevent = CreateEvent(NULL, FALSE, FALSE, NULL) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
25 return mutex->hevent != NULL ; /* TRUE if the mutex is created */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
26 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
27 |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
28 VOID |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
29 DeleteNonRecursiveMutex(PNRMUTEX mutex) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
30 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
31 /* No in-use check */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
32 CloseHandle(mutex->hevent) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
33 mutex->hevent = NULL ; /* Just in case */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
34 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
35 |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
36 DWORD |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
37 EnterNonRecursiveMutex(PNRMUTEX mutex, BOOL wait) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
38 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
39 /* Assume that the thread waits successfully */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
40 DWORD ret ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
41 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
42 /* InterlockedIncrement(&mutex->owned) == 0 means that no thread currently owns the mutex */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
43 if (!wait) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
44 { |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
45 if (InterlockedCompareExchange(&mutex->owned, 0, -1) != -1) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
46 return WAIT_TIMEOUT ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
47 ret = WAIT_OBJECT_0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
48 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
49 else |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
50 ret = InterlockedIncrement(&mutex->owned) ? |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
51 /* Some thread owns the mutex, let's wait... */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
52 WaitForSingleObject(mutex->hevent, INFINITE) : WAIT_OBJECT_0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
53 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
54 mutex->thread_id = GetCurrentThreadId() ; /* We own it */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
55 return ret ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
56 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
57 |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
58 BOOL |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
59 LeaveNonRecursiveMutex(PNRMUTEX mutex) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
60 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
61 /* We don't own the mutex */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
62 mutex->thread_id = 0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
63 return |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
64 InterlockedDecrement(&mutex->owned) < 0 || |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
65 SetEvent(mutex->hevent) ; /* Other threads are waiting, wake one on them up */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
66 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
67 |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
68 PNRMUTEX |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
69 AllocNonRecursiveMutex(void) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
70 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
71 PNRMUTEX mutex = (PNRMUTEX)malloc(sizeof(NRMUTEX)) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
72 if (mutex && !InitializeNonRecursiveMutex(mutex)) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
73 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
74 free(mutex) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
75 mutex = NULL ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
76 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
77 return mutex ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
78 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
79 |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
80 void |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
81 FreeNonRecursiveMutex(PNRMUTEX mutex) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
82 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
83 if (mutex) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
84 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
85 DeleteNonRecursiveMutex(mutex) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
86 free(mutex) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
87 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
88 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
89 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
90 long PyThread_get_thread_ident(void); |
| 2152 | 91 |
| 92 /* | |
| 93 * Initialization of the C package, should not be needed. | |
| 94 */ | |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
95 static void |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
96 PyThread__init_thread(void) |
| 2152 | 97 { |
| 98 } | |
| 99 | |
| 100 /* | |
| 101 * Thread support. | |
| 102 */ | |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
103 |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
104 typedef struct { |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
105 void (*func)(void*); |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
106 void *arg; |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
107 long id; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
108 HANDLE done; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
109 } callobj; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
110 |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
111 static int |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
112 bootstrap(void *call) |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
113 { |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
114 callobj *obj = (callobj*)call; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
115 /* copy callobj since other thread might free it before we're done */ |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
116 void (*func)(void*) = obj->func; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
117 void *arg = obj->arg; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
118 |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
119 obj->id = PyThread_get_thread_ident(); |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
120 ReleaseSemaphore(obj->done, 1, NULL); |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
121 func(arg); |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
122 return 0; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
123 } |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
124 |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
125 long |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
126 PyThread_start_new_thread(void (*func)(void *), void *arg) |
| 2152 | 127 { |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
128 Py_uintptr_t rv; |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
129 callobj obj; |
| 2152 | 130 |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
131 dprintf(("%ld: PyThread_start_new_thread called\n", |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
132 PyThread_get_thread_ident())); |
| 2152 | 133 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
134 PyThread_init_thread(); |
| 2152 | 135 |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
136 obj.id = -1; /* guilty until proved innocent */ |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
137 obj.func = func; |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
138 obj.arg = arg; |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
139 obj.done = CreateSemaphore(NULL, 0, 1, NULL); |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
140 if (obj.done == NULL) |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
141 return -1; |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
142 |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
143 rv = _beginthread(bootstrap, |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
144 Py_SAFE_DOWNCAST(_pythread_stacksize, |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
145 Py_ssize_t, int), |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
146 &obj); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
147 if (rv == (Py_uintptr_t)-1) { |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
148 /* I've seen errno == EAGAIN here, which means "there are |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
149 * too many threads". |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
150 */ |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
151 dprintf(("%ld: PyThread_start_new_thread failed: %p errno %d\n", |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
152 PyThread_get_thread_ident(), (void*)rv, errno)); |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
153 obj.id = -1; |
| 2152 | 154 } |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
155 else { |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
156 dprintf(("%ld: PyThread_start_new_thread succeeded: %p\n", |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
157 PyThread_get_thread_ident(), (void*)rv)); |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
158 /* wait for thread to initialize, so we can get its id */ |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
159 WaitForSingleObject(obj.done, INFINITE); |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
160 assert(obj.id != -1); |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
161 } |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
162 CloseHandle((HANDLE)obj.done); |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
163 return obj.id; |
| 2152 | 164 } |
| 165 | |
| 166 /* | |
| 167 * Return the thread Id instead of an handle. The Id is said to uniquely identify the | |
| 168 * thread in the system | |
| 169 */ | |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
170 long |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
171 PyThread_get_thread_ident(void) |
| 2152 | 172 { |
| 173 if (!initialized) | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
174 PyThread_init_thread(); |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
175 |
| 2152 | 176 return GetCurrentThreadId(); |
| 177 } | |
| 178 | |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
179 static void |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
180 do_PyThread_exit_thread(int no_cleanup) |
| 2152 | 181 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
182 dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident())); |
| 2152 | 183 if (!initialized) |
| 184 if (no_cleanup) | |
| 185 _exit(0); | |
| 186 else | |
| 187 exit(0); | |
|
6029
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
188 _endthread(); |
| 2152 | 189 } |
| 190 | |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
191 void |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
192 PyThread_exit_thread(void) |
| 2152 | 193 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
194 do_PyThread_exit_thread(0); |
| 2152 | 195 } |
| 196 | |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
197 void |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
198 PyThread__exit_thread(void) |
| 2152 | 199 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
200 do_PyThread_exit_thread(1); |
| 2152 | 201 } |
| 202 | |
| 203 #ifndef NO_EXIT_PROG | |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
204 static void |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
205 do_PyThread_exit_prog(int status, int no_cleanup) |
| 2152 | 206 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
207 dprintf(("PyThread_exit_prog(%d) called\n", status)); |
| 2152 | 208 if (!initialized) |
| 209 if (no_cleanup) | |
| 210 _exit(status); | |
| 211 else | |
| 212 exit(status); | |
| 213 } | |
| 214 | |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
215 void |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
216 PyThread_exit_prog(int status) |
| 2152 | 217 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
218 do_PyThread_exit_prog(status, 0); |
| 2152 | 219 } |
| 220 | |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
221 void |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
222 PyThread__exit_prog(int status) |
| 2152 | 223 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
224 do_PyThread_exit_prog(status, 1); |
| 2152 | 225 } |
| 226 #endif /* NO_EXIT_PROG */ | |
| 227 | |
| 228 /* | |
| 229 * Lock support. It has too be implemented as semaphores. | |
| 230 * I [Dag] tried to implement it with mutex but I could find a way to | |
| 231 * tell whether a thread already own the lock or not. | |
| 232 */ | |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
233 PyThread_type_lock |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
234 PyThread_allocate_lock(void) |
| 2152 | 235 { |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
236 PNRMUTEX aLock; |
| 2152 | 237 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
238 dprintf(("PyThread_allocate_lock called\n")); |
| 2152 | 239 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
240 PyThread_init_thread(); |
| 2152 | 241 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
242 aLock = AllocNonRecursiveMutex() ; |
| 2152 | 243 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
244 dprintf(("%ld: PyThread_allocate_lock() -> %p\n", PyThread_get_thread_ident(), aLock)); |
| 2152 | 245 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
246 return (PyThread_type_lock) aLock; |
| 2152 | 247 } |
| 248 | |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
249 void |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
250 PyThread_free_lock(PyThread_type_lock aLock) |
| 2152 | 251 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
252 dprintf(("%ld: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); |
| 2152 | 253 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
254 FreeNonRecursiveMutex(aLock) ; |
| 2152 | 255 } |
| 256 | |
| 257 /* | |
| 258 * Return 1 on success if the lock was acquired | |
| 259 * | |
| 260 * and 0 if the lock was not acquired. This means a 0 is returned | |
| 261 * if the lock has already been acquired by this thread! | |
| 262 */ | |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
263 int |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
264 PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag) |
| 2152 | 265 { |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
266 int success ; |
| 2152 | 267 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
268 dprintf(("%ld: PyThread_acquire_lock(%p, %d) called\n", PyThread_get_thread_ident(),aLock, waitflag)); |
| 2152 | 269 |
|
35217
b86392f55b59
bug [ 1234979 ] Lock.acquire treats only 1 as True
Georg Brandl <georg@python.org>
parents:
29755
diff
changeset
|
270 success = aLock && EnterNonRecursiveMutex((PNRMUTEX) aLock, (waitflag ? INFINITE : 0)) == WAIT_OBJECT_0 ; |
| 2152 | 271 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
272 dprintf(("%ld: PyThread_acquire_lock(%p, %d) -> %d\n", PyThread_get_thread_ident(),aLock, waitflag, success)); |
| 2152 | 273 |
| 274 return success; | |
| 275 } | |
| 276 | |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
277 void |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
278 PyThread_release_lock(PyThread_type_lock aLock) |
| 2152 | 279 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
280 dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); |
| 2152 | 281 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
282 if (!(aLock && LeaveNonRecursiveMutex((PNRMUTEX) aLock))) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
283 dprintf(("%ld: Could not PyThread_release_lock(%p) error: %ld\n", PyThread_get_thread_ident(), aLock, GetLastError())); |
| 2152 | 284 } |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
285 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
286 /* minimum/maximum thread stack sizes supported */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
287 #define THREAD_MIN_STACKSIZE 0x8000 /* 32kB */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
288 #define THREAD_MAX_STACKSIZE 0x10000000 /* 256MB */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
289 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
290 /* set the thread stack size. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
291 * Return 0 if size is valid, -1 otherwise. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
292 */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
293 static int |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
294 _pythread_nt_set_stacksize(size_t size) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
295 { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
296 /* set to default */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
297 if (size == 0) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
298 _pythread_stacksize = 0; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
299 return 0; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
300 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
301 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
302 /* valid range? */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
303 if (size >= THREAD_MIN_STACKSIZE && size < THREAD_MAX_STACKSIZE) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
304 _pythread_stacksize = size; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
305 return 0; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
306 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
307 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
308 return -1; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
309 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
310 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
311 #define THREAD_SET_STACKSIZE(x) _pythread_nt_set_stacksize(x) |
