Skip to content
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

winapi: Implement Suspend/Resume Thread #687

Merged
merged 1 commit into from
Dec 27, 2024
Merged

Conversation

Ryzee119
Copy link
Contributor

@Ryzee119 Ryzee119 commented Dec 27, 2024

Needed these, realised we had no winapi wrapper. Tested on xemu and hw with the below code:

#include <hal/debug.h>
#include <hal/video.h>
#include <windows.h>
#include <assert.h>

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
    while (1)
    {
        debugPrint("Worker thread is running...\n");
        Sleep(250);
    }
    return 0;
}

int main(void)
{
    XVideoSetMode(640, 480, 32, REFRESH_DEFAULT);

    HANDLE hThread = CreateThread(NULL, 0, ThreadProc, NULL, 0, NULL);

    // Let thread work for a while
    Sleep(1000);

    // Suspend the thread 3 times to test count
    SuspendThread(hThread);
    SuspendThread(hThread);
    DWORD dwPreviousCount = SuspendThread(hThread);

    // If the function succeeds, the return value is the thread's previous suspend count
    assert(dwPreviousCount == 2);

    // Ensure thread is suspended
    debugPrint("Thread is suspended\n");
    Sleep(1000);

    DWORD dwResumeCount = ResumeThread(hThread);

    // If the function succeeds, the return value is the thread's previous suspend count.
    // We suspend the thread 3 times, so we need to resume 3 times
    assert(dwResumeCount == 3);
    ResumeThread(hThread);

    // Ensure thread still isn't resumed yet
    Sleep(1000);

    // Okay, this should actually resume the thread
    ResumeThread(hThread);
    debugPrint("Thread is resumed\n");

    // Let thread work for a while
    Sleep(3000);

    return 0;
}

@mborgerson mborgerson merged commit 9bfd250 into XboxDev:master Dec 27, 2024
6 checks passed
@Ryzee119 Ryzee119 deleted the resume branch December 27, 2024 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants