[Python-Dev] pthreads question: typedef ??? pthread_t and hacky return statements
Mark Hammond
MarkH@ActiveState.com
Fri, 18 Aug 2000 09:59:18 +1000
> IOW, an x-plat TLS is going to be done at some point. If you need it now,
> then please do it now. That will help us immeasurably in the long run.
I just discovered the TLS code in the Mozilla source tree. This could be a
good place to start.
The definitions are in mozilla/nsprpub/pr/include/prthread.h, and I include
some of this file below... I can confirm this code works _with_ Python -
but I have no idea how hard it would be to distill it _into_ Python!
Then-we-just-need-Tim-to-check-the-license-for-us<wink> ly,
Mark.
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
[MarkH - it looks good to me - very open license]
...
/*
** This routine returns a new index for per-thread-private data table.
** The index is visible to all threads within a process. This index can
** be used with the PR_SetThreadPrivate() and PR_GetThreadPrivate()
routines
** to save and retrieve data associated with the index for a thread.
**
** Each index is associationed with a destructor function ('dtor'). The
function
** may be specified as NULL when the index is created. If it is not NULL,
the
** function will be called when:
** - the thread exits and the private data for the associated index
** is not NULL,
** - new thread private data is set and the current private data is
** not NULL.
**
** The index independently maintains specific values for each binding
thread.
** A thread can only get access to its own thread-specific-data.
**
** Upon a new index return the value associated with the index for all
threads
** is NULL, and upon thread creation the value associated with all indices
for
** that thread is NULL.
**
** Returns PR_FAILURE if the total number of indices will exceed the
maximun
** allowed.
*/
typedef void (PR_CALLBACK *PRThreadPrivateDTOR)(void *priv);
NSPR_API(PRStatus) PR_NewThreadPrivateIndex(
PRUintn *newIndex, PRThreadPrivateDTOR destructor);
/*
** Define some per-thread-private data.
** "tpdIndex" is an index into the per-thread private data table
** "priv" is the per-thread-private data
**
** If the per-thread private data table has a previously registered
** destructor function and a non-NULL per-thread-private data value,
** the destructor function is invoked.
**
** This can return PR_FAILURE if the index is invalid.
*/
NSPR_API(PRStatus) PR_SetThreadPrivate(PRUintn tpdIndex, void *priv);
/*
** Recover the per-thread-private data for the current thread. "tpdIndex"
is
** the index into the per-thread private data table.
**
** The returned value may be NULL which is indistinguishable from an error
** condition.
**
** A thread can only get access to its own thread-specific-data.
*/
NSPR_API(void*) PR_GetThreadPrivate(PRUintn tpdIndex);