Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
e8934125
Kaydet (Commit)
e8934125
authored
Ock 13, 1993
tarafından
Sjoerd Mullender
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added error checking.
Improved coexistance with dl module.
üst
dd104400
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
21 deletions
+82
-21
thread.c
Python/thread.c
+82
-21
No files found.
Python/thread.c
Dosyayı görüntüle @
e8934125
...
@@ -14,6 +14,7 @@ static int thread_debug = 0;
...
@@ -14,6 +14,7 @@ static int thread_debug = 0;
#include <sys/types.h>
#include <sys/types.h>
#include <sys/prctl.h>
#include <sys/prctl.h>
#include <ulocks.h>
#include <ulocks.h>
#include <errno.h>
#define MAXPROC 100
/* max # of threads that can be started */
#define MAXPROC 100
/* max # of threads that can be started */
...
@@ -101,6 +102,9 @@ void init_thread _P0()
...
@@ -101,6 +102,9 @@ void init_thread _P0()
{
{
#ifdef __sgi
#ifdef __sgi
struct
sigaction
s
;
struct
sigaction
s
;
#ifdef USE_DL
long
addr
,
size
;
#endif
#endif
#endif
#ifdef DEBUG
#ifdef DEBUG
...
@@ -112,6 +116,17 @@ void init_thread _P0()
...
@@ -112,6 +116,17 @@ void init_thread _P0()
dprintf
((
"init_thread called
\n
"
));
dprintf
((
"init_thread called
\n
"
));
#ifdef __sgi
#ifdef __sgi
#ifdef USE_DL
if
((
size
=
usconfig
(
CONF_INITSIZE
,
64
*
1024
))
<
0
)
perror
(
"usconfig - CONF_INITSIZE (check)"
);
if
(
usconfig
(
CONF_INITSIZE
,
size
)
<
0
)
perror
(
"usconfig - CONF_INITSIZE (reset)"
);
addr
=
(
long
)
dl_getrange
(
size
+
sizeof
(
ushdr_t
));
dprintf
((
"trying to use addr %lx-%lx for shared arena
\n
"
,
addr
,
addr
+
size
));
errno
=
0
;
if
((
addr
=
usconfig
(
CONF_ATTACHADDR
,
addr
))
<
0
&&
errno
!=
0
)
perror
(
"usconfig - CONF_ATTACHADDR (set)"
);
#endif
if
(
usconfig
(
CONF_INITUSERS
,
16
)
<
0
)
if
(
usconfig
(
CONF_INITUSERS
,
16
)
<
0
)
perror
(
"usconfig - CONF_INITUSERS"
);
perror
(
"usconfig - CONF_INITUSERS"
);
my_pid
=
getpid
();
/* so that we know which is the main thread */
my_pid
=
getpid
();
/* so that we know which is the main thread */
...
@@ -128,13 +143,16 @@ void init_thread _P0()
...
@@ -128,13 +143,16 @@ void init_thread _P0()
/*usconfig(CONF_LOCKTYPE, US_DEBUGPLUS);*/
/*usconfig(CONF_LOCKTYPE, US_DEBUGPLUS);*/
if
((
shared_arena
=
usinit
(
tmpnam
(
0
)))
==
0
)
if
((
shared_arena
=
usinit
(
tmpnam
(
0
)))
==
0
)
perror
(
"usinit"
);
perror
(
"usinit"
);
count_lock
=
usnewlock
(
shared_arena
);
#ifdef USE_DL
if
(
usconfig
(
CONF_ATTACHADDR
,
addr
)
<
0
)
/* reset address */
perror
(
"usconfig - CONF_ATTACHADDR (reset)"
);
#endif
if
((
count_lock
=
usnewlock
(
shared_arena
))
==
NULL
)
perror
(
"usnewlock (count_lock)"
);
(
void
)
usinitlock
(
count_lock
);
(
void
)
usinitlock
(
count_lock
);
wait_lock
=
usnewlock
(
shared_arena
);
if
((
wait_lock
=
usnewlock
(
shared_arena
))
==
NULL
)
perror
(
"usnewlock (wait_lock)"
);
dprintf
((
"arena start: %lx, arena size: %ld
\n
"
,
(
long
)
shared_arena
,
(
long
)
usconfig
(
CONF_GETSIZE
,
shared_arena
)));
dprintf
((
"arena start: %lx, arena size: %ld
\n
"
,
(
long
)
shared_arena
,
(
long
)
usconfig
(
CONF_GETSIZE
,
shared_arena
)));
#ifdef USE_DL
/* for python */
dl_setrange
((
long
)
shared_arena
,
(
long
)
shared_arena
+
64
*
1024
);
#endif
#endif
#endif
#ifdef sun
#ifdef sun
lwp_setstkcache
(
STACKSIZE
,
NSTACKS
);
lwp_setstkcache
(
STACKSIZE
,
NSTACKS
);
...
@@ -151,6 +169,10 @@ int start_new_thread _P2(func, void (*func) _P((void *)), arg, void *arg)
...
@@ -151,6 +169,10 @@ int start_new_thread _P2(func, void (*func) _P((void *)), arg, void *arg)
{
{
#ifdef sun
#ifdef sun
thread_t
tid
;
thread_t
tid
;
#endif
#if defined(__sgi) && defined(USE_DL)
long
addr
,
size
;
static
int
local_initialized
=
0
;
#endif
#endif
int
success
=
0
;
/* init not needed when SOLARIS and */
int
success
=
0
;
/* init not needed when SOLARIS and */
/* C_THREADS implemented properly */
/* C_THREADS implemented properly */
...
@@ -159,18 +181,42 @@ int start_new_thread _P2(func, void (*func) _P((void *)), arg, void *arg)
...
@@ -159,18 +181,42 @@ int start_new_thread _P2(func, void (*func) _P((void *)), arg, void *arg)
if
(
!
initialized
)
if
(
!
initialized
)
init_thread
();
init_thread
();
#ifdef __sgi
#ifdef __sgi
if
(
ussetlock
(
count_lock
)
==
0
)
switch
(
ussetlock
(
count_lock
))
{
return
0
;
case
0
:
return
0
;
case
-
1
:
perror
(
"ussetlock (count_lock)"
);
}
if
(
maxpidindex
>=
MAXPROC
)
if
(
maxpidindex
>=
MAXPROC
)
success
=
-
1
;
success
=
-
1
;
else
{
else
{
success
=
sproc
(
func
,
PR_SALL
,
arg
);
#ifdef USE_DL
if
(
!
local_initialized
)
{
if
((
size
=
usconfig
(
CONF_INITSIZE
,
64
*
1024
))
<
0
)
perror
(
"usconfig - CONF_INITSIZE (check)"
);
if
(
usconfig
(
CONF_INITSIZE
,
size
)
<
0
)
perror
(
"usconfig - CONF_INITSIZE (reset)"
);
addr
=
(
long
)
dl_getrange
(
size
+
sizeof
(
ushdr_t
));
dprintf
((
"trying to use addr %lx-%lx for sproc
\n
"
,
addr
,
addr
+
size
));
errno
=
0
;
if
((
addr
=
usconfig
(
CONF_ATTACHADDR
,
addr
))
<
0
&&
errno
!=
0
)
perror
(
"usconfig - CONF_ATTACHADDR (set)"
);
}
#endif
if
((
success
=
sproc
(
func
,
PR_SALL
,
arg
))
<
0
)
perror
(
"sproc"
);
#ifdef USE_DL
if
(
!
local_initialized
)
{
if
(
usconfig
(
CONF_ATTACHADDR
,
addr
)
<
0
)
/* reset address */
perror
(
"usconfig - CONF_ATTACHADDR (reset)"
);
local_initialized
=
1
;
}
#endif
if
(
success
>=
0
)
{
if
(
success
>=
0
)
{
nthreads
++
;
nthreads
++
;
pidlist
[
maxpidindex
++
]
=
success
;
pidlist
[
maxpidindex
++
]
=
success
;
}
}
}
}
(
void
)
usunsetlock
(
count_lock
);
if
(
usunsetlock
(
count_lock
)
<
0
)
perror
(
"usunsetlock (count_lock)"
);
#endif
#endif
#ifdef SOLARIS
#ifdef SOLARIS
(
void
)
thread_create
(
0
,
0
,
func
,
arg
,
THREAD_NEW_LWP
);
(
void
)
thread_create
(
0
,
0
,
func
,
arg
,
THREAD_NEW_LWP
);
...
@@ -193,7 +239,8 @@ static void do_exit_thread _P1(no_cleanup, int no_cleanup)
...
@@ -193,7 +239,8 @@ static void do_exit_thread _P1(no_cleanup, int no_cleanup)
else
else
exit
(
0
);
exit
(
0
);
#ifdef __sgi
#ifdef __sgi
(
void
)
ussetlock
(
count_lock
);
if
(
ussetlock
(
count_lock
)
<
0
)
perror
(
"ussetlock (count_lock)"
);
nthreads
--
;
nthreads
--
;
if
(
getpid
()
==
my_pid
)
{
if
(
getpid
()
==
my_pid
)
{
/* main thread; wait for other threads to exit */
/* main thread; wait for other threads to exit */
...
@@ -210,7 +257,8 @@ static void do_exit_thread _P1(no_cleanup, int no_cleanup)
...
@@ -210,7 +257,8 @@ static void do_exit_thread _P1(no_cleanup, int no_cleanup)
}
}
}
}
waiting_for_threads
=
1
;
waiting_for_threads
=
1
;
ussetlock
(
wait_lock
);
if
(
ussetlock
(
wait_lock
)
<
0
)
perror
(
"ussetlock (wait_lock)"
);
for
(;;)
{
for
(;;)
{
if
(
nthreads
<
0
)
{
if
(
nthreads
<
0
)
{
dprintf
((
"really exit (%d)
\n
"
,
exit_status
));
dprintf
((
"really exit (%d)
\n
"
,
exit_status
));
...
@@ -219,19 +267,24 @@ static void do_exit_thread _P1(no_cleanup, int no_cleanup)
...
@@ -219,19 +267,24 @@ static void do_exit_thread _P1(no_cleanup, int no_cleanup)
else
else
exit
(
exit_status
);
exit
(
exit_status
);
}
}
usunsetlock
(
count_lock
);
if
(
usunsetlock
(
count_lock
)
<
0
)
perror
(
"usunsetlock (count_lock)"
);
dprintf
((
"waiting for other threads (%d)
\n
"
,
nthreads
));
dprintf
((
"waiting for other threads (%d)
\n
"
,
nthreads
));
ussetlock
(
wait_lock
);
if
(
ussetlock
(
wait_lock
)
<
0
)
ussetlock
(
count_lock
);
perror
(
"ussetlock (wait_lock)"
);
if
(
ussetlock
(
count_lock
)
<
0
)
perror
(
"ussetlock (count_lock)"
);
}
}
}
}
/* not the main thread */
/* not the main thread */
if
(
waiting_for_threads
)
{
if
(
waiting_for_threads
)
{
dprintf
((
"main thread is waiting
\n
"
));
dprintf
((
"main thread is waiting
\n
"
));
usunsetlock
(
wait_lock
);
if
(
usunsetlock
(
wait_lock
)
<
0
)
perror
(
"usunsetlock (wait_lock)"
);
}
else
if
(
do_exit
)
}
else
if
(
do_exit
)
(
void
)
kill
(
my_pid
,
SIGUSR1
);
(
void
)
kill
(
my_pid
,
SIGUSR1
);
(
void
)
usunsetlock
(
count_lock
);
if
(
usunsetlock
(
count_lock
)
<
0
)
perror
(
"usunsetlock (count_lock)"
);
_exit
(
0
);
_exit
(
0
);
#endif
#endif
#ifdef SOLARIS
#ifdef SOLARIS
...
@@ -301,7 +354,8 @@ type_lock allocate_lock _P0()
...
@@ -301,7 +354,8 @@ type_lock allocate_lock _P0()
init_thread
();
init_thread
();
#ifdef __sgi
#ifdef __sgi
lock
=
usnewlock
(
shared_arena
);
if
((
lock
=
usnewlock
(
shared_arena
))
==
NULL
)
perror
(
"usnewlock"
);
(
void
)
usinitlock
(
lock
);
(
void
)
usinitlock
(
lock
);
#endif
#endif
#ifdef sun
#ifdef sun
...
@@ -332,10 +386,13 @@ int acquire_lock _P2(lock, type_lock lock, waitflag, int waitflag)
...
@@ -332,10 +386,13 @@ int acquire_lock _P2(lock, type_lock lock, waitflag, int waitflag)
dprintf
((
"acquire_lock(%lx, %d) called
\n
"
,
(
long
)
lock
,
waitflag
));
dprintf
((
"acquire_lock(%lx, %d) called
\n
"
,
(
long
)
lock
,
waitflag
));
#ifdef __sgi
#ifdef __sgi
errno
=
0
;
/* clear it just in case */
if
(
waitflag
)
if
(
waitflag
)
success
=
ussetlock
((
ulock_t
)
lock
);
success
=
ussetlock
((
ulock_t
)
lock
);
else
else
success
=
uscsetlock
((
ulock_t
)
lock
,
1
);
/* Try it once */
success
=
uscsetlock
((
ulock_t
)
lock
,
1
);
/* Try it once */
if
(
success
<
0
)
perror
(
waitflag
?
"ussetlock"
:
"uscsetlock"
);
#endif
#endif
#ifdef sun
#ifdef sun
success
=
0
;
success
=
0
;
...
@@ -359,7 +416,8 @@ void release_lock _P1(lock, type_lock lock)
...
@@ -359,7 +416,8 @@ void release_lock _P1(lock, type_lock lock)
{
{
dprintf
((
"release_lock(%lx) called
\n
"
,
(
long
)
lock
));
dprintf
((
"release_lock(%lx) called
\n
"
,
(
long
)
lock
));
#ifdef __sgi
#ifdef __sgi
(
void
)
usunsetlock
((
ulock_t
)
lock
);
if
(
usunsetlock
((
ulock_t
)
lock
)
<
0
)
perror
(
"usunsetlock"
);
#endif
#endif
#ifdef sun
#ifdef sun
(
void
)
mon_enter
(((
struct
lock
*
)
lock
)
->
lock_monitor
);
(
void
)
mon_enter
(((
struct
lock
*
)
lock
)
->
lock_monitor
);
...
@@ -383,7 +441,8 @@ type_sema allocate_sema _P1(value, int value)
...
@@ -383,7 +441,8 @@ type_sema allocate_sema _P1(value, int value)
init_thread
();
init_thread
();
#ifdef __sgi
#ifdef __sgi
sema
=
usnewsema
(
shared_arena
,
value
);
if
((
sema
=
usnewsema
(
shared_arena
,
value
))
==
NULL
)
perror
(
"usnewsema"
);
dprintf
((
"allocate_sema() -> %lx
\n
"
,
(
long
)
sema
));
dprintf
((
"allocate_sema() -> %lx
\n
"
,
(
long
)
sema
));
return
(
type_sema
)
sema
;
return
(
type_sema
)
sema
;
#endif
#endif
...
@@ -401,7 +460,8 @@ void down_sema _P1(sema, type_sema sema)
...
@@ -401,7 +460,8 @@ void down_sema _P1(sema, type_sema sema)
{
{
dprintf
((
"down_sema(%lx) called
\n
"
,
(
long
)
sema
));
dprintf
((
"down_sema(%lx) called
\n
"
,
(
long
)
sema
));
#ifdef __sgi
#ifdef __sgi
(
void
)
uspsema
((
usema_t
*
)
sema
);
if
(
uspsema
((
usema_t
*
)
sema
)
<
0
)
perror
(
"uspsema"
);
#endif
#endif
dprintf
((
"down_sema(%lx) return
\n
"
,
(
long
)
sema
));
dprintf
((
"down_sema(%lx) return
\n
"
,
(
long
)
sema
));
}
}
...
@@ -410,6 +470,7 @@ void up_sema _P1(sema, type_sema sema)
...
@@ -410,6 +470,7 @@ void up_sema _P1(sema, type_sema sema)
{
{
dprintf
((
"up_sema(%lx)
\n
"
,
(
long
)
sema
));
dprintf
((
"up_sema(%lx)
\n
"
,
(
long
)
sema
));
#ifdef __sgi
#ifdef __sgi
(
void
)
usvsema
((
usema_t
*
)
sema
);
if
(
usvsema
((
usema_t
*
)
sema
)
<
0
)
perror
(
"usvsema"
);
#endif
#endif
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment