mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
reformat for PEP-7 style conformance
This commit is contained in:
parent
6904959921
commit
c4c127b850
1 changed files with 128 additions and 117 deletions
|
@ -28,85 +28,86 @@ PyThread__init_thread(void)
|
||||||
long
|
long
|
||||||
PyThread_start_new_thread(void (*func)(void *), void *arg)
|
PyThread_start_new_thread(void (*func)(void *), void *arg)
|
||||||
{
|
{
|
||||||
int aThread;
|
int aThread;
|
||||||
int success = 0;
|
int success = 0;
|
||||||
|
|
||||||
aThread = _beginthread(func,NULL,65536,arg);
|
aThread = _beginthread(func,NULL,65536,arg);
|
||||||
|
|
||||||
if( aThread == -1 ) {
|
if (aThread == -1) {
|
||||||
success = -1;
|
success = -1;
|
||||||
fprintf(stderr,"aThread failed == %d",aThread);
|
fprintf(stderr, "aThread failed == %d", aThread);
|
||||||
dprintf(("_beginthread failed. return %ld\n", errno));
|
dprintf(("_beginthread failed. return %ld\n", errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
long
|
||||||
PyThread_get_thread_ident(void)
|
PyThread_get_thread_ident(void)
|
||||||
{
|
{
|
||||||
#if !defined(PYCC_GCC)
|
#if !defined(PYCC_GCC)
|
||||||
PPIB pib;
|
PPIB pib;
|
||||||
PTIB tib;
|
PTIB tib;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
PyThread_init_thread();
|
PyThread_init_thread();
|
||||||
|
|
||||||
#if defined(PYCC_GCC)
|
#if defined(PYCC_GCC)
|
||||||
return _gettid();
|
return _gettid();
|
||||||
#else
|
#else
|
||||||
DosGetInfoBlocks(&tib,&pib);
|
DosGetInfoBlocks(&tib, &pib);
|
||||||
return tib->tib_ptib2->tib2_ultid;
|
return tib->tib_ptib2->tib2_ultid;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_PyThread_exit_thread(int no_cleanup)
|
do_PyThread_exit_thread(int no_cleanup)
|
||||||
{
|
{
|
||||||
dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident()));
|
dprintf(("%ld: PyThread_exit_thread called\n",
|
||||||
if (!initialized)
|
PyThread_get_thread_ident()));
|
||||||
if (no_cleanup)
|
if (!initialized)
|
||||||
_exit(0);
|
if (no_cleanup)
|
||||||
else
|
_exit(0);
|
||||||
exit(0);
|
else
|
||||||
_endthread();
|
exit(0);
|
||||||
|
_endthread();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PyThread_exit_thread(void)
|
PyThread_exit_thread(void)
|
||||||
{
|
{
|
||||||
do_PyThread_exit_thread(0);
|
do_PyThread_exit_thread(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PyThread__exit_thread(void)
|
PyThread__exit_thread(void)
|
||||||
{
|
{
|
||||||
do_PyThread_exit_thread(1);
|
do_PyThread_exit_thread(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NO_EXIT_PROG
|
#ifndef NO_EXIT_PROG
|
||||||
static void
|
static void
|
||||||
do_PyThread_exit_prog(int status, int no_cleanup)
|
do_PyThread_exit_prog(int status, int no_cleanup)
|
||||||
{
|
{
|
||||||
dprintf(("PyThread_exit_prog(%d) called\n", status));
|
dprintf(("PyThread_exit_prog(%d) called\n", status));
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
if (no_cleanup)
|
if (no_cleanup)
|
||||||
_exit(status);
|
_exit(status);
|
||||||
else
|
else
|
||||||
exit(status);
|
exit(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PyThread_exit_prog(int status)
|
PyThread_exit_prog(int status)
|
||||||
{
|
{
|
||||||
do_PyThread_exit_prog(status, 0);
|
do_PyThread_exit_prog(status, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PyThread__exit_prog(int status)
|
PyThread__exit_prog(int status)
|
||||||
{
|
{
|
||||||
do_PyThread_exit_prog(status, 1);
|
do_PyThread_exit_prog(status, 1);
|
||||||
}
|
}
|
||||||
#endif /* NO_EXIT_PROG */
|
#endif /* NO_EXIT_PROG */
|
||||||
|
|
||||||
|
@ -117,42 +118,42 @@ PyThread__exit_prog(int status)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct os2_lock_t {
|
typedef struct os2_lock_t {
|
||||||
int is_set;
|
int is_set;
|
||||||
HEV changed;
|
HEV changed;
|
||||||
} *type_os2_lock;
|
} *type_os2_lock;
|
||||||
|
|
||||||
PyThread_type_lock
|
PyThread_type_lock
|
||||||
PyThread_allocate_lock(void)
|
PyThread_allocate_lock(void)
|
||||||
{
|
{
|
||||||
#if defined(PYCC_GCC)
|
#if defined(PYCC_GCC)
|
||||||
_fmutex *sem = malloc(sizeof(_fmutex));
|
_fmutex *sem = malloc(sizeof(_fmutex));
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
PyThread_init_thread();
|
PyThread_init_thread();
|
||||||
dprintf(("%ld: PyThread_allocate_lock() -> %lx\n",
|
dprintf(("%ld: PyThread_allocate_lock() -> %lx\n",
|
||||||
PyThread_get_thread_ident(),
|
PyThread_get_thread_ident(),
|
||||||
(long)sem));
|
(long)sem));
|
||||||
if (_fmutex_create(sem, 0)) {
|
if (_fmutex_create(sem, 0)) {
|
||||||
free(sem);
|
free(sem);
|
||||||
sem = NULL;
|
sem = NULL;
|
||||||
}
|
}
|
||||||
return (PyThread_type_lock) sem;
|
return (PyThread_type_lock)sem;
|
||||||
#else
|
#else
|
||||||
APIRET rc;
|
APIRET rc;
|
||||||
type_os2_lock lock = (type_os2_lock)malloc(sizeof(struct os2_lock_t));
|
type_os2_lock lock = (type_os2_lock)malloc(sizeof(struct os2_lock_t));
|
||||||
|
|
||||||
dprintf(("PyThread_allocate_lock called\n"));
|
dprintf(("PyThread_allocate_lock called\n"));
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
PyThread_init_thread();
|
PyThread_init_thread();
|
||||||
|
|
||||||
lock->is_set = 0;
|
lock->is_set = 0;
|
||||||
|
|
||||||
DosCreateEventSem(NULL, &lock->changed, 0, 0);
|
DosCreateEventSem(NULL, &lock->changed, 0, 0);
|
||||||
|
|
||||||
dprintf(("%ld: PyThread_allocate_lock() -> %p\n",
|
dprintf(("%ld: PyThread_allocate_lock() -> %p\n",
|
||||||
PyThread_get_thread_ident(),
|
PyThread_get_thread_ident(),
|
||||||
lock->changed));
|
lock->changed));
|
||||||
|
|
||||||
return (PyThread_type_lock) lock;
|
return (PyThread_type_lock)lock;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,19 +161,20 @@ void
|
||||||
PyThread_free_lock(PyThread_type_lock aLock)
|
PyThread_free_lock(PyThread_type_lock aLock)
|
||||||
{
|
{
|
||||||
#if !defined(PYCC_GCC)
|
#if !defined(PYCC_GCC)
|
||||||
type_os2_lock lock = (type_os2_lock)aLock;
|
type_os2_lock lock = (type_os2_lock)aLock;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dprintf(("%ld: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock));
|
dprintf(("%ld: PyThread_free_lock(%p) called\n",
|
||||||
|
PyThread_get_thread_ident(),aLock));
|
||||||
|
|
||||||
#if defined(PYCC_GCC)
|
#if defined(PYCC_GCC)
|
||||||
if (aLock) {
|
if (aLock) {
|
||||||
_fmutex_close((_fmutex *)aLock);
|
_fmutex_close((_fmutex *)aLock);
|
||||||
free((_fmutex *)aLock);
|
free((_fmutex *)aLock);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
DosCloseEventSem(lock->changed);
|
DosCloseEventSem(lock->changed);
|
||||||
free(aLock);
|
free(aLock);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,77 +187,86 @@ int
|
||||||
PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag)
|
PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag)
|
||||||
{
|
{
|
||||||
#if !defined(PYCC_GCC)
|
#if !defined(PYCC_GCC)
|
||||||
int done = 0;
|
int done = 0;
|
||||||
ULONG count;
|
ULONG count;
|
||||||
PID pid = 0;
|
PID pid = 0;
|
||||||
TID tid = 0;
|
TID tid = 0;
|
||||||
type_os2_lock lock = (type_os2_lock)aLock;
|
type_os2_lock lock = (type_os2_lock)aLock;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dprintf(("%ld: PyThread_acquire_lock(%p, %d) called\n", PyThread_get_thread_ident(),
|
dprintf(("%ld: PyThread_acquire_lock(%p, %d) called\n",
|
||||||
aLock, waitflag));
|
PyThread_get_thread_ident(),
|
||||||
|
aLock,
|
||||||
|
waitflag));
|
||||||
|
|
||||||
#if defined(PYCC_GCC)
|
#if defined(PYCC_GCC)
|
||||||
/* always successful if the lock doesn't exist */
|
/* always successful if the lock doesn't exist */
|
||||||
if (aLock && _fmutex_request((_fmutex *)aLock, waitflag ? 0 : _FMR_NOWAIT))
|
if (aLock &&
|
||||||
return 0;
|
_fmutex_request((_fmutex *)aLock, waitflag ? 0 : _FMR_NOWAIT))
|
||||||
|
return 0;
|
||||||
#else
|
#else
|
||||||
while (!done) {
|
while (!done) {
|
||||||
/* if the lock is currently set, we have to wait for the state to change */
|
/* if the lock is currently set, we have to wait for
|
||||||
if (lock->is_set) {
|
* the state to change
|
||||||
if (!waitflag)
|
*/
|
||||||
return 0;
|
if (lock->is_set) {
|
||||||
DosWaitEventSem(lock->changed, SEM_INDEFINITE_WAIT);
|
if (!waitflag)
|
||||||
}
|
return 0;
|
||||||
|
DosWaitEventSem(lock->changed, SEM_INDEFINITE_WAIT);
|
||||||
/*
|
}
|
||||||
* enter a critical section and try to get the semaphore. If
|
|
||||||
* it is still locked, we will try again.
|
|
||||||
*/
|
|
||||||
if (DosEnterCritSec())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!lock->is_set) {
|
/* enter a critical section and try to get the semaphore. If
|
||||||
lock->is_set = 1;
|
* it is still locked, we will try again.
|
||||||
DosResetEventSem(lock->changed, &count);
|
*/
|
||||||
done = 1;
|
if (DosEnterCritSec())
|
||||||
}
|
return 0;
|
||||||
|
|
||||||
DosExitCritSec();
|
if (!lock->is_set) {
|
||||||
}
|
lock->is_set = 1;
|
||||||
|
DosResetEventSem(lock->changed, &count);
|
||||||
|
done = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DosExitCritSec();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PyThread_release_lock(PyThread_type_lock aLock)
|
void PyThread_release_lock(PyThread_type_lock aLock)
|
||||||
{
|
{
|
||||||
#if !defined(PYCC_GCC)
|
#if !defined(PYCC_GCC)
|
||||||
type_os2_lock lock = (type_os2_lock)aLock;
|
type_os2_lock lock = (type_os2_lock)aLock;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock));
|
dprintf(("%ld: PyThread_release_lock(%p) called\n",
|
||||||
|
PyThread_get_thread_ident(),
|
||||||
|
aLock));
|
||||||
|
|
||||||
#if defined(PYCC_GCC)
|
#if defined(PYCC_GCC)
|
||||||
if (aLock)
|
if (aLock)
|
||||||
_fmutex_release((_fmutex *)aLock);
|
_fmutex_release((_fmutex *)aLock);
|
||||||
#else
|
#else
|
||||||
if (!lock->is_set) {
|
if (!lock->is_set) {
|
||||||
dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n",
|
dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n",
|
||||||
PyThread_get_thread_ident(), aLock, GetLastError()));
|
PyThread_get_thread_ident(),
|
||||||
return;
|
aLock,
|
||||||
}
|
GetLastError()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DosEnterCritSec()) {
|
||||||
|
dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n",
|
||||||
|
PyThread_get_thread_ident(),
|
||||||
|
aLock,
|
||||||
|
GetLastError()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (DosEnterCritSec()) {
|
lock->is_set = 0;
|
||||||
dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n",
|
DosPostEventSem(lock->changed);
|
||||||
PyThread_get_thread_ident(), aLock, GetLastError()));
|
|
||||||
return;
|
DosExitCritSec();
|
||||||
}
|
|
||||||
|
|
||||||
lock->is_set = 0;
|
|
||||||
DosPostEventSem(lock->changed);
|
|
||||||
|
|
||||||
DosExitCritSec();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue