summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/cygtls.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2012-08-09 19:58:53 +0000
committerChristopher Faylor <me@cgf.cx>2012-08-09 19:58:53 +0000
commit52d2371da52be037af8020220650645df497d90d (patch)
tree981b4d875ae69b48fc6dfd2451f72c82002f14cd /winsup/cygwin/cygtls.cc
parentcc02df128665f400e911e1f67e9963e827962914 (diff)
downloadcygnal-52d2371da52be037af8020220650645df497d90d.tar.gz
cygnal-52d2371da52be037af8020220650645df497d90d.tar.bz2
cygnal-52d2371da52be037af8020220650645df497d90d.zip
* DevNotes: Add entry cgf-000014.
* cygheap.cc (tls_sentry): Move here, rename from 'sentry' in cygtls.cc (tls_sentry::lock): Ditto. (nthreads): Move from cygtls.cc (THREADLIST_CHUNK): Ditto. (cygheap_init): Call init_tls_list(). (init_cygheap::init_tls_list): Define new function. (init_cygheap::add_tls): Ditto. (init_cygheap::remove_tls): Ditto. (init_cygheap::find_tls): Ditto. Semi-resurrect from _cygtls::find_tls. * cygheap.h (init_cygheap::init_tls_list): Declare new function. (init_cygheap::add_tls): Ditto. (init_cygheap::remove_tls): Ditto. (init_cygheap::find_tls): Ditto. * cygtls.cc (sentry): Delete. (sentry::lock): Ditto. (nthreads): Ditto. (THREADLIST_CHUNK): Ditto. (_cygtls::init): Delete definition. (_cygtls::init_thread): Call cygheap->add_tls() to add thread to global list. (_cygtls::remove): cygheap->remove_tls() to remove thread from global list. * cygtls.h (_cygtls::init): Delete declaration. * dcrt0.cc (dll_crt0_0): Delete call to _cygtls::init(). * exceptions.cc (sigpacket::process): When no thread is specified, try to find one via cygheap->find_tls.
Diffstat (limited to 'winsup/cygwin/cygtls.cc')
-rw-r--r--winsup/cygwin/cygtls.cc63
1 files changed, 2 insertions, 61 deletions
diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc
index da48622f1..abda77c5f 100644
--- a/winsup/cygwin/cygtls.cc
+++ b/winsup/cygwin/cygtls.cc
@@ -19,39 +19,6 @@ details. */
#include "sigproc.h"
#include "exception.h"
-class sentry
-{
- static muto lock;
- int destroy;
-public:
- void init ();
- bool acquired () {return lock.acquired ();}
- sentry () {destroy = 0;}
- sentry (DWORD wait) {destroy = lock.acquire (wait);}
- ~sentry () {if (destroy) lock.release ();}
- friend void _cygtls::init ();
-};
-
-muto NO_COPY sentry::lock;
-
-static size_t NO_COPY nthreads;
-
-#define THREADLIST_CHUNK 256
-
-void
-_cygtls::init ()
-{
- if (cygheap->threadlist)
- memset (cygheap->threadlist, 0, cygheap->sthreads * sizeof (cygheap->threadlist[0]));
- else
- {
- cygheap->sthreads = THREADLIST_CHUNK;
- cygheap->threadlist = (_cygtls **) ccalloc_abort (HEAP_TLS, cygheap->sthreads,
- sizeof (cygheap->threadlist[0]));
- }
- sentry::lock.init ("sentry_lock");
-}
-
/* Two calls to get the stack right... */
void
_cygtls::call (DWORD (*func) (void *, void *), void *arg)
@@ -167,18 +134,7 @@ _cygtls::init_thread (void *x, DWORD (*func) (void *, void *))
|| (void *) func == (void *) cygthread::simplestub)
return;
- cygheap->user.reimpersonate ();
-
- sentry here (INFINITE);
- if (nthreads >= cygheap->sthreads)
- {
- cygheap->threadlist = (_cygtls **)
- crealloc_abort (cygheap->threadlist, (cygheap->sthreads += THREADLIST_CHUNK)
- * sizeof (cygheap->threadlist[0]));
- memset (cygheap->threadlist + nthreads, 0, THREADLIST_CHUNK * sizeof (cygheap->threadlist[0]));
- }
-
- cygheap->threadlist[nthreads++] = this;
+ cygheap->add_tls (this);
}
void
@@ -237,22 +193,7 @@ _cygtls::remove (DWORD wait)
free_local (hostent_buf);
/* Free temporary TLS path buffers. */
locals.pathbufs.destroy ();
-
- do
- {
- sentry here (wait);
- if (here.acquired ())
- {
- for (size_t i = 0; i < nthreads; i++)
- if (this == cygheap->threadlist[i])
- {
- if (i < --nthreads)
- cygheap->threadlist[i] = cygheap->threadlist[nthreads];
- debug_printf ("removed %p element %d", this, i);
- break;
- }
- }
- } while (0);
+ cygheap->remove_tls (this, wait);
remove_wq (wait);
}