Conversation
|
Not ready for review yet... |
|
@guantaol ping |
guantaol
left a comment
There was a problem hiding this comment.
General comment: please add some comments for the changes in those .cc files and .h files. I do not think I can understand what you want to achieve without comments.
src/core/lib/iomgr/ev_apple.cc
Outdated
| grpc_core::CondVar cv; | ||
| }; | ||
|
|
||
| static GlobalRunloopContext global_runloop_context; |
There was a problem hiding this comment.
According to Google C++ style guide https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables, static objects must be trivially destructible.
src/core/lib/iomgr/ev_apple.cc
Outdated
| #endif // NDEBUG | ||
|
|
||
| struct GlobalRunloopContext { | ||
| grpc_core::Mutex mu; |
There was a problem hiding this comment.
Which fields are guarded by this mutex?
src/core/lib/iomgr/ev_apple.cc
Outdated
| GrpcApplePollset* apple_pollset = | ||
| reinterpret_cast<GrpcApplePollset*>(pollset); | ||
| if (worker != nullptr) { | ||
| *worker = nullptr; |
There was a problem hiding this comment.
If you set worker to nullptr, how could you kick it later?
There was a problem hiding this comment.
I think it works if pollset_kick broadcasts, according to comments here
There was a problem hiding this comment.
What happens if there is a thread that do not want to be kicked by the broadcast? Previously this thread could simply set grpc_pollset_worker** worker == nullptr. Now all the thread using the same pollset will be waken up altogether.
|
@guantaol - updated. PTAL |
|
@guantaol ping~ |
guantaol
left a comment
There was a problem hiding this comment.
I still need at least one other pass for this PR. Feel free to schedule a meeting to discuss this PR if that is more efficient.
src/core/lib/iomgr/ev_apple.cc
Outdated
| @@ -0,0 +1,252 @@ | |||
| /* | |||
| * | |||
| * Copyright 2015 gRPC authors. | |||
src/core/lib/iomgr/ev_apple.cc
Outdated
| grpc_core::CondVar init_cv; | ||
| grpc_core::CondVar input_source_cv; | ||
|
|
||
| // Protects all the variables below |
There was a problem hiding this comment.
This comment may not be true in the future if someone else adds a new member that is not protected by mu. May be better to use this style of comments (as other reviewers suggested to me in the past):
bool input_source_registered = false; /* GUARDED_BY(mu) */
...
When someday we actually introduce the GUARDED_BY annotation in grpc, it can be easily converted.
src/core/lib/iomgr/ev_apple.cc
Outdated
| static grpc_core::Thread* gGlobalRunLoopThread = nullptr; | ||
|
|
||
| /// Register the stream with the dispatch queue. Callbacks of the stream will be | ||
| /// issued to the dispatch queue and managed by Grand Central Dispatch. |
There was a problem hiding this comment.
When will the callback be issued, before or after read happens?
There was a problem hiding this comment.
Added comment to explain in the code
src/core/lib/iomgr/ev_apple.cc
Outdated
| } | ||
|
|
||
| /// Register the stream with the dispatch queue. Callbacks of the stream will be | ||
| /// issued to the dispatch queue and managed by Grand Central Dispatch. |
There was a problem hiding this comment.
Added comment to explain in the code
src/core/lib/iomgr/ev_apple.cc
Outdated
| GrpcApplePollset* apple_pollset = | ||
| reinterpret_cast<GrpcApplePollset*>(pollset); | ||
| if (worker != nullptr) { | ||
| *worker = nullptr; |
There was a problem hiding this comment.
What happens if there is a thread that do not want to be kicked by the broadcast? Previously this thread could simply set grpc_pollset_worker** worker == nullptr. Now all the thread using the same pollset will be waken up altogether.
src/core/lib/iomgr/ev_apple.cc
Outdated
| *worker = nullptr; | ||
| } | ||
| while (!apple_pollset->kicked) { | ||
| if (apple_pollset->cv.Wait( |
There was a problem hiding this comment.
Why don't we need to grab the pollset mutex beforehand? If it is required to hold the mutex before calling pollset_work, this should be commented out.
There was a problem hiding this comment.
It is exactly because it is required to hold the mutex before calling grpc_pollset_work. I don't really understand what you mean by "this should be commented out"
|
@guantaol - Updated. PTAL |
src/core/lib/iomgr/ev_apple.cc
Outdated
| *worker = reinterpret_cast<grpc_pollset_worker*>(&actual_worker); | ||
| } | ||
|
|
||
| if (apple_pollset->outstanding_kick) { |
There was a problem hiding this comment.
If this is the same as the kicked_without_poller in ev_epollex_linux, I suggest using the same name for easy understanding.
|
|
||
| return GRPC_ERROR_NONE; | ||
| } | ||
|
|
There was a problem hiding this comment.
Please add a comment to explain which mutex must be held before calling kick_worker().
|
Squashing commits |
Use a CFRunLoop based iomgr for CFStream on apple platforms. Workaround for the Apple bug where CFStream gets stuck on read.
The new iomgr spawns a global thread to handle all the CFStream callbacks. Network events are driven by the global thread. The pollset is a dummy conditional variable blocked on
pollset_workand can be awaken bypollset_kick.The CFStream networking layer is supposed to be included on iOS-targeted builds but not MacOS-targeted builds. It is supposed to be specified in the header
port_platform.h. Specifying it for Mac in .bzl file is not the right thing to do. Fixing this issue in the PR as well.