Skip to content

Commit 2c8cb9f

Browse files
committed
Split thread.c into a number of system-specific files.
Added Tim Peters' pthread version.
1 parent b9c4461 commit 2c8cb9f

File tree

6 files changed

+1409
-0
lines changed

6 files changed

+1409
-0
lines changed

Python/thread_cthread.h

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/***********************************************************
2+
Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
3+
Amsterdam, The Netherlands.
4+
5+
All Rights Reserved
6+
7+
Permission to use, copy, modify, and distribute this software and its
8+
documentation for any purpose and without fee is hereby granted,
9+
provided that the above copyright notice appear in all copies and that
10+
both that copyright notice and this permission notice appear in
11+
supporting documentation, and that the names of Stichting Mathematisch
12+
Centrum or CWI not be used in advertising or publicity pertaining to
13+
distribution of the software without specific, written prior permission.
14+
15+
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16+
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17+
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18+
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21+
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22+
23+
******************************************************************/
24+
25+
#include <cthreads.h>
26+
27+
28+
/*
29+
* Initialization.
30+
*/
31+
static void _init_thread _P0()
32+
{
33+
cthread_init();
34+
}
35+
36+
/*
37+
* Thread support.
38+
*/
39+
int start_new_thread _P2(func, void (*func) _P((void *)), arg, void *arg)
40+
{
41+
#if defined(SGI_THREADS) && defined(USE_DL)
42+
long addr, size;
43+
static int local_initialized = 0;
44+
#endif /* SGI_THREADS and USE_DL */
45+
int success = 0; /* init not needed when SOLARIS_THREADS and */
46+
/* C_THREADS implemented properly */
47+
48+
dprintf(("start_new_thread called\n"));
49+
if (!initialized)
50+
init_thread();
51+
(void) cthread_fork(func, arg);
52+
return success < 0 ? 0 : 1;
53+
}
54+
55+
static void do_exit_thread _P1(no_cleanup, int no_cleanup)
56+
{
57+
dprintf(("exit_thread called\n"));
58+
if (!initialized)
59+
if (no_cleanup)
60+
_exit(0);
61+
else
62+
exit(0);
63+
cthread_exit(0);
64+
}
65+
66+
void exit_thread _P0()
67+
{
68+
do_exit_thread(0);
69+
}
70+
71+
void _exit_thread _P0()
72+
{
73+
do_exit_thread(1);
74+
}
75+
76+
#ifndef NO_EXIT_PROG
77+
static void do_exit_prog _P2(status, int status, no_cleanup, int no_cleanup)
78+
{
79+
dprintf(("exit_prog(%d) called\n", status));
80+
if (!initialized)
81+
if (no_cleanup)
82+
_exit(status);
83+
else
84+
exit(status);
85+
}
86+
87+
void exit_prog _P1(status, int status)
88+
{
89+
do_exit_prog(status, 0);
90+
}
91+
92+
void _exit_prog _P1(status, int status)
93+
{
94+
do_exit_prog(status, 1);
95+
}
96+
#endif /* NO_EXIT_PROG */
97+
98+
/*
99+
* Lock support.
100+
*/
101+
type_lock allocate_lock _P0()
102+
{
103+
104+
dprintf(("allocate_lock called\n"));
105+
if (!initialized)
106+
init_thread();
107+
108+
dprintf(("allocate_lock() -> %lx\n", (long)lock));
109+
return (type_lock) lock;
110+
}
111+
112+
void free_lock _P1(lock, type_lock lock)
113+
{
114+
dprintf(("free_lock(%lx) called\n", (long)lock));
115+
}
116+
117+
int acquire_lock _P2(lock, type_lock lock, waitflag, int waitflag)
118+
{
119+
int success;
120+
121+
dprintf(("acquire_lock(%lx, %d) called\n", (long)lock, waitflag));
122+
dprintf(("acquire_lock(%lx, %d) -> %d\n", (long)lock, waitflag, success));
123+
return success;
124+
}
125+
126+
void release_lock _P1(lock, type_lock lock)
127+
{
128+
dprintf(("release_lock(%lx) called\n", (long)lock));
129+
}
130+
131+
/*
132+
* Semaphore support.
133+
*/
134+
type_sema allocate_sema _P1(value, int value)
135+
{
136+
dprintf(("allocate_sema called\n"));
137+
if (!initialized)
138+
init_thread();
139+
140+
dprintf(("allocate_sema() -> %lx\n", (long) sema));
141+
return (type_sema) sema;
142+
}
143+
144+
void free_sema _P1(sema, type_sema sema)
145+
{
146+
dprintf(("free_sema(%lx) called\n", (long) sema));
147+
}
148+
149+
void down_sema _P1(sema, type_sema sema)
150+
{
151+
dprintf(("down_sema(%lx) called\n", (long) sema));
152+
dprintf(("down_sema(%lx) return\n", (long) sema));
153+
}
154+
155+
void up_sema _P1(sema, type_sema sema)
156+
{
157+
dprintf(("up_sema(%lx)\n", (long) sema));
158+
}

Python/thread_foobar.h

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/***********************************************************
2+
Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
3+
Amsterdam, The Netherlands.
4+
5+
All Rights Reserved
6+
7+
Permission to use, copy, modify, and distribute this software and its
8+
documentation for any purpose and without fee is hereby granted,
9+
provided that the above copyright notice appear in all copies and that
10+
both that copyright notice and this permission notice appear in
11+
supporting documentation, and that the names of Stichting Mathematisch
12+
Centrum or CWI not be used in advertising or publicity pertaining to
13+
distribution of the software without specific, written prior permission.
14+
15+
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16+
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17+
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18+
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21+
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22+
23+
******************************************************************/
24+
25+
/*
26+
* Initialization.
27+
*/
28+
static void _init_thread _P0()
29+
{
30+
}
31+
32+
/*
33+
* Thread support.
34+
*/
35+
int start_new_thread _P2(func, void (*func) _P((void *)), arg, void *arg)
36+
{
37+
int success = 0; /* init not needed when SOLARIS_THREADS and */
38+
/* C_THREADS implemented properly */
39+
40+
dprintf(("start_new_thread called\n"));
41+
if (!initialized)
42+
init_thread();
43+
return success < 0 ? 0 : 1;
44+
}
45+
46+
static void do_exit_thread _P1(no_cleanup, int no_cleanup)
47+
{
48+
dprintf(("exit_thread called\n"));
49+
if (!initialized)
50+
if (no_cleanup)
51+
_exit(0);
52+
else
53+
exit(0);
54+
}
55+
56+
void exit_thread _P0()
57+
{
58+
do_exit_thread(0);
59+
}
60+
61+
void _exit_thread _P0()
62+
{
63+
do_exit_thread(1);
64+
}
65+
66+
#ifndef NO_EXIT_PROG
67+
static void do_exit_prog _P2(status, int status, no_cleanup, int no_cleanup)
68+
{
69+
dprintf(("exit_prog(%d) called\n", status));
70+
if (!initialized)
71+
if (no_cleanup)
72+
_exit(status);
73+
else
74+
exit(status);
75+
}
76+
77+
void exit_prog _P1(status, int status)
78+
{
79+
do_exit_prog(status, 0);
80+
}
81+
82+
void _exit_prog _P1(status, int status)
83+
{
84+
do_exit_prog(status, 1);
85+
}
86+
#endif /* NO_EXIT_PROG */
87+
88+
/*
89+
* Lock support.
90+
*/
91+
type_lock allocate_lock _P0()
92+
{
93+
94+
dprintf(("allocate_lock called\n"));
95+
if (!initialized)
96+
init_thread();
97+
98+
dprintf(("allocate_lock() -> %lx\n", (long)lock));
99+
return (type_lock) lock;
100+
}
101+
102+
void free_lock _P1(lock, type_lock lock)
103+
{
104+
dprintf(("free_lock(%lx) called\n", (long)lock));
105+
}
106+
107+
int acquire_lock _P2(lock, type_lock lock, waitflag, int waitflag)
108+
{
109+
int success;
110+
111+
dprintf(("acquire_lock(%lx, %d) called\n", (long)lock, waitflag));
112+
dprintf(("acquire_lock(%lx, %d) -> %d\n", (long)lock, waitflag, success));
113+
return success;
114+
}
115+
116+
void release_lock _P1(lock, type_lock lock)
117+
{
118+
dprintf(("release_lock(%lx) called\n", (long)lock));
119+
}
120+
121+
/*
122+
* Semaphore support.
123+
*/
124+
type_sema allocate_sema _P1(value, int value)
125+
{
126+
dprintf(("allocate_sema called\n"));
127+
if (!initialized)
128+
init_thread();
129+
130+
dprintf(("allocate_sema() -> %lx\n", (long) sema));
131+
return (type_sema) sema;
132+
}
133+
134+
void free_sema _P1(sema, type_sema sema)
135+
{
136+
dprintf(("free_sema(%lx) called\n", (long) sema));
137+
}
138+
139+
void down_sema _P1(sema, type_sema sema)
140+
{
141+
dprintf(("down_sema(%lx) called\n", (long) sema));
142+
dprintf(("down_sema(%lx) return\n", (long) sema));
143+
}
144+
145+
void up_sema _P1(sema, type_sema sema)
146+
{
147+
dprintf(("up_sema(%lx)\n", (long) sema));
148+
}

0 commit comments

Comments
 (0)