mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
Added C++ support in thread.h; don't use signals if not strictly
necessary, and when they are, use SIGKILL; when compiled with -DDEBUG, only print debug messages when "THREADDEBUG" is set in the environment.
This commit is contained in:
parent
0aead9f1ba
commit
d10d8291f1
3 changed files with 40 additions and 15 deletions
|
@ -1,19 +1,24 @@
|
||||||
#ifndef _THREAD_H_included
|
#ifndef _THREAD_H_included
|
||||||
#define _THREAD_H_included
|
#define _THREAD_H_included
|
||||||
|
|
||||||
#ifdef __STDC__
|
#if defined(__STDC__) || defined(__cplusplus)
|
||||||
#define _P(args) args
|
#define _P(args) args
|
||||||
#else
|
#else
|
||||||
#define _P(args) ()
|
#define _P(args) ()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef void *type_lock;
|
||||||
|
typedef void *type_sema;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
void init_thread _P((void));
|
void init_thread _P((void));
|
||||||
int start_new_thread _P((void (*)(void *), void *));
|
int start_new_thread _P((void (*)(void *), void *));
|
||||||
void exit_thread _P((void));
|
void exit_thread _P((void));
|
||||||
void _exit_thread _P((void));
|
void _exit_thread _P((void));
|
||||||
|
|
||||||
typedef void *type_lock;
|
|
||||||
|
|
||||||
type_lock allocate_lock _P((void));
|
type_lock allocate_lock _P((void));
|
||||||
void free_lock _P((type_lock));
|
void free_lock _P((type_lock));
|
||||||
int acquire_lock _P((type_lock, int));
|
int acquire_lock _P((type_lock, int));
|
||||||
|
@ -21,8 +26,6 @@ int acquire_lock _P((type_lock, int));
|
||||||
#define NOWAIT_LOCK 0
|
#define NOWAIT_LOCK 0
|
||||||
void release_lock _P((type_lock));
|
void release_lock _P((type_lock));
|
||||||
|
|
||||||
typedef void *type_sema;
|
|
||||||
|
|
||||||
type_sema allocate_sema _P((int));
|
type_sema allocate_sema _P((int));
|
||||||
void free_sema _P((type_sema));
|
void free_sema _P((type_sema));
|
||||||
void down_sema _P((type_sema));
|
void down_sema _P((type_sema));
|
||||||
|
@ -31,6 +34,10 @@ void up_sema _P((type_sema));
|
||||||
void exit_prog _P((int));
|
void exit_prog _P((int));
|
||||||
void _exit_prog _P((int));
|
void _exit_prog _P((int));
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#undef _P
|
#undef _P
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,19 +1,24 @@
|
||||||
#ifndef _THREAD_H_included
|
#ifndef _THREAD_H_included
|
||||||
#define _THREAD_H_included
|
#define _THREAD_H_included
|
||||||
|
|
||||||
#ifdef __STDC__
|
#if defined(__STDC__) || defined(__cplusplus)
|
||||||
#define _P(args) args
|
#define _P(args) args
|
||||||
#else
|
#else
|
||||||
#define _P(args) ()
|
#define _P(args) ()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef void *type_lock;
|
||||||
|
typedef void *type_sema;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
void init_thread _P((void));
|
void init_thread _P((void));
|
||||||
int start_new_thread _P((void (*)(void *), void *));
|
int start_new_thread _P((void (*)(void *), void *));
|
||||||
void exit_thread _P((void));
|
void exit_thread _P((void));
|
||||||
void _exit_thread _P((void));
|
void _exit_thread _P((void));
|
||||||
|
|
||||||
typedef void *type_lock;
|
|
||||||
|
|
||||||
type_lock allocate_lock _P((void));
|
type_lock allocate_lock _P((void));
|
||||||
void free_lock _P((type_lock));
|
void free_lock _P((type_lock));
|
||||||
int acquire_lock _P((type_lock, int));
|
int acquire_lock _P((type_lock, int));
|
||||||
|
@ -21,8 +26,6 @@ int acquire_lock _P((type_lock, int));
|
||||||
#define NOWAIT_LOCK 0
|
#define NOWAIT_LOCK 0
|
||||||
void release_lock _P((type_lock));
|
void release_lock _P((type_lock));
|
||||||
|
|
||||||
typedef void *type_sema;
|
|
||||||
|
|
||||||
type_sema allocate_sema _P((int));
|
type_sema allocate_sema _P((int));
|
||||||
void free_sema _P((type_sema));
|
void free_sema _P((type_sema));
|
||||||
void down_sema _P((type_sema));
|
void down_sema _P((type_sema));
|
||||||
|
@ -31,6 +34,10 @@ void up_sema _P((type_sema));
|
||||||
void exit_prog _P((int));
|
void exit_prog _P((int));
|
||||||
void _exit_prog _P((int));
|
void _exit_prog _P((int));
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#undef _P
|
#undef _P
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#define dprintf(args) printf args
|
static int thread_debug = 0;
|
||||||
|
#define dprintf(args) (thread_debug && printf args)
|
||||||
#else
|
#else
|
||||||
#define dprintf(args)
|
#define dprintf(args)
|
||||||
#endif
|
#endif
|
||||||
|
@ -102,6 +103,9 @@ void init_thread _P0()
|
||||||
struct sigaction s;
|
struct sigaction s;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
thread_debug = getenv("THREADDEBUG") != 0;
|
||||||
|
#endif
|
||||||
dprintf(("init_thread called\n"));
|
dprintf(("init_thread called\n"));
|
||||||
if (initialized)
|
if (initialized)
|
||||||
return;
|
return;
|
||||||
|
@ -112,7 +116,7 @@ void init_thread _P0()
|
||||||
atexit(maybe_exit);
|
atexit(maybe_exit);
|
||||||
s.sa_handler = exit_sig;
|
s.sa_handler = exit_sig;
|
||||||
sigemptyset(&s.sa_mask);
|
sigemptyset(&s.sa_mask);
|
||||||
sigaddset(&s.sa_mask, SIGUSR1);
|
/*sigaddset(&s.sa_mask, SIGUSR1);*/
|
||||||
s.sa_flags = 0;
|
s.sa_flags = 0;
|
||||||
sigaction(SIGUSR1, &s, 0);
|
sigaction(SIGUSR1, &s, 0);
|
||||||
prctl(PR_SETEXITSIG, SIGUSR1);
|
prctl(PR_SETEXITSIG, SIGUSR1);
|
||||||
|
@ -189,8 +193,12 @@ static void do_exit_thread _P1(no_cleanup, int no_cleanup)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* notify other threads */
|
/* notify other threads */
|
||||||
|
if (nthreads >= 0) {
|
||||||
|
dprintf(("kill other threads\n"));
|
||||||
for (i = 0; i < maxpidindex; i++)
|
for (i = 0; i < maxpidindex; i++)
|
||||||
(void) kill(pidlist[i], SIGUSR1);
|
(void) kill(pidlist[i], SIGKILL);
|
||||||
|
_exit(exit_status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
waiting_for_threads = 1;
|
waiting_for_threads = 1;
|
||||||
ussetlock(wait_lock);
|
ussetlock(wait_lock);
|
||||||
|
@ -212,7 +220,8 @@ static void do_exit_thread _P1(no_cleanup, int no_cleanup)
|
||||||
if (waiting_for_threads) {
|
if (waiting_for_threads) {
|
||||||
dprintf(("main thread is waiting\n"));
|
dprintf(("main thread is waiting\n"));
|
||||||
usunsetlock(wait_lock);
|
usunsetlock(wait_lock);
|
||||||
}
|
} else if (do_exit)
|
||||||
|
(void) kill(my_pid, SIGUSR1);
|
||||||
(void) usunsetlock(count_lock);
|
(void) usunsetlock(count_lock);
|
||||||
_exit(0);
|
_exit(0);
|
||||||
#endif
|
#endif
|
||||||
|
@ -361,6 +370,8 @@ type_sema allocate_sema _P1(value, int value)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dprintf(("allocate_sema called\n"));
|
dprintf(("allocate_sema called\n"));
|
||||||
|
if (!initialized)
|
||||||
|
init_thread();
|
||||||
|
|
||||||
#ifdef __sgi
|
#ifdef __sgi
|
||||||
sema = usnewsema(shared_arena, value);
|
sema = usnewsema(shared_arena, value);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue