diff options
author | H.Merijn Brand <h.m.brand@xs4all.nl> | 2002-10-19 14:10:21 +0000 |
---|---|---|
committer | H.Merijn Brand <h.m.brand@xs4all.nl> | 2002-10-19 14:10:21 +0000 |
commit | 3db8f154c4c6e098a5a0bdf7932e8f86fbd2c451 (patch) | |
tree | 304393fdb48236335e35a83047fba6223e13f602 /os2 | |
parent | efc41c8ef9279ab1e5f723c2c73a85333a96e0e2 (diff) | |
download | perl-3db8f154c4c6e098a5a0bdf7932e8f86fbd2c451.tar.gz |
Happy chainsaw stories; The removal of the 5005 threads
Still imcomplete. Configure will follow
p4raw-id: //depot/perl@18030
Diffstat (limited to 'os2')
-rw-r--r-- | os2/os2.c | 158 | ||||
-rw-r--r-- | os2/os2ish.h | 107 |
2 files changed, 0 insertions, 265 deletions
@@ -29,161 +29,6 @@ #include "EXTERN.h" #include "perl.h" -#ifdef USE_5005THREADS - -typedef void (*emx_startroutine)(void *); -typedef void* (*pthreads_startroutine)(void *); - -enum pthreads_state { - pthreads_st_none = 0, - pthreads_st_run, - pthreads_st_exited, - pthreads_st_detached, - pthreads_st_waited, -}; -const char *pthreads_states[] = { - "uninit", - "running", - "exited", - "detached", - "waited for", -}; - -typedef struct { - void *status; - perl_cond cond; - enum pthreads_state state; -} thread_join_t; - -thread_join_t *thread_join_data; -int thread_join_count; -perl_mutex start_thread_mutex; - -int -pthread_join(perl_os_thread tid, void **status) -{ - MUTEX_LOCK(&start_thread_mutex); - switch (thread_join_data[tid].state) { - case pthreads_st_exited: - thread_join_data[tid].state = pthreads_st_none; /* Ready to reuse */ - MUTEX_UNLOCK(&start_thread_mutex); - *status = thread_join_data[tid].status; - break; - case pthreads_st_waited: - MUTEX_UNLOCK(&start_thread_mutex); - Perl_croak_nocontext("join with a thread with a waiter"); - break; - case pthreads_st_run: - thread_join_data[tid].state = pthreads_st_waited; - COND_INIT(&thread_join_data[tid].cond); - MUTEX_UNLOCK(&start_thread_mutex); - COND_WAIT(&thread_join_data[tid].cond, NULL); - COND_DESTROY(&thread_join_data[tid].cond); - thread_join_data[tid].state = pthreads_st_none; /* Ready to reuse */ - *status = thread_join_data[tid].status; - break; - default: - MUTEX_UNLOCK(&start_thread_mutex); - Perl_croak_nocontext("join: unknown thread state: '%s'", - pthreads_states[thread_join_data[tid].state]); - break; - } - return 0; -} - -void -pthread_startit(void *arg) -{ - /* Thread is already started, we need to transfer control only */ - pthreads_startroutine start_routine = *((pthreads_startroutine*)arg); - int tid = pthread_self(); - void *retval; - - arg = ((void**)arg)[1]; - if (tid >= thread_join_count) { - int oc = thread_join_count; - - thread_join_count = tid + 5 + tid/5; - if (thread_join_data) { - Renew(thread_join_data, thread_join_count, thread_join_t); - Zero(thread_join_data + oc, thread_join_count - oc, thread_join_t); - } else { - Newz(1323, thread_join_data, thread_join_count, thread_join_t); - } - } - if (thread_join_data[tid].state != pthreads_st_none) - Perl_croak_nocontext("attempt to reuse thread id %i", tid); - thread_join_data[tid].state = pthreads_st_run; - /* Now that we copied/updated the guys, we may release the caller... */ - MUTEX_UNLOCK(&start_thread_mutex); - thread_join_data[tid].status = (*start_routine)(arg); - switch (thread_join_data[tid].state) { - case pthreads_st_waited: - COND_SIGNAL(&thread_join_data[tid].cond); - break; - default: - thread_join_data[tid].state = pthreads_st_exited; - break; - } -} - -int -pthread_create(perl_os_thread *tid, const pthread_attr_t *attr, - void *(*start_routine)(void*), void *arg) -{ - void *args[2]; - - args[0] = (void*)start_routine; - args[1] = arg; - - MUTEX_LOCK(&start_thread_mutex); - *tid = _beginthread(pthread_startit, /*stack*/ NULL, - /*stacksize*/ 10*1024*1024, (void*)args); - MUTEX_LOCK(&start_thread_mutex); - MUTEX_UNLOCK(&start_thread_mutex); - return *tid ? 0 : EINVAL; -} - -int -pthread_detach(perl_os_thread tid) -{ - MUTEX_LOCK(&start_thread_mutex); - switch (thread_join_data[tid].state) { - case pthreads_st_waited: - MUTEX_UNLOCK(&start_thread_mutex); - Perl_croak_nocontext("detach on a thread with a waiter"); - break; - case pthreads_st_run: - thread_join_data[tid].state = pthreads_st_detached; - MUTEX_UNLOCK(&start_thread_mutex); - break; - default: - MUTEX_UNLOCK(&start_thread_mutex); - Perl_croak_nocontext("detach: unknown thread state: '%s'", - pthreads_states[thread_join_data[tid].state]); - break; - } - return 0; -} - -/* This is a very bastardized version: */ -int -os2_cond_wait(perl_cond *c, perl_mutex *m) -{ - int rc; - STRLEN n_a; - if ((rc = DosResetEventSem(*c,&n_a)) && (rc != ERROR_ALREADY_RESET)) - Perl_croak_nocontext("panic: COND_WAIT-reset: rc=%i", rc); - if (m) MUTEX_UNLOCK(m); - if (CheckOSError(DosWaitEventSem(*c,SEM_INDEFINITE_WAIT)) - && (rc != ERROR_INTERRUPT)) - Perl_croak_nocontext("panic: COND_WAIT: rc=%i", rc); - if (rc == ERROR_INTERRUPT) - errno = EINTR; - if (m) MUTEX_LOCK(m); -} -#endif - static int exe_is_aout(void); /*****************************************************************************/ @@ -1406,9 +1251,6 @@ mod2fname(pTHX_ SV *sv) } avlen --; } -#ifdef USE_5005THREADS - sum++; /* Avoid conflict of DLLs in memory. */ -#endif /* We always load modules as *specific* DLLs, and with the full name. When loading a specific DLL by its full name, one cannot get a different DLL, even if a DLL with the same basename is loaded already. diff --git a/os2/os2ish.h b/os2/os2ish.h index 1b38b85427..20e413a837 100644 --- a/os2/os2ish.h +++ b/os2/os2ish.h @@ -99,115 +99,8 @@ # undef I_SYS_UN #endif -#ifdef USE_5005THREADS - -#define do_spawn(a) os2_do_spawn(aTHX_ (a)) -#define do_aspawn(a,b,c) os2_do_aspawn(aTHX_ (a),(b),(c)) - -#define OS2_ERROR_ALREADY_POSTED 299 /* Avoid os2.h */ - -extern int rc; - -#define MUTEX_INIT(m) \ - STMT_START { \ - int rc; \ - if ((rc = _rmutex_create(m,0))) \ - Perl_croak_nocontext("panic: MUTEX_INIT: rc=%i", rc); \ - } STMT_END -#define MUTEX_LOCK(m) \ - STMT_START { \ - int rc; \ - if ((rc = _rmutex_request(m,_FMR_IGNINT))) \ - Perl_croak_nocontext("panic: MUTEX_LOCK: rc=%i", rc); \ - } STMT_END -#define MUTEX_UNLOCK(m) \ - STMT_START { \ - int rc; \ - if ((rc = _rmutex_release(m))) \ - Perl_croak_nocontext("panic: MUTEX_UNLOCK: rc=%i", rc); \ - } STMT_END -#define MUTEX_DESTROY(m) \ - STMT_START { \ - int rc; \ - if ((rc = _rmutex_close(m))) \ - Perl_croak_nocontext("panic: MUTEX_DESTROY: rc=%i", rc); \ - } STMT_END - -#define COND_INIT(c) \ - STMT_START { \ - int rc; \ - if ((rc = DosCreateEventSem(NULL,c,0,0))) \ - Perl_croak_nocontext("panic: COND_INIT: rc=%i", rc); \ - } STMT_END -#define COND_SIGNAL(c) \ - STMT_START { \ - int rc; \ - if ((rc = DosPostEventSem(*(c))) && rc != OS2_ERROR_ALREADY_POSTED)\ - Perl_croak_nocontext("panic: COND_SIGNAL, rc=%ld", rc); \ - } STMT_END -#define COND_BROADCAST(c) \ - STMT_START { \ - int rc; \ - if ((rc = DosPostEventSem(*(c))) && rc != OS2_ERROR_ALREADY_POSTED)\ - Perl_croak_nocontext("panic: COND_BROADCAST, rc=%i", rc); \ - } STMT_END -/* #define COND_WAIT(c, m) \ - STMT_START { \ - if (WaitForSingleObject(*(c),INFINITE) == WAIT_FAILED) \ - Perl_croak_nocontext("panic: COND_WAIT"); \ - } STMT_END -*/ -#define COND_WAIT(c, m) os2_cond_wait(c,m) - -#define COND_WAIT_win32(c, m) \ - STMT_START { \ - int rc; \ - if ((rc = SignalObjectAndWait(*(m),*(c),INFINITE,FALSE))) \ - Perl_croak_nocontext("panic: COND_WAIT"); \ - else \ - MUTEX_LOCK(m); \ - } STMT_END -#define COND_DESTROY(c) \ - STMT_START { \ - int rc; \ - if ((rc = DosCloseEventSem(*(c)))) \ - Perl_croak_nocontext("panic: COND_DESTROY, rc=%i", rc); \ - } STMT_END -/*#define THR ((struct thread *) TlsGetValue(PL_thr_key)) -*/ - -#ifdef USE_SLOW_THREAD_SPECIFIC -# define pthread_getspecific(k) (*_threadstore()) -# define pthread_setspecific(k,v) (*_threadstore()=v,0) -# define pthread_key_create(keyp,flag) (*keyp=_gettid(),0) -#else /* USE_SLOW_THREAD_SPECIFIC */ -# define pthread_getspecific(k) (*(k)) -# define pthread_setspecific(k,v) (*(k)=(v),0) -# define pthread_key_create(keyp,flag) \ - ( DosAllocThreadLocalMemory(1,(U32*)keyp) \ - ? Perl_croak_nocontext("LocalMemory"),1 \ - : 0 \ - ) -#endif /* USE_SLOW_THREAD_SPECIFIC */ -#define pthread_key_delete(keyp) -#define pthread_self() _gettid() -#define YIELD DosSleep(0) - -#ifdef PTHREADS_INCLUDED /* For ./x2p stuff. */ -int pthread_join(pthread_t tid, void **status); -int pthread_detach(pthread_t tid); -int pthread_create(pthread_t *tid, const pthread_attr_t *attr, - void *(*start_routine)(void*), void *arg); -#endif /* PTHREAD_INCLUDED */ - -#define THREADS_ELSEWHERE - -#else /* USE_5005THREADS */ - #define do_spawn(a) os2_do_spawn(a) #define do_aspawn(a,b,c) os2_do_aspawn((a),(b),(c)) - -#endif /* USE_5005THREADS */ void Perl_OS2_init(char **); void Perl_OS2_init3(char **envp, void **excH, int flags); |