-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C++11 thread requirements #274
Conversation
d8b2fcb
to
ecfd1d4
Compare
Built and ran the two test cases: Gives the expected output on both xqemu and real hardware. |
ecfd1d4
to
e8558ad
Compare
Just noticed that one of the code changes was accidentally spread over two commits. I fixed it with a rebase, the actual code didn't change. |
62fc8e2
to
b09edfc
Compare
b09edfc
to
3aae926
Compare
Tested 3aae926 using the supplied tests both on XQEMU and on real hardware. Still behaves as expected. 👍 |
c43260b
to
29e0272
Compare
} | ||
|
||
if (dwFlags & INIT_ONCE_INIT_FAILED) { | ||
if (lpContext || (dwFlags & INIT_ONCE_ASYNC)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see anything about this disallowing lpContext
on MSDN; I assume this was tested against Windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe? Tbh, I don't remember and currently can't find any test code on my HDD. I did switch the machine I do my experiments on a while ago though, so maybe I just wiped it with the old Windows installation.
I did just look up that part in ReactOS though, and it does the same here.
lib/winapi/sync.c
Outdated
return TRUE; | ||
} | ||
|
||
BOOL SleepConditionVariableSRW (PCONDITION_VARIABLE ConditionVariable, PSRWLOCK SRWLock, DWORD dwMilliseconds, ULONG Flags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: There's a lot of redundancy with SleepConditionVariableCS
that could have been factored out; fine as-is though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but the lock stuff is pretty much spread over the entire function. I think factoring it out would make the control flow much harder to understand.
29e0272
to
eaf7e88
Compare
static BOOL WINAPI condvar_init (PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context) | ||
{ | ||
PCONDITION_VARIABLE ConditionVariable = Parameter; | ||
NTSTATUS status; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Before creating new events, you could probably check (assert
) if this thing is really clean at this point:
ConditionVariable->initOnce.Ptr == 0
(this assumption would currently be broken after re-using aCONDITION_VARIABLE
without manually settingCONDITION_VARIABLE_INIT
afterUninitializeConditionVariable
)ConditionVariable->waitCount == 0
ConditionVariable->eventHandles[0] == INVALID_HANDLE_VALUE
ConditionVariable->eventHandles[1] == INVALID_HANDLE_VALUE
You'd just have to reintroduce the initialization of the events to INVALID_HANDLE_VALUE
in InitializeConditionVariable
.
These assumptions should always be true then, because they come from CONDITION_VARIABLE_INIT
or InitializeConditionVariable
.
However, I'll leave up to you wether you consider this a useful addition that's worth adding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I forgot about this.
We can't really check for ConditionVariable->initOnce.Ptr == 0
here, because the InitOnce API functions will change the value of this variable before calling this function, so it's never zero here.
I did add checks for the other conditions though.
eaf7e88
to
6af974c
Compare
6af974c
to
cedfa15
Compare
cedfa15
to
3091aaf
Compare
3091aaf
to
31a9220
Compare
I'm merging this untested, because it has been here for way too long.
There have been a couple of improvements in this new implementation during this review, which probably aren't in PDCLib yet. |
This implements all the winapi functionality required to enable the C++11 thread support in libc++: The InitOnce* API, Slim Reader/Writer Locks, and condition variables (I intended to split them up, but it just caused merge conflicts everywhere).
The support for condition variables is basically equivalent to how I implemented it for PDCLib, but it's modified for the lock types winapi provides. One crucial difference to the way this works on Windows, is that Windows uses keyed events to implement condition variables. We don't have that feature in the Xbox kernel, so instead, all functions use the InitOnce* API for initialization of normal events, and an additional function (which doesn't exist on Windows) is provided,
DestroyConditionVariable
, which frees the events. My thread-support patch for libc++ hooks that function up when building on nxdk.I've written some test code for SRW locks here, and some test code for the InitOnce* API here.