From: Gurusamy Sarathy Date: Sat, 11 Mar 2000 16:50:05 +0000 (+0000) Subject: avoid using context pointer in MUTEX_INIT() et al; remove the X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=efc57feb990d7c1543c73387ff9802db712d8581;p=p5sagit%2Fp5-mst-13.2.git avoid using context pointer in MUTEX_INIT() et al; remove the *_NOCONTEXT variants to keep it simple p4raw-id: //depot/perl@5651 --- diff --git a/malloc.c b/malloc.c index f76a210..57ca5a1 100644 --- a/malloc.c +++ b/malloc.c @@ -150,8 +150,8 @@ warn(format, arg) fprintf(stderr, idem) # Locking/unlocking for MT operation - MALLOC_LOCK MUTEX_LOCK_NOCONTEXT(&PL_malloc_mutex) - MALLOC_UNLOCK MUTEX_UNLOCK_NOCONTEXT(&PL_malloc_mutex) + MALLOC_LOCK MUTEX_LOCK(&PL_malloc_mutex) + MALLOC_UNLOCK MUTEX_UNLOCK(&PL_malloc_mutex) # Locking/unlocking mutex for MT operation MUTEX_LOCK(l) void @@ -319,11 +319,11 @@ #endif #ifndef MALLOC_LOCK -# define MALLOC_LOCK MUTEX_LOCK_NOCONTEXT(&PL_malloc_mutex) +# define MALLOC_LOCK MUTEX_LOCK(&PL_malloc_mutex) #endif #ifndef MALLOC_UNLOCK -# define MALLOC_UNLOCK MUTEX_UNLOCK_NOCONTEXT(&PL_malloc_mutex) +# define MALLOC_UNLOCK MUTEX_UNLOCK(&PL_malloc_mutex) #endif # ifndef fatalcroak /* make depend */ diff --git a/thread.h b/thread.h index 72292b5..0ea9e74 100644 --- a/thread.h +++ b/thread.h @@ -8,7 +8,7 @@ STMT_START { \ if (pthread_detach(&(t)->self)) { \ MUTEX_UNLOCK(&(t)->mutex); \ - Perl_croak(aTHX_ "panic: DETACH"); \ + Perl_croak_nocontext("panic: DETACH"); \ } \ } STMT_END @@ -70,14 +70,12 @@ if (*m) { \ mutex_init(*m); \ } else { \ - Perl_croak(aTHX_ "panic: MUTEX_INIT"); \ + Perl_croak_nocontext("panic: MUTEX_INIT"); \ } \ } STMT_END #define MUTEX_LOCK(m) mutex_lock(*m) -#define MUTEX_LOCK_NOCONTEXT(m) mutex_lock(*m) #define MUTEX_UNLOCK(m) mutex_unlock(*m) -#define MUTEX_UNLOCK_NOCONTEXT(m) mutex_unlock(*m) #define MUTEX_DESTROY(m) \ STMT_START { \ mutex_free(*m); \ @@ -91,7 +89,7 @@ condition_init(*c); \ } \ else { \ - Perl_croak(aTHX_ "panic: COND_INIT"); \ + Perl_croak_nocontext("panic: COND_INIT"); \ } \ } STMT_END @@ -151,35 +149,23 @@ STMT_START { \ Zero((m), 1, perl_mutex); \ if (pthread_mutex_init((m), pthread_mutexattr_default)) \ - Perl_croak(aTHX_ "panic: MUTEX_INIT"); \ + Perl_croak_nocontext("panic: MUTEX_INIT"); \ } STMT_END # else # define MUTEX_INIT(m) \ STMT_START { \ if (pthread_mutex_init((m), pthread_mutexattr_default)) \ - Perl_croak(aTHX_ "panic: MUTEX_INIT"); \ + Perl_croak_nocontext("panic: MUTEX_INIT"); \ } STMT_END # endif # define MUTEX_LOCK(m) \ STMT_START { \ if (pthread_mutex_lock((m))) \ - Perl_croak(aTHX_ "panic: MUTEX_LOCK"); \ - } STMT_END - -# define MUTEX_UNLOCK(m) \ - STMT_START { \ - if (pthread_mutex_unlock((m))) \ - Perl_croak(aTHX_ "panic: MUTEX_UNLOCK"); \ - } STMT_END - -# define MUTEX_LOCK_NOCONTEXT(m) \ - STMT_START { \ - if (pthread_mutex_lock((m))) \ Perl_croak_nocontext("panic: MUTEX_LOCK"); \ } STMT_END -# define MUTEX_UNLOCK_NOCONTEXT(m) \ +# define MUTEX_UNLOCK(m) \ STMT_START { \ if (pthread_mutex_unlock((m))) \ Perl_croak_nocontext("panic: MUTEX_UNLOCK"); \ @@ -188,7 +174,7 @@ # define MUTEX_DESTROY(m) \ STMT_START { \ if (pthread_mutex_destroy((m))) \ - Perl_croak(aTHX_ "panic: MUTEX_DESTROY"); \ + Perl_croak_nocontext("panic: MUTEX_DESTROY"); \ } STMT_END #endif /* MUTEX_INIT */ @@ -196,31 +182,31 @@ # define COND_INIT(c) \ STMT_START { \ if (pthread_cond_init((c), pthread_condattr_default)) \ - Perl_croak(aTHX_ "panic: COND_INIT"); \ + Perl_croak_nocontext("panic: COND_INIT"); \ } STMT_END # define COND_SIGNAL(c) \ STMT_START { \ if (pthread_cond_signal((c))) \ - Perl_croak(aTHX_ "panic: COND_SIGNAL"); \ + Perl_croak_nocontext("panic: COND_SIGNAL"); \ } STMT_END # define COND_BROADCAST(c) \ STMT_START { \ if (pthread_cond_broadcast((c))) \ - Perl_croak(aTHX_ "panic: COND_BROADCAST"); \ + Perl_croak_nocontext("panic: COND_BROADCAST"); \ } STMT_END # define COND_WAIT(c, m) \ STMT_START { \ if (pthread_cond_wait((c), (m))) \ - Perl_croak(aTHX_ "panic: COND_WAIT"); \ + Perl_croak_nocontext("panic: COND_WAIT"); \ } STMT_END # define COND_DESTROY(c) \ STMT_START { \ if (pthread_cond_destroy((c))) \ - Perl_croak(aTHX_ "panic: COND_DESTROY"); \ + Perl_croak_nocontext("panic: COND_DESTROY"); \ } STMT_END #endif /* COND_INIT */ @@ -230,7 +216,7 @@ STMT_START { \ if (pthread_detach((t)->self)) { \ MUTEX_UNLOCK(&(t)->mutex); \ - Perl_croak(aTHX_ "panic: DETACH"); \ + Perl_croak_nocontext("panic: DETACH"); \ } \ } STMT_END #endif /* DETACH */ @@ -239,7 +225,7 @@ # define JOIN(t, avp) \ STMT_START { \ if (pthread_join((t)->self, (void**)(avp))) \ - Perl_croak(aTHX_ "panic: pthread_join"); \ + Perl_croak_nocontext("panic: pthread_join"); \ } STMT_END #endif /* JOIN */ @@ -251,7 +237,7 @@ # define PERL_SET_CONTEXT(t) \ STMT_START { \ if (pthread_setspecific(PL_thr_key, (void *)(t))) \ - Perl_croak(aTHX_ "panic: pthread_setspecific"); \ + Perl_croak_nocontext("panic: pthread_setspecific"); \ } STMT_END #endif /* PERL_SET_CONTEXT */ @@ -334,18 +320,10 @@ typedef struct condpair { # define MUTEX_LOCK(m) #endif -#ifndef MUTEX_LOCK_NOCONTEXT -# define MUTEX_LOCK_NOCONTEXT(m) -#endif - #ifndef MUTEX_UNLOCK # define MUTEX_UNLOCK(m) #endif -#ifndef MUTEX_UNLOCK_NOCONTEXT -# define MUTEX_UNLOCK_NOCONTEXT(m) -#endif - #ifndef MUTEX_INIT # define MUTEX_INIT(m) #endif diff --git a/win32/win32thread.h b/win32/win32thread.h index 46c6bf5..809e0f7 100644 --- a/win32/win32thread.h +++ b/win32/win32thread.h @@ -17,8 +17,6 @@ typedef CRITICAL_SECTION perl_mutex; #define MUTEX_INIT(m) InitializeCriticalSection(m) #define MUTEX_LOCK(m) EnterCriticalSection(m) #define MUTEX_UNLOCK(m) LeaveCriticalSection(m) -#define MUTEX_LOCK_NOCONTEXT(m) EnterCriticalSection(m) -#define MUTEX_UNLOCK_NOCONTEXT(m) LeaveCriticalSection(m) #define MUTEX_DESTROY(m) DeleteCriticalSection(m) #else @@ -27,28 +25,16 @@ typedef HANDLE perl_mutex; # define MUTEX_INIT(m) \ STMT_START { \ if ((*(m) = CreateMutex(NULL,FALSE,NULL)) == NULL) \ - Perl_croak(aTHX_ "panic: MUTEX_INIT"); \ + Perl_croak_nocontext("panic: MUTEX_INIT"); \ } STMT_END # define MUTEX_LOCK(m) \ STMT_START { \ if (WaitForSingleObject(*(m),INFINITE) == WAIT_FAILED) \ - Perl_croak(aTHX_ "panic: MUTEX_LOCK"); \ - } STMT_END - -# define MUTEX_UNLOCK(m) \ - STMT_START { \ - if (ReleaseMutex(*(m)) == 0) \ - Perl_croak(aTHX_ "panic: MUTEX_UNLOCK"); \ - } STMT_END - -# define MUTEX_LOCK_NOCONTEXT(m) \ - STMT_START { \ - if (WaitForSingleObject(*(m),INFINITE) == WAIT_FAILED) \ Perl_croak_nocontext("panic: MUTEX_LOCK"); \ } STMT_END -# define MUTEX_UNLOCK_NOCONTEXT(m) \ +# define MUTEX_UNLOCK(m) \ STMT_START { \ if (ReleaseMutex(*(m)) == 0) \ Perl_croak_nocontext("panic: MUTEX_UNLOCK"); \ @@ -57,7 +43,7 @@ typedef HANDLE perl_mutex; # define MUTEX_DESTROY(m) \ STMT_START { \ if (CloseHandle(*(m)) == 0) \ - Perl_croak(aTHX_ "panic: MUTEX_DESTROY"); \ + Perl_croak_nocontext("panic: MUTEX_DESTROY"); \ } STMT_END #endif @@ -71,21 +57,21 @@ typedef HANDLE perl_mutex; (c)->waiters = 0; \ (c)->sem = CreateSemaphore(NULL,0,LONG_MAX,NULL); \ if ((c)->sem == NULL) \ - Perl_croak(aTHX_ "panic: COND_INIT (%ld)",GetLastError()); \ + Perl_croak_nocontext("panic: COND_INIT (%ld)",GetLastError()); \ } STMT_END #define COND_SIGNAL(c) \ STMT_START { \ if ((c)->waiters > 0 && \ ReleaseSemaphore((c)->sem,1,NULL) == 0) \ - Perl_croak(aTHX_ "panic: COND_SIGNAL (%ld)",GetLastError()); \ + Perl_croak_nocontext("panic: COND_SIGNAL (%ld)",GetLastError()); \ } STMT_END #define COND_BROADCAST(c) \ STMT_START { \ if ((c)->waiters > 0 && \ ReleaseSemaphore((c)->sem,(c)->waiters,NULL) == 0) \ - Perl_croak(aTHX_ "panic: COND_BROADCAST (%ld)",GetLastError());\ + Perl_croak_nocontext("panic: COND_BROADCAST (%ld)",GetLastError());\ } STMT_END #define COND_WAIT(c, m) \ @@ -96,7 +82,7 @@ typedef HANDLE perl_mutex; * COND_BROADCAST() on another thread will have seen the\ * right number of waiters (i.e. including this one) */ \ if (WaitForSingleObject((c)->sem,INFINITE)==WAIT_FAILED)\ - Perl_croak(aTHX_ "panic: COND_WAIT (%ld)",GetLastError()); \ + Perl_croak_nocontext("panic: COND_WAIT (%ld)",GetLastError()); \ /* XXX there may be an inconsequential race here */ \ MUTEX_LOCK(m); \ (c)->waiters--; \ @@ -106,14 +92,14 @@ typedef HANDLE perl_mutex; STMT_START { \ (c)->waiters = 0; \ if (CloseHandle((c)->sem) == 0) \ - Perl_croak(aTHX_ "panic: COND_DESTROY (%ld)",GetLastError()); \ + Perl_croak_nocontext("panic: COND_DESTROY (%ld)",GetLastError()); \ } STMT_END #define DETACH(t) \ STMT_START { \ if (CloseHandle((t)->self) == 0) { \ MUTEX_UNLOCK(&(t)->mutex); \ - Perl_croak(aTHX_ "panic: DETACH"); \ + Perl_croak_nocontext("panic: DETACH"); \ } \ } STMT_END @@ -195,7 +181,7 @@ END_EXTERN_C if ((WaitForSingleObject((t)->self,INFINITE) == WAIT_FAILED) \ || (GetExitCodeThread((t)->self,(LPDWORD)(avp)) == 0) \ || (CloseHandle((t)->self) == 0)) \ - Perl_croak(aTHX_ "panic: JOIN"); \ + Perl_croak_nocontext("panic: JOIN"); \ *avp = (AV *)((t)->i.retv); \ } STMT_END #else /* !USE_RTL_THREAD_API || _MSC_VER */ @@ -204,7 +190,7 @@ END_EXTERN_C if ((WaitForSingleObject((t)->self,INFINITE) == WAIT_FAILED) \ || (GetExitCodeThread((t)->self,(LPDWORD)(avp)) == 0) \ || (CloseHandle((t)->self) == 0)) \ - Perl_croak(aTHX_ "panic: JOIN"); \ + Perl_croak_nocontext("panic: JOIN"); \ } STMT_END #endif /* !USE_RTL_THREAD_API || _MSC_VER */