Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ecebf1

Browse files
committed
Changes needed by NeXT (the only platform that seems to use this).
1 parent f2d125b commit 3ecebf1

1 file changed

Lines changed: 38 additions & 3 deletions

File tree

Python/thread_cthread.h

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2222
2323
******************************************************************/
2424

25-
#include <cthreads.h>
25+
#include <mach/cthreads.h>
2626

2727

2828
/*
@@ -44,14 +44,18 @@ int start_new_thread _P2(func, void (*func) _P((void *)), arg, void *arg)
4444
dprintf(("start_new_thread called\n"));
4545
if (!initialized)
4646
init_thread();
47-
(void) cthread_fork(func, arg);
47+
/* looks like solaris detaches the thread to never rejoin
48+
* so well do it here
49+
*/
50+
cthread_detach(cthread_fork((cthread_fn_t) func, arg));
4851
return success < 0 ? 0 : 1;
4952
}
5053

5154
long get_thread_ident _P0()
5255
{
5356
if (!initialized)
5457
init_thread();
58+
return (long) cthread_self();
5559
}
5660

5761
static void do_exit_thread _P1(no_cleanup, int no_cleanup)
@@ -84,6 +88,10 @@ static void do_exit_prog _P2(status, int status, no_cleanup, int no_cleanup)
8488
_exit(status);
8589
else
8690
exit(status);
91+
if (no_cleanup)
92+
_exit(status);
93+
else
94+
exit(status);
8795
}
8896

8997
void exit_prog _P1(status, int status)
@@ -102,39 +110,66 @@ void _exit_prog _P1(status, int status)
102110
*/
103111
type_lock allocate_lock _P0()
104112
{
113+
mutex_t lock;
105114

106115
dprintf(("allocate_lock called\n"));
107116
if (!initialized)
108117
init_thread();
109118

119+
lock = mutex_alloc();
120+
if (mutex_init(lock)) {
121+
perror("mutex_init");
122+
free((void *) lock);
123+
lock = 0;
124+
}
110125
dprintf(("allocate_lock() -> %lx\n", (long)lock));
111126
return (type_lock) lock;
112127
}
113128

114129
void free_lock _P1(lock, type_lock lock)
115130
{
116131
dprintf(("free_lock(%lx) called\n", (long)lock));
132+
mutex_free(lock);
117133
}
118134

119135
int acquire_lock _P2(lock, type_lock lock, waitflag, int waitflag)
120136
{
121-
int success;
137+
int success = FALSE;
122138

123139
dprintf(("acquire_lock(%lx, %d) called\n", (long)lock, waitflag));
140+
if (waitflag) { /* blocking */
141+
mutex_lock(lock);
142+
success = TRUE;
143+
} else { /* non blocking */
144+
success = mutex_try_lock(lock);
145+
}
124146
dprintf(("acquire_lock(%lx, %d) -> %d\n", (long)lock, waitflag, success));
125147
return success;
126148
}
127149

128150
void release_lock _P1(lock, type_lock lock)
129151
{
130152
dprintf(("release_lock(%lx) called\n", (long)lock));
153+
mutex_unlock((mutex_t )lock);
131154
}
132155

133156
/*
134157
* Semaphore support.
158+
*
159+
* This implementation is ripped directly from the pthreads implementation.
160+
* Which is to say that it is 100% non-functional at this time.
161+
*
162+
* Assuming the page is still up, documentation can be found at:
163+
*
164+
* http://www.doc.ic.ac.uk/~mac/manuals/solaris-manual-pages/solaris/usr/man/man2/_lwp_sema_wait.2.html
165+
*
166+
* Looking at the man page, it seems that one could easily implement a
167+
* semaphore using a condition.
168+
*
135169
*/
136170
type_sema allocate_sema _P1(value, int value)
137171
{
172+
char *sema = 0;
138173
dprintf(("allocate_sema called\n"));
139174
if (!initialized)
140175
init_thread();

0 commit comments

Comments
 (0)