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

Single-threaded asynchronous svrplus #198

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

DankRank
Copy link
Contributor

// The installation is done on a separate thread so that we don't lock the message loop
   - © 2017 Egor 

Well, turns out there is a way to do this without having to resort to multithreading. MsgWaitForMultipleObjects treats message queue as yet another object, allowing us to wait for regsvr32 to finish, while handling incoming messages on the same thread.

Why even bother? Well, IMO, multithreading should only be used when it's actually needed (i.e. in computationally expensive and/or unbounded code). Using it here was more of a hack than anything else. However, there is a benefit to this. Now it's very easy to make regsvr32 run for 32 and 64 bit DLLs at the same time. I'm not sure if that would be a sane thing to do, so I haven't looked into it yet, and I'm not including it in this PR.

Right now this works similarly to the DialogBox function.

Dialog end is done differently. EndDialog sets a flag in a struct and
sends a WM_NULL to the window. The message loop checks the flag on each
iteration, and if it's present, it terminates the loop, saves the return
value (also from the same struct), and calls DestroyWindow.

Aforementioned struct (called DIALOGINFO in Wine/ROS) is undocumented,
so we have to do this ourselves. For simplicity, EndDialog is replaced
with DestroyWindow+PostQuitMessage. This is less robust, but good enough
for our purposes.
We only really need to wait for one object at the time, but:
- it's only ~7 lines of code to make it work with 63 objects
- we might want to install both things in parallel at some point
Now all blocking code is in ThreadProc
now it runs asnychronously
@GerbilSoft
Copy link
Owner

I'll need to take a closer look at this before merging, since I haven't used async functions on Windows.

@GerbilSoft GerbilSoft self-assigned this Oct 20, 2019
@GerbilSoft GerbilSoft added this to the 1.5 milestone Oct 20, 2019
@GerbilSoft
Copy link
Owner

There seems to be some visual artifacting when updating the onscreen messages when registering/unregistering DLLs. I'll take a look at fixing this first.

@GerbilSoft
Copy link
Owner

GerbilSoft commented Jan 18, 2020

I'm not sure what's causing the weird window updating. Also, it looks like both DLLs are registered in parallel, which is probably not a good idea, since they both touch the same parts of the registry (even on 64-bit).

Leaving this in feature/svrplus-async for now.

EDIT: The DLLs aren't being registered in parallel; the WM_APP_TASK and WM_APP_SIGNAL messages are being used to handle this. However, using the message loop to handle processes is likely what's causing the visual artifacting.

@DankRank
Copy link
Contributor Author

Check if visual artifacting is present in b557ed4 and the commit before it (or just bisect. each individual commit should compile, run and work). That commit is supposed to reimplement the DialogBoxW function so that GetMessage can be later replaced, and it might be missing something.

@GerbilSoft GerbilSoft removed this from the 1.5 milestone Mar 14, 2020
Apparently all message-waiting functions are edge-triggered, not
level-triggered as I thought.

This should fix the graphical bugs.

Obligatory oldnewthing link:
<https://web.archive.org/web/20190127104202/https://blogs.msdn.microsoft.com/oldnewthing/20050217-00/?p=36423>
Commits from master which touched svrplus.c:
5aa6a3d
6234bd0
972e32b
056c7a3
25c6aa5
00aac94
fcb238f
88ab807
b09471a

Also, updated copyright year.
Commits from master which touched svrplus.c:
69e4d89
e845f51
ef0f7d2
3899553
bef1caa
b6ab51c
4f32188
81626e9

This time the only conflict was the copyright year.
@DankRank
Copy link
Contributor Author

Looks like I forgot to notify you when I fixed this. I merged the changes from master and tested it, it seems to work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants