aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/thread.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2004-04-10 00:53:25 +0000
committerChristopher Faylor <me@cgf.cx>2004-04-10 00:53:25 +0000
commit56a188d1f3c3fb3d38c380f0052c16c5ee046c9b (patch)
treeaf6abfca253634243d80ef0a4e5be86e4c0193ed /winsup/cygwin/thread.cc
parent60210cc795bcea2e34ed668cc5bccff35ba43246 (diff)
downloadnewlib-56a188d1f3c3fb3d38c380f0052c16c5ee046c9b.zip
newlib-56a188d1f3c3fb3d38c380f0052c16c5ee046c9b.tar.gz
newlib-56a188d1f3c3fb3d38c380f0052c16c5ee046c9b.tar.bz2
* thread.h (pthread::init_mainthread): Remove parameter forked.
(pthread::set_tls_self_pointer): New static function. * thread.cc (MTinterface::fixup_after_fork): Change call to pthread::init_mainthread. (pthread::init_mainthread): Remove parameter forked. Simplify thread self pointer handling. (pthread::self): Set thread self pointer to null_pthread if thread has not been initialized. (pthread::set_tls_self_pointer): New static function.
Diffstat (limited to 'winsup/cygwin/thread.cc')
-rw-r--r--winsup/cygwin/thread.cc34
1 files changed, 19 insertions, 15 deletions
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index 3652a91..5607442 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -153,7 +153,7 @@ MTinterface::fixup_after_fork (void)
pthread_key::fixup_after_fork ();
threadcount = 0;
- pthread::init_mainthread (true);
+ pthread::init_mainthread ();
pthread::fixup_after_fork ();
pthread_mutex::fixup_after_fork ();
@@ -166,23 +166,17 @@ MTinterface::fixup_after_fork (void)
/* static methods */
void
-pthread::init_mainthread (const bool forked)
+pthread::init_mainthread ()
{
pthread *thread = get_tls_self_pointer ();
if (!thread)
{
- if (forked)
- thread = pthread_null::get_null_pthread ();
- else
- {
- thread = new pthread ();
- if (!thread)
- api_fatal ("failed to create mainthread object");
- }
+ thread = new pthread ();
+ if (!thread)
+ api_fatal ("failed to create mainthread object");
}
- thread->cygtls = &_my_tls;
- _my_tls.tid = thread;
+ set_tls_self_pointer (thread);
thread->thread_id = GetCurrentThreadId ();
if (!DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
GetCurrentProcess (), &thread->win32_obj_id,
@@ -198,9 +192,12 @@ pthread *
pthread::self ()
{
pthread *thread = get_tls_self_pointer ();
- if (thread)
- return thread;
- return pthread_null::get_null_pthread ();
+ if (!thread)
+ {
+ thread = pthread_null::get_null_pthread ();
+ set_tls_self_pointer (thread);
+ }
+ return thread;
}
pthread *
@@ -209,6 +206,13 @@ pthread::get_tls_self_pointer ()
return _my_tls.tid;
}
+void
+pthread::set_tls_self_pointer (pthread *thread)
+{
+ thread->cygtls = &_my_tls;
+ _my_tls.tid = thread;
+}
+
List<pthread> pthread::threads;
/* member methods */