diff options
author | Christopher Faylor <me@cgf.cx> | 2010-03-13 22:34:35 +0300 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2010-03-13 22:34:35 +0300 |
commit | f8af64be8716333f179a1d240ef42fab5188b607 (patch) | |
tree | 75eb82c89d02e0c32f69359dc558c076c7de1137 /winsup/cygwin/spinlock.h | |
parent | 084ea5108e86738a09288268b186541b0c23920a (diff) |
* spinlock.h: New file.
(spinlock): New class.
* shared.cc: Include spinlock.h.
(memory_init): Use new spinlock methods rather than roll-your-own. Time out
after ten seconds if shared_mem_inited is not initialized.
* sync.h: Update copyright. Remove vanity attribution.
* sigproc.cc (sigproc_terminate): Avoid attempts to kill the signal thread
while we're still initializing or suffer a deadlock.
Diffstat (limited to 'winsup/cygwin/spinlock.h')
-rw-r--r-- | winsup/cygwin/spinlock.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/winsup/cygwin/spinlock.h b/winsup/cygwin/spinlock.h new file mode 100644 index 000000000..abf723acc --- /dev/null +++ b/winsup/cygwin/spinlock.h @@ -0,0 +1,40 @@ +/* spinlock.h: Header file for cygwin time-sensitive synchronization primitive. + + Copyright 2010 Red Hat, Inc. + +This file is part of Cygwin. + +This software is a copyrighted work licensed under the terms of the +Cygwin license. Please consult the file "CYGWIN_LICENSE" for +details. */ + +#ifndef _SPINLOCK_H +#define _SPINLOCK_H + +#include "hires.h" + +class spinlock +{ + LONG *locker; + LONG val; +public: + spinlock (LONG& locktest, LONGLONG timeout): + locker (&locktest) + { + if ((val = locktest) == 1) + return; + LONGLONG then = gtod.msecs (); + for (;;) + { + if ((val = InterlockedExchange (locker, -1)) != -1 + || (gtod.msecs () - then) >= timeout) + break; + yield (); + } + } + ~spinlock () {InterlockedExchange (locker, 1);} + operator LONG () const {return val;} +}; + +#endif /*_SPINLOCK_H*/ + |