diff options
author | hobbs <hobbs> | 2002-04-23 05:41:03 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2002-04-23 05:41:03 (GMT) |
commit | c8606fb44370611225383e0f4cbe59c18edbc31b (patch) | |
tree | 8e915d33b9e1c08eeb19f3ffde5853fc2fc6a31d /unix/tclUnixThrd.c | |
parent | 8142c17a36e5e8959ca0577e6ac377269c6eea7e (diff) | |
download | tcl-c8606fb44370611225383e0f4cbe59c18edbc31b.zip tcl-c8606fb44370611225383e0f4cbe59c18edbc31b.tar.gz tcl-c8606fb44370611225383e0f4cbe59c18edbc31b.tar.bz2 |
* generic/tclAlloc.c:
* generic/tclInt.h:
* generic/tclThreadAlloc.c (new):
* unix/Makefile.in:
* unix/tclUnixThrd.c:
* win/Makefile.in:
* win/tclWinInt.h:
* win/tclWinThrd.c: added new threaded allocator contributed by
AOL that significantly reduces lock contention when multiple
threads are in use. Only Windows and Unix implementations are
ready, and the Windows one may need work. It is only used by
default on Unix for now, and requires that USE_THREAD_ALLOC be
defined (--enable-threads on Unix will define this).
Diffstat (limited to 'unix/tclUnixThrd.c')
-rw-r--r-- | unix/tclUnixThrd.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c index 82b4d24..4084cbe 100644 --- a/unix/tclUnixThrd.c +++ b/unix/tclUnixThrd.c @@ -833,4 +833,54 @@ TclpInetNtoa(struct in_addr addr) return tsdPtr->nabuf; } +/* + * Additions by AOL for specialized thread memory allocator. + */ +#ifdef USE_THREAD_ALLOC +static int initialized = 0; +static pthread_key_t key; +static pthread_once_t once = PTHREAD_ONCE_INIT; + +Tcl_Mutex * +TclpNewAllocMutex(void) +{ + struct lock { + Tcl_Mutex tlock; + pthread_mutex_t plock; + } *lockPtr; + + lockPtr = malloc(sizeof(struct lock)); + if (lockPtr == NULL) { + panic("could not allocate lock"); + } + lockPtr->tlock = (Tcl_Mutex) &lockPtr->plock; + pthread_mutex_init(&lockPtr->plock, NULL); + return &lockPtr->tlock; +} + +static void +InitKey(void) +{ + extern void TclFreeAllocCache(void *); + + pthread_key_create(&key, TclFreeAllocCache); + initialized = 1; +} + +void * +TclpGetAllocCache(void) +{ + if (!initialized) { + pthread_once(&once, InitKey); + } + return pthread_getspecific(key); +} + +void +TclpSetAllocCache(void *arg) +{ + pthread_setspecific(key, arg); +} + +#endif /* USE_THREAD_ALLOC */ #endif /* TCL_THREADS */ |