summaryrefslogtreecommitdiffstats
path: root/unix/tclUnixThrd.c
diff options
context:
space:
mode:
authorhobbs <hobbs@noemail.net>2002-04-23 05:41:03 (GMT)
committerhobbs <hobbs@noemail.net>2002-04-23 05:41:03 (GMT)
commit4ff45cfd27ef01e54be5fe50caed6e33054a0e76 (patch)
tree8e915d33b9e1c08eeb19f3ffde5853fc2fc6a31d /unix/tclUnixThrd.c
parent36dcb229a5f12fbbe9075ada8620c223c9bea487 (diff)
downloadtcl-4ff45cfd27ef01e54be5fe50caed6e33054a0e76.zip
tcl-4ff45cfd27ef01e54be5fe50caed6e33054a0e76.tar.gz
tcl-4ff45cfd27ef01e54be5fe50caed6e33054a0e76.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). FossilOrigin-Name: 329bb4c2950b83d7f84e74e956bc925bbfd25684
Diffstat (limited to 'unix/tclUnixThrd.c')
-rw-r--r--unix/tclUnixThrd.c50
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 */