Repository navigation
Refactor explicit FLS usage in the runtime - #832
Conversation
|
Please note that setting the FLS value to the current thread pointer is now done before initializing the thread. I believe the change doesn't introduce any functional problem. |
|
@smosier I was trying to preserve the saveguard checks in the ThreadStore::AttachCurrentThread, but if we don't care about failing fast in case a thread is registered with a fiber and ThreadStore::AttachCurrentThread is called on another fiber and we are ok just doing nothing in that case, I could simplify it further by removing the isFirstAttach parameter of the PalAttachThread and returning from the ThreadStore::AttachCurrentThread without doing anything when the pAttachingThread->IsInitialized() is true. |
|
Implements #640 |
|
|
||
| REDHAWK_PALIMPORT UInt32 REDHAWK_PALAPI PalCompatibleWaitAny(UInt32_BOOL alertable, UInt32 timeout, UInt32 count, HANDLE* pHandles, UInt32_BOOL allowReentrantWait); | ||
|
|
||
| REDHAWK_PALIMPORT bool REDHAWK_PALAPI PalRegisterThreadShutdownCallback(ThreadShutdownCallback callback); |
There was a problem hiding this comment.
I look at this PAL just as some platform specific code factored into separate files. I do not look at it as independent piece.
I think it would be ok to just call extern C method with given name from the PAL, and not have this registration.
|
LGTM otherwise |
|
The original point of this fiber business was move the thread detach code to a place where the Win32 loader lock was not held. It's been too long for me to remember much more detail, but I will dig into it and get back to you. Do we have to worry about anything like the loader lock on unix? |
|
@smosier There is not such issue on Unix. |
03e7456 to
92b5433
Compare
|
Link error on Ubuntu |
92b5433 to
3146b1b
Compare
|
@jkotas, the PalInit in PalRedhawkUnix.cpp was missing REDHAWK_PALEXPORT and REDHAWK_PALAPI annotation. |
| void ThreadStore::DetachCurrentThread() | ||
| { | ||
| // | ||
| // Note: we call this when each *fiber* is destroyed, because we receive that notification outside |
There was a problem hiding this comment.
Shouldn't the comment be updated to remove the reference to fiber?
|
|
||
| if (attachedThread != NULL) | ||
| { | ||
| ASSERT_UNCONDITIONALLY("PalAttachThread called multiple times for the same thread"); |
There was a problem hiding this comment.
Nit - Regular assert may be more appropriate here.
|
LGTM |
13a0910 to
fe5bc43
Compare
|
|
||
| bool InitDLL(HANDLE hPalInstance) | ||
| { | ||
| if (!PalInit()) |
There was a problem hiding this comment.
Calling PalInit here will mean that it gets called twice in the PN runtime, which calls PalInit from DllMain. The reason for PN to do it this way was that we considered the runtime to be three separate parts: unmanaged (C++), managed (C#), and PAL. DllMain was responsible for initializing all 3 in the proper order. Putting the PalInit here will conflate the C++ and PAL pieces together and require some corresponding PN-side changes. Could we call PalInit from __initialize_runtime instead?
|
In general, I'd feel more comfortable about the FLS changes if you were to at least prototype the corresponding changes in the "app PAL" used by PN. This would help us understand if there are any unique issues there which might affect the form of these changes. |
| if (!PalQueryProcessorTopology()) | ||
| return false; | ||
|
|
||
| g_flsIndex = FlsAlloc(FiberDetachCallback); |
There was a problem hiding this comment.
Please add a comment about what we're doing with FLS here. Basically something along the lines of "we use fiber detach callbacks to run our thread shutdown code because the fiber detach callback is made without the OS loader lock" is what I'd like to see.
This change abstracts the FLS usage for thread shutdown notification in PAL into a general thread shutdown callback registration mechanism. It also implements its Unix version.
fe5bc43 to
8d00b43
Compare
|
@smosier I've reflected all your feedback. I am going to try to create the prototype change that you've asked for. |
This change replaces explicit FLS usage for thread shutdown notification in the runtime into a
general thread shutdown callback registration mechanism.
The implementation using the FLS on Windows is moved to the PalRedhawkWinMin.cpp.
On Unix, it is implemented using TLS, since there are no fibers.