summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/shared.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2010-03-13 19:34:35 +0000
committerChristopher Faylor <me@cgf.cx>2010-03-13 19:34:35 +0000
commitf8af64be8716333f179a1d240ef42fab5188b607 (patch)
tree75eb82c89d02e0c32f69359dc558c076c7de1137 /winsup/cygwin/shared.cc
parent084ea5108e86738a09288268b186541b0c23920a (diff)
downloadcygnal-f8af64be8716333f179a1d240ef42fab5188b607.tar.gz
cygnal-f8af64be8716333f179a1d240ef42fab5188b607.tar.bz2
cygnal-f8af64be8716333f179a1d240ef42fab5188b607.zip
* 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/shared.cc')
-rw-r--r--winsup/cygwin/shared.cc57
1 files changed, 23 insertions, 34 deletions
diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc
index fcca6f40f..6e166f3fa 100644
--- a/winsup/cygwin/shared.cc
+++ b/winsup/cygwin/shared.cc
@@ -23,6 +23,7 @@ details. */
#include "registry.h"
#include "cygwin_version.h"
#include "pwdgrp.h"
+#include "spinlock.h"
#include "ntdll.h"
#include <alloca.h>
#include <wchar.h>
@@ -418,40 +419,28 @@ memory_init (bool init_cygheap)
}
/* Initialize general shared memory under spinlock control */
- for (;;)
- {
- LONG smi = InterlockedExchange (&shared_mem_inited, -1);
- if (smi < 0)
- {
- yield ();
- continue;
- }
-
- if (!smi)
- /* Initialize installation root dir */
- init_installation_root ();
-
- cygwin_shared = (shared_info *) open_shared (L"shared",
- CYGWIN_VERSION_SHARED_DATA,
- cygwin_shared_h,
- sizeof (*cygwin_shared),
- SH_CYGWIN_SHARED);
- heap_init ();
-
- if (!smi)
- {
- cygwin_shared->initialize ();
- /* Defer debug output printing the installation root and installation key
- up to this point. Debug output except for system_printf requires
- the global shared memory to exist. */
- debug_printf ("Installation root: <%W> key: <%S>",
- installation_root, &installation_key);
- smi = 1;
- }
-
- InterlockedExchange (&shared_mem_inited, smi);
- break;
- }
+ {
+ spinlock smi (shared_mem_inited, 10000);
+ if (!smi)
+ init_installation_root (); /* Initialize installation root dir */
+
+ cygwin_shared = (shared_info *) open_shared (L"shared",
+ CYGWIN_VERSION_SHARED_DATA,
+ cygwin_shared_h,
+ sizeof (*cygwin_shared),
+ SH_CYGWIN_SHARED);
+ heap_init ();
+
+ if (!smi)
+ {
+ cygwin_shared->initialize ();
+ /* Defer debug output printing the installation root and installation key
+ up to this point. Debug output except for system_printf requires
+ the global shared memory to exist. */
+ debug_printf ("Installation root: <%W> key: <%S>",
+ installation_root, &installation_key);
+ }
+ }
user_shared_create (false);
}