Add cooperative suspend aware threads for hybrid suspend. (mono/mono#15204)
authorJohan Lorensson <lateralusx.github@gmail.com>
Tue, 25 Jun 2019 15:40:39 +0000 (17:40 +0200)
committerGitHub <noreply@github.com>
Tue, 25 Jun 2019 15:40:39 +0000 (17:40 +0200)
commitf1953ca13f2df0a88c902013a02915d9344edbaa
tree91768d36721c4154be457a46e92be1de0e010d1f
parent320789f10c13be587967ce44b33d4ebb877fdaa1
Add cooperative suspend aware threads for hybrid suspend. (mono/mono#15204)

* Add cooperative suspend aware threads for hybrid suspend.

When running in hybrid suspend and having threads in blocking mode, GC Safe
mode, threads will still be preemptive suspended. This is done to make sure
compatibility is kept with embedders since current embedding API is not coop
aware. If, however the external attached threads promise to follow the coop
rules for a thread in Safe mode, it could still be possible to have them
running, making sure they won't be preempted when running STW. Unlocking this
possibility could have large performance wins if embedding threads runs a lot
of native code on threads attached to runtime.

This commit adds support for a new pair of API's where an external thread can
mark itself as cooperative suspend aware. Doing that guarantees the runtime
that it will follow all rules as dictated by cooperative suspend when a thread
is in safe mode. The change only goes one way since this is a lifetime commitment
for a thread. Once’s set, thread will be kept running when in safe mode.

Commit migrated from https://github.com/mono/mono/commit/5ca92bdbe8fc2f151c44b21b09ce53c4ad6ec379
src/mono/mono/utils/mono-threads-api.h
src/mono/mono/utils/mono-threads-coop.c
src/mono/mono/utils/mono-threads-windows.c
src/mono/mono/utils/mono-threads.c
src/mono/mono/utils/mono-threads.h