From f8af64be8716333f179a1d240ef42fab5188b607 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Sat, 13 Mar 2010 19:34:35 +0000 Subject: * 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. --- winsup/cygwin/spinlock.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 winsup/cygwin/spinlock.h (limited to 'winsup/cygwin/spinlock.h') 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*/ + -- cgit v1.2.3