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