annotate Python/thread_pth.h @ 60174:255a401c19b0

(partially) Merged revisions 79534,79537,79539,79558,79606 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r79534 | florent.xicluna | 2010-03-31 23:21:54 +0200 (mer, 31 mar 2010) | 2 lines Fix test for xml.etree when using a non-ascii path. And use check_warnings instead of catch_warnings. ........ r79537 | florent.xicluna | 2010-03-31 23:40:32 +0200 (mer, 31 mar 2010) | 2 lines Fix typo ........ r79539 | florent.xicluna | 2010-04-01 00:01:03 +0200 (jeu, 01 avr 2010) | 2 lines Replace catch_warnings with check_warnings when it makes sense. Use assertRaises context manager to simplify some tests. ........ r79558 | florent.xicluna | 2010-04-01 20:17:09 +0200 (jeu, 01 avr 2010) | 2 lines #7092: Fix some -3 warnings, and fix Lib/platform.py when the path contains a double-quote. ........ r79606 | florent.xicluna | 2010-04-02 19:26:42 +0200 (ven, 02 avr 2010) | 2 lines Backport some robotparser test and skip the test if the external resource is not available. ........
author Florent Xicluna <florent.xicluna@gmail.com>
date Fri, 02 Apr 2010 18:52:12 +0000
parents 798e0d0c7246
children fd25030223b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* GNU pth threads interface
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 http://www.gnu.org/software/pth
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 2000-05-03 Andy Dustman <andy@dustman.net>
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 Adapted from Posix threads interface
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 12 May 1997 -- david arnold <davida@pobox.com>
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 #include <stdlib.h>
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 #include <string.h>
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 #include <pth.h>
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 /* A pth mutex isn't sufficient to model the Python lock type
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 * because pth mutexes can be acquired multiple times by the
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 * same thread.
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 *
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 * The pth_lock struct implements a Python lock as a "locked?" bit
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 * and a <condition, mutex> pair. In general, if the bit can be acquired
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 * instantly, it is, else the pair is used to block the thread until the
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 * bit is cleared.
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 typedef struct {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 char locked; /* 0=unlocked, 1=locked */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 /* a <cond, mutex> pair to handle an acquire of a locked lock */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 pth_cond_t lock_released;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 pth_mutex_t mut;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 } pth_lock;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 #define CHECK_STATUS(name) if (status == -1) { printf("%d ", status); perror(name); error = 1; }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
30466
1a817694ecbd Patch #805613: Fix usage of the PTH library.
Martin v. Löwis <martin@v.loewis.de>
parents: 21766
diff changeset
33 pth_attr_t PyThread_attr;
1a817694ecbd Patch #805613: Fix usage of the PTH library.
Martin v. Löwis <martin@v.loewis.de>
parents: 21766
diff changeset
34
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 /*
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 * Initialization.
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
39 static void PyThread__init_thread(void)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 pth_init();
30466
1a817694ecbd Patch #805613: Fix usage of the PTH library.
Martin v. Löwis <martin@v.loewis.de>
parents: 21766
diff changeset
42 PyThread_attr = pth_attr_new();
1a817694ecbd Patch #805613: Fix usage of the PTH library.
Martin v. Löwis <martin@v.loewis.de>
parents: 21766
diff changeset
43 pth_attr_set(PyThread_attr, PTH_ATTR_STACK_SIZE, 1<<18);
1a817694ecbd Patch #805613: Fix usage of the PTH library.
Martin v. Löwis <martin@v.loewis.de>
parents: 21766
diff changeset
44 pth_attr_set(PyThread_attr, PTH_ATTR_JOINABLE, FALSE);
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 /*
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 * Thread support.
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
20468
ebfd87e87884 Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents: 15187
diff changeset
52 long PyThread_start_new_thread(void (*func)(void *), void *arg)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 pth_t th;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 dprintf(("PyThread_start_new_thread called\n"));
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 if (!initialized)
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 PyThread_init_thread();
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
58
30466
1a817694ecbd Patch #805613: Fix usage of the PTH library.
Martin v. Löwis <martin@v.loewis.de>
parents: 21766
diff changeset
59 th = pth_spawn(PyThread_attr,
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
60 (void* (*)(void *))func,
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 (void *)arg
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 );
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
63
20468
ebfd87e87884 Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents: 15187
diff changeset
64 return th;
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
66
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
67 long PyThread_get_thread_ident(void)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 volatile pth_t threadid;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 if (!initialized)
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 PyThread_init_thread();
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 /* Jump through some hoops for Alpha OSF/1 */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 threadid = pth_self();
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 return (long) *(long *) &threadid;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
76
59089
798e0d0c7246 Merged revisions 78393 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 30466
diff changeset
77 void PyThread_exit_thread(void)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 dprintf(("PyThread_exit_thread called\n"));
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 if (!initialized) {
59089
798e0d0c7246 Merged revisions 78393 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 30466
diff changeset
81 exit(0);
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
84
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 /*
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 * Lock support.
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 */
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
88 PyThread_type_lock PyThread_allocate_lock(void)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 pth_lock *lock;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 int status, error = 0;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
92
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 dprintf(("PyThread_allocate_lock called\n"));
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 if (!initialized)
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 PyThread_init_thread();
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
96
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 lock = (pth_lock *) malloc(sizeof(pth_lock));
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 memset((void *)lock, '\0', sizeof(pth_lock));
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 if (lock) {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 lock->locked = 0;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 status = pth_mutex_init(&lock->mut);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 CHECK_STATUS("pth_mutex_init");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 status = pth_cond_init(&lock->lock_released);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 CHECK_STATUS("pth_cond_init");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 if (error) {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 free((void *)lock);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 lock = NULL;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 }
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12611
diff changeset
110 dprintf(("PyThread_allocate_lock() -> %p\n", lock));
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 return (PyThread_type_lock) lock;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
113
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
114 void PyThread_free_lock(PyThread_type_lock lock)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 pth_lock *thelock = (pth_lock *)lock;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
117
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12611
diff changeset
118 dprintf(("PyThread_free_lock(%p) called\n", lock));
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
119
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 free((void *)thelock);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
122
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
123 int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 int success;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 pth_lock *thelock = (pth_lock *)lock;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 int status, error = 0;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
128
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12611
diff changeset
129 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
130
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 status = pth_mutex_acquire(&thelock->mut, !waitflag, NULL);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 CHECK_STATUS("pth_mutex_acquire[1]");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 success = thelock->locked == 0;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 if (success) thelock->locked = 1;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 status = pth_mutex_release( &thelock->mut );
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 CHECK_STATUS("pth_mutex_release[1]");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
137
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 if ( !success && waitflag ) {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 /* continue trying until we get the lock */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 /* mut must be locked by me -- part of the condition
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 * protocol */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 status = pth_mutex_acquire( &thelock->mut, !waitflag, NULL );
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 CHECK_STATUS("pth_mutex_acquire[2]");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 while ( thelock->locked ) {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 status = pth_cond_await(&thelock->lock_released,
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 &thelock->mut, NULL);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 CHECK_STATUS("pth_cond_await");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 thelock->locked = 1;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 status = pth_mutex_release( &thelock->mut );
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 CHECK_STATUS("pth_mutex_release[2]");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 success = 1;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 if (error) success = 0;
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12611
diff changeset
156 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 return success;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
159
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
160 void PyThread_release_lock(PyThread_type_lock lock)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 pth_lock *thelock = (pth_lock *)lock;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 int status, error = 0;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
164
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12611
diff changeset
165 dprintf(("PyThread_release_lock(%p) called\n", lock));
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
166
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 status = pth_mutex_acquire( &thelock->mut, 0, NULL );
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 CHECK_STATUS("pth_mutex_acquire[3]");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
169
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 thelock->locked = 0;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
171
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 status = pth_mutex_release( &thelock->mut );
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 CHECK_STATUS("pth_mutex_release[3]");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
174
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 /* wake up someone (anyone, if any) waiting on the lock */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 status = pth_cond_notify( &thelock->lock_released, 0 );
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 CHECK_STATUS("pth_cond_notify");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 }