summaryrefslogtreecommitdiff
path: root/pr/src/md/unix/solaris.c
diff options
context:
space:
mode:
Diffstat (limited to 'pr/src/md/unix/solaris.c')
-rw-r--r--pr/src/md/unix/solaris.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/pr/src/md/unix/solaris.c b/pr/src/md/unix/solaris.c
index 4dd1c06e..0437903a 100644
--- a/pr/src/md/unix/solaris.c
+++ b/pr/src/md/unix/solaris.c
@@ -183,9 +183,28 @@ THREAD_KEY_T cpuid_key;
THREAD_KEY_T last_thread_key;
static sigset_t set, oldset;
+static void
+threadid_key_destructor(void *value)
+{
+ PRThread *me = (PRThread *)value;
+ PR_ASSERT(me != NULL);
+ /* the thread could be PRIMORDIAL (thus not ATTACHED) */
+ if (me->flags & _PR_ATTACHED) {
+ /*
+ * The Solaris thread library sets the thread specific
+ * data (the current thread) to NULL before invoking
+ * the destructor. We need to restore it to prevent the
+ * _PR_MD_CURRENT_THREAD() call in _PRI_DetachThread()
+ * from attaching the thread again.
+ */
+ _PR_MD_SET_CURRENT_THREAD(me);
+ _PRI_DetachThread();
+ }
+}
+
void _MD_EarlyInit(void)
{
- THR_KEYCREATE(&threadid_key, NULL);
+ THR_KEYCREATE(&threadid_key, threadid_key_destructor);
THR_KEYCREATE(&cpuid_key, NULL);
THR_KEYCREATE(&last_thread_key, NULL);
sigemptyset(&set);
@@ -337,7 +356,7 @@ void _MD_lock(struct _MDLock *md_lock)
mutex_lock(&md_lock->lock);
}
-PRThread *_pr_current_thread_tls()
+PRThread *_pr_attached_thread_tls()
{
PRThread *ret;
@@ -345,6 +364,21 @@ PRThread *_pr_current_thread_tls()
return ret;
}
+PRThread *_pr_current_thread_tls()
+{
+ PRThread *thread;
+
+ thread = _MD_GET_ATTACHED_THREAD();
+
+ if (NULL == thread) {
+ thread = _PRI_AttachThread(
+ PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL, 0);
+ }
+ PR_ASSERT(thread != NULL);
+
+ return thread;
+}
+
PRStatus
_MD_wait(PRThread *thread, PRIntervalTime ticks)
{