diff options
-rw-r--r-- | mac/tclMacThrd.c | 27 | ||||
-rw-r--r-- | unix/tclUnixThrd.c | 49 | ||||
-rw-r--r-- | win/tclWinThrd.c | 49 |
3 files changed, 75 insertions, 50 deletions
diff --git a/mac/tclMacThrd.c b/mac/tclMacThrd.c index 7790e5f..75f5e35 100644 --- a/mac/tclMacThrd.c +++ b/mac/tclMacThrd.c @@ -308,6 +308,33 @@ TclpMasterUnlock() #endif } + +/* + *---------------------------------------------------------------------- + * + * Tcl_GetAllocMutex + * + * This procedure returns a pointer to a statically initialized + * mutex for use by the memory allocator. The alloctor must + * use this lock, because all other locks are allocated... + * + * Results: + * A pointer to a mutex that is suitable for passing to + * Tcl_MutexLock and Tcl_MutexUnlock. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +Tcl_Mutex * +Tcl_GetAllocMutex() +{ + /* There is nothing to do on the Mac */ + return NULL; +} + #ifdef TCL_THREADS /* diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c index ac0804e..a9127a7 100644 --- a/unix/tclUnixThrd.c +++ b/unix/tclUnixThrd.c @@ -36,6 +36,13 @@ static pthread_mutex_t masterLock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t initLock = PTHREAD_MUTEX_INITIALIZER; /* + * allocLock is used by Tcl's version of malloc for synchronization. + * For obvious reasons, cannot use any dyamically allocated storage. + */ + +static pthread_mutex_t allocLock = PTHREAD_MUTEX_INITIALIZER; + +/* * These are for the critical sections inside this file. */ @@ -248,45 +255,37 @@ TclpMasterUnlock() #endif } -#ifdef TCL_THREADS /* *---------------------------------------------------------------------- * - * TclpMutexInit -- - * TclpMutexLock -- - * TclpMutexUnlock -- + * Tcl_GetAllocMutex + * + * This procedure returns a pointer to a statically initialized + * mutex for use by the memory allocator. The alloctor must + * use this lock, because all other locks are allocated... * - * These procedures use an explicitly initialized mutex. - * These are used by memory allocators for their own mutex. - * * Results: - * None. + * A pointer to a mutex that is suitable for passing to + * Tcl_MutexLock and Tcl_MutexUnlock. * * Side effects: - * Initialize, Lock, and Unlock the mutex. + * None. * *---------------------------------------------------------------------- */ -void -TclpMutexInit(mPtr) - TclpMutex *mPtr; +Tcl_Mutex * +Tcl_GetAllocMutex() { - pthread_mutex_init((pthread_mutex_t *)mPtr, NULL); -} -void -TclpMutexLock(mPtr) - TclpMutex *mPtr; -{ - pthread_mutex_lock((pthread_mutex_t *)mPtr); -} -void -TclpMutexUnlock(mPtr) - TclpMutex *mPtr; -{ - pthread_mutex_unlock((pthread_mutex_t *)mPtr); +#ifdef TCL_THREADS + return (Tcl_Mutex *)&allocLock; +#else + return NULL; +#endif } + +#ifdef TCL_THREADS /* *---------------------------------------------------------------------- diff --git a/win/tclWinThrd.c b/win/tclWinThrd.c index ade458e..eaf0dc9 100644 --- a/win/tclWinThrd.c +++ b/win/tclWinThrd.c @@ -37,6 +37,13 @@ static int init = 0; static CRITICAL_SECTION initLock; /* + * allocLock is used by Tcl's version of malloc for synchronization. + * For obvious reasons, cannot use any dyamically allocated storage. + */ + +static CRITICAL_SECTION allocLock; + +/* * Condition variables are implemented with a combination of a * per-thread Windows Event and a per-condition waiting queue. * The idea is that each thread has its own Event that it waits @@ -202,6 +209,7 @@ TclpInitLock() init = 1; InitializeCriticalSection(&initLock); InitializeCriticalSection(&masterLock); + InitializeCriticalSection(&allocLock); } EnterCriticalSection(&initLock); } @@ -264,6 +272,7 @@ TclpMasterLock() init = 1; InitializeCriticalSection(&initLock); InitializeCriticalSection(&masterLock); + InitializeCriticalSection(&allocLock); } EnterCriticalSection(&masterLock); } @@ -292,44 +301,34 @@ TclpMasterUnlock() LeaveCriticalSection(&masterLock); } -#ifdef TCL_THREADS /* *---------------------------------------------------------------------- * - * TclpMutexInit -- - * TclpMutexLock -- - * TclpMutexUnlock -- + * Tcl_GetAllocMutex + * + * This procedure returns a pointer to a statically initialized + * mutex for use by the memory allocator. The alloctor must + * use this lock, because all other locks are allocated... * - * These procedures use an explicitly initialized mutex. - * These are used by memory allocators for their own mutex. - * * Results: - * None. + * A pointer to a mutex that is suitable for passing to + * Tcl_MutexLock and Tcl_MutexUnlock. * * Side effects: - * Initialize, Lock, and Unlock the mutex. + * None. * *---------------------------------------------------------------------- */ -void -TclpMutexInit(mPtr) - TclpMutex *mPtr; -{ - InitializeCriticalSection((CRITICAL_SECTION *)mPtr); -} -void -TclpMutexLock(mPtr) - TclpMutex *mPtr; +Tcl_Mutex * +Tcl_GetAllocMutex() { - EnterCriticalSection((CRITICAL_SECTION *)mPtr); -} -void -TclpMutexUnlock(mPtr) - TclpMutex *mPtr; -{ - LeaveCriticalSection((CRITICAL_SECTION *)mPtr); +#ifdef TCL_THREADS + return &allocLock; +#else + return NULL; +#endif } |