[threading] Switch to a native implementation of LowLevelLifoSemaphore (#2098)
authorRyan Lucia <rylucia@microsoft.com>
Wed, 12 Feb 2020 22:14:21 +0000 (17:14 -0500)
committerGitHub <noreply@github.com>
Wed, 12 Feb 2020 22:14:21 +0000 (17:14 -0500)
commit3eaff603cdb6787006049a5376e695a6e4e462ba
treed3f00854af590d7cd09bc77b1fb5d167ddd8e69c
parent084dd1a5aae0fbe6ed4f9164ac4ee1c5f0b2398f
[threading] Switch to a native implementation of LowLevelLifoSemaphore (#2098)

This change is motivated on two main fronts. The first is maintainability - the current managed implementation is difficult to understand and I worry diagnosing any potential issues would be a massive time sink. The second is performance - the current implementation appears to suffer from significant lock contention when running the TechEmpower plaintext benchmark. My hope is that the simpler, cleaner native implementation here will avoid both problems, but I don't want to merge it until we have benchmarking data. However, even if the numbers are similar, I still think it's worth merging just from a maintainability perspective.

The native LifoSemaphore implementation has only ever been tested on posix-like platforms, so Windows behavior is unknown. Currently the Windows implementation of LowLevelLifoSemaphore is very different, so unless we have need for the LifoSemaphore elsewhere in the runtime this isn't a concern.

Many thanks to @filipnavara for the initial implementation.
src/mono/mono/metadata/icall-decl.h
src/mono/mono/metadata/icall-def-netcore.h
src/mono/mono/metadata/threads.c
src/mono/mono/utils/Makefile.am
src/mono/mono/utils/lifo-semaphore.c [new file with mode: 0644]
src/mono/mono/utils/lifo-semaphore.h [new file with mode: 0644]
src/mono/msvc/libmonoutils-common.targets
src/mono/msvc/libmonoutils-common.targets.filters
src/mono/netcore/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Unix.Mono.cs