* 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.
This commit is contained in:
Christopher Faylor
2010-03-13 19:34:35 +00:00
parent 084ea5108e
commit f8af64be87
5 changed files with 78 additions and 36 deletions

View File

@@ -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;
}
{
spinlock smi (shared_mem_inited, 10000);
if (!smi)
init_installation_root (); /* Initialize installation root dir */
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 ();
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;
}
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);
}