Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2004-05-16 08:18:50 +0400
committerChristopher Faylor <me@cgf.cx>2004-05-16 08:18:50 +0400
commit0c565ab35b47c29c0d5ba7a6e28ca63535776ce8 (patch)
tree3c5c40d2bb4eb150ee58f043bbec30d1032c2a74 /winsup/cygwin/sync.cc
parentaafd8a545f7d9089d47ac28d890840f22dac6df4 (diff)
* cygthread.cc (cygthread::is): Eliminate.
* cygthread.h (cygthread::is): Eliminate declaratin. * fhandler_console.cc (fhandler_console::read): Only wait for signal_arrived in the main thread. * fhandler_socket.cc: Include new "wininfo.h". (fhandler_socket::ioctl): Use 'winmsg' rather than 'gethwnd()'. * sync.cc (muto::grab): Define new function. (muto::acquire): Use tls pointer rather than tid. (muto::acquired): Ditto. (muto::reset): Delete. (muto::release): Ditto. Also implement "close on last release". * sync.h (muto::tid): Delete. (muto::tls): New field. (muto::ismine): Delete. (muto::owner): Delete. (muto::unstable): Delete. (muto::reset): Delete. (muto::upforgrabs): New method. (muto::grab): Ditto. (new_muto_name): New define. * wininfo.h: New file. (wininfo): New class. * window.cc: Rework throughout to use winfo class for controlling invisible window operation. (gethwnd): Delete definition. * winsup.h (gethwnd): Delete declaration.
Diffstat (limited to 'winsup/cygwin/sync.cc')
-rw-r--r--winsup/cygwin/sync.cc55
1 files changed, 30 insertions, 25 deletions
diff --git a/winsup/cygwin/sync.cc b/winsup/cygwin/sync.cc
index bd89793fd..a7994048d 100644
--- a/winsup/cygwin/sync.cc
+++ b/winsup/cygwin/sync.cc
@@ -22,11 +22,19 @@ details. */
#include <stdlib.h>
#include "sync.h"
#include "security.h"
+#include "thread.h"
+#include "cygtls.h"
#undef WaitForSingleObject
DWORD NO_COPY muto::exiting_thread;
+void
+muto::grab ()
+{
+ tls = &_my_tls;
+}
+
/* Constructor */
muto *
muto::init (const char *s)
@@ -69,13 +77,13 @@ muto::~muto ()
int
muto::acquire (DWORD ms)
{
- DWORD this_tid = GetCurrentThreadId ();
+ void *this_tls = &_my_tls;
#if 0
if (exiting_thread)
return this_tid == exiting_thread;
#endif
- if (tid != this_tid)
+ if (tls != this_tls)
{
/* Increment the waiters part of the class. Need to do this first to
avoid potential races. */
@@ -97,19 +105,25 @@ muto::acquire (DWORD ms)
if (!ms)
InterlockedIncrement (&waiters);
- tid = this_tid; /* register this thread. */
+ tls = this_tls; /* register this thread. */
}
return ++visits; /* Increment visit count. */
}
+bool
+muto::acquired ()
+{
+ return tls == &_my_tls;
+}
+
/* Return the muto lock. Needs to be called once per every acquire. */
int
muto::release ()
{
- DWORD this_tid = GetCurrentThreadId ();
+ void *this_tls = &_my_tls;
- if (tid != this_tid || !visits)
+ if (tls != this_tls || !visits)
{
SetLastError (ERROR_NOT_OWNER); /* Didn't have the lock. */
return 0; /* failed. */
@@ -118,33 +132,24 @@ muto::release ()
/* FIXME: Need to check that other thread has not exited, too. */
if (!--visits)
{
- tid = 0; /* We were the last unlocker. */
+ tls = 0; /* We were the last unlocker. */
(void) InterlockedExchange (&sync, 0); /* Reset trigger. */
/* This thread had incremented waiters but had never decremented it.
Decrement it now. If it is >= 0 then there are possibly other
threads waiting for the lock, so trigger bruteforce. */
if (InterlockedDecrement (&waiters) >= 0)
(void) SetEvent (bruteforce); /* Wake up one of the waiting threads */
+ else if (*name == '!')
+ {
+ CloseHandle (bruteforce); /* If *name == '!' and there are no
+ other waiters, then this is the
+ last time this muto will ever be
+ used, so close the handle. */
+#ifdef DEBUGGING
+ bruteforce = NULL;
+#endif
+ }
}
return 1; /* success. */
}
-
-bool
-muto::acquired ()
-{
- return tid == GetCurrentThreadId ();
-}
-
-/* Call only when we're exiting. This is not thread safe. */
-void
-muto::reset ()
-{
- visits = sync = tid = 0;
- InterlockedExchange (&waiters, -1);
- if (bruteforce)
- {
- CloseHandle (bruteforce);
- bruteforce = CreateEvent (&sec_none_nih, FALSE, FALSE, name);
- }
-}