From a9ff3dc41192afa82e052a8550725cf74bf13cf2 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 27 Jun 2018 14:53:21 +0100 Subject: [PATCH 1/2] Branching master to branch/2018-06-27/job004056. Copied from Perforce Change: 194240 From b6b66edf9be7e861587dfd50495d810c8197f631 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Thu, 28 Jun 2018 12:39:06 +0100 Subject: [PATCH 2/2] Use initonceexecuteonce to get thread-safe initialization of the global locks. This means that the MPS no longer supports Windows XP, so update documentation accordingly. Exercise the global locks in lockut. Copied from Perforce Change: 194253 --- mps/code/lockut.c | 7 +++++++ mps/code/lockw3.c | 25 ++++++++++++++++++++++--- mps/manual/source/guide/overview.rst | 3 ++- mps/manual/source/release.rst | 9 +++++++++ mps/readme.txt | 3 ++- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/mps/code/lockut.c b/mps/code/lockut.c index a6e592988f1..9f9637914f0 100644 --- a/mps/code/lockut.c +++ b/mps/code/lockut.c @@ -57,7 +57,14 @@ static void inc(unsigned long i) #define COUNT 100000l static void *thread0(void *p) { + unsigned i; testlib_unused(p); + LockClaimGlobal(); + LockReleaseGlobal(); + for (i = 0; i < COUNT; ++i) + LockClaimGlobalRecursive(); + for (i = 0; i < COUNT; ++i) + LockReleaseGlobalRecursive(); inc(COUNT); return NULL; } diff --git a/mps/code/lockw3.c b/mps/code/lockw3.c index a2266542158..ba177c6b68b 100644 --- a/mps/code/lockw3.c +++ b/mps/code/lockw3.c @@ -136,13 +136,32 @@ void LockInitGlobal(void) globalLockInit = TRUE; } -static void lockEnsureGlobalLock(void) +/* lockEnsureGlobalLock -- one-time initialization of global locks + * + * InitOnceExecuteOnce ensures that only one thread can be running the + * callback at a time, which allows to safely check globalLockInit. See + * + * but note that at time of writing (2018-06-27) the documentation has + * the arguments the wrong way round (parameter comes before context). + */ + +static BOOL CALLBACK lockEnsureGlobalLockCallback(INIT_ONCE *init_once, void *parameter, void **context) { - /* Ensure both global locks have been initialized. */ - /* There is a race condition initializing them (job004056). */ + UNUSED(init_once); + AVER(parameter == UNUSED_POINTER); + UNUSED(context); if (!globalLockInit) { LockInitGlobal(); } + return TRUE; +} + +static void lockEnsureGlobalLock(void) +{ + static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT; + BOOL b = InitOnceExecuteOnce(&init_once, lockEnsureGlobalLockCallback, + UNUSED_POINTER, NULL); + AVER(b); } void (LockClaimGlobalRecursive)(void) diff --git a/mps/manual/source/guide/overview.rst b/mps/manual/source/guide/overview.rst index 116843e9697..c813aaf34c4 100644 --- a/mps/manual/source/guide/overview.rst +++ b/mps/manual/source/guide/overview.rst @@ -50,7 +50,8 @@ Supported target platforms The MPS is currently supported for deployment on: -- Windows XP or later, on IA-32 and x86-64, using Microsoft Visual C/C++; +- Windows Vista or later, on IA-32 and x86-64, using Microsoft Visual + C/C++; - Linux 2.6 or later, on IA-32 using GCC and on x86-64 using GCC or Clang/LLVM; diff --git a/mps/manual/source/release.rst b/mps/manual/source/release.rst index bdde9d1e04d..ed92bbc085f 100644 --- a/mps/manual/source/release.rst +++ b/mps/manual/source/release.rst @@ -15,6 +15,15 @@ New features #. On FreeBSD, Linux and macOS, the MPS is now able to run in the child process after ``fork()``. See :ref:`topic-thread-fork`. +#. The MPS now supports Windows Vista or later; it no longer supports + Windows XP. (Microsoft's own support for Windows XP `expired in + April 2014`_.) This is so that we can use |InitOnceExecuteOnce|_ to + ensure thread-safe initialization. + + .. _expired in April 2014: https://www.microsoft.com/en-gb/windowsforbusiness/end-of-xp-support + .. |InitOnceExecuteOnce| replace:: ``InitOnceExecuteOnce()`` + .. _InitOnceExecuteOnce: https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-initonceexecuteonce + .. _release-notes-1.116: diff --git a/mps/readme.txt b/mps/readme.txt index 747abcc727c..115ec3d01d3 100644 --- a/mps/readme.txt +++ b/mps/readme.txt @@ -72,7 +72,8 @@ Supported target platforms The MPS is currently supported for deployment on: -- Windows XP or later, on IA-32 and x86-64, using Microsoft Visual C/C++; +- Windows Vista or later, on IA-32 and x86-64, using Microsoft Visual + C/C++; - Linux 2.6 or later, on IA-32 using GCC and on x86-64 using GCC or Clang/LLVM;