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

[delegate] Refactor how AsyncResult are created for BeginInvoke #2568

Closed
wants to merge 4 commits into from

Conversation

luhenry
Copy link
Contributor

@luhenry luhenry commented Feb 3, 2016

No description provided.

@kumpera
Copy link
Contributor

kumpera commented Feb 3, 2016

The commit message is empty, there's nothing more than a title.

It lacks explanation of the changes and justifications on why they are being done.
Refactoring for the sake of moving stuff around is to be frowned upon.

Changes must have a reason and the commit should tell those.

There's an argument being removed because it's no longer used, but there's more going on
which warrants an explanation.

@luhenry luhenry force-pushed the asyncresult-refactor branch 3 times, most recently from c45003e to 73ff4a4 Compare February 4, 2016 19:35
When doing Delegate.BeginInvoke, we return an AsyncResult, and it has to cover 2 possible cases:
 - the remoting case
 - the threadpool case (or non-remote case)

The code paths both starts at mono_delegate_begin_invoke. In the threadpool case, we call mono_threadpool_ms_begin_invoke.

The previous implementation of mono_async_result_new would take the following 5 parameters:
 - domain
 - handle: it would always be NULL
 - state: used in both cases
 - data: it would always be NULL
 - object_data: it would only be non-NULL in the threadpool case

As 3 out of these 5 parameters are either not used, or used in only in one of the 2 cases, it's easier to get rid of them.

They have been replaces with the following parameters:
 - domain
 - delegate: the delegate to asynchronously call
 - state: the state to pass the above delegate
 - callback: the callback to call after the delegate

As for object_data, it is now set in the threadpool case after having created the AsyncResult object.

Finally, as the value returned by AsyncResult.Invoke is never used (and can never be used by the threadpool), we can simply set its return type to void.
@luhenry luhenry force-pushed the asyncresult-refactor branch 2 times, most recently from 50231be to c4c0b7e Compare February 12, 2016 14:11
This is invoked for every BeginInvoke in the runtime. By switching it to managed, we reduce the numer of LOC in the runtime, leading to less possible very hard to track bugs. We also reduce the number of transitions from managed to native and from native to managed, leading to better performance. Another added benefit is exception handling is better managed.
There is no os_handle field on ManualResetEvent, EventWaitHandle or WaitHandle, so f_os_handle would always be NULL.
We try here to reduce even further the number of transitions from managed to native and from native to managed. Exception propagation is also better done, as all the code is managed.
@lewurm
Copy link
Contributor

lewurm commented Mar 29, 2016

@ludovic-henry what's the status of this PR?

@luhenry luhenry closed this Mar 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants