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

Auto-forwarding now waits for a result when using blocking mode before returning #133

Merged
merged 2 commits into from
Sep 8, 2020

Conversation

FletcherJ1
Copy link
Contributor

@FletcherJ1 FletcherJ1 commented Sep 4, 2020

I've added the wait method to the cmd_result class because calling get won't work due to how the presult variable is instantiated.

ptr< cmd_result< ptr<buffer> > >
presult( cs_new< cmd_result< ptr<buffer> > >() );

When presult is made, it calls a constructor that sets has_result_ to true. Then, if get() was used it would see that has_result_ is true and return immediately and not wait for the set_result call. Therefore, the explicit wait method will guarantee the current thread to wait until a call to set_result happens.

@greensky00
Copy link
Contributor

@FletcherJ1
Thanks for submitting the new PR.

I get your point regarding has_result_ value. But my understanding is that the code that you are referring to will call the default constructor (i.e., cmd_result()) as there is no parameter given for cmd_result: cs_new< cmd_result< ptr<buffer> > >()

I just checked with GDB and saw that has_result_ value is false.

Thread 1 "asio_service_te" hit Breakpoint 1, nuraft::raft_server::send_msg_to_leader (this=0x555555c65bf0,
    req=std::shared_ptr<nuraft::req_msg> (use count 1, weak count 0) = {...})
    at /home/junahn/sandbox/nuraft/src/handle_user_cmd.cxx:187
187	    rpc_cli->send(req, handler);
(gdb) p presult->has_result_
$1 = false
(gdb) p presult->result_
$2 = std::shared_ptr<nuraft::buffer> (empty) = {get() = 0x0}
(gdb)

If that's the case, we can just use the existing get() function. Could you please double-check? Thanks!

@FletcherJ1
Copy link
Contributor Author

Ah yes, you're correct. I've swapped to using get and it works!

@greensky00 greensky00 merged commit 7c32f32 into eBay:master Sep 8, 2020
@greensky00
Copy link
Contributor

Merged, thanks!

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.

2 participants