-
Notifications
You must be signed in to change notification settings - Fork 120
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
Fix & improves #178
Merged
Merged
Fix & improves #178
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6bd575e
fix photon gdb tool for current stack layout
Coldwings 4c5bf3a
test not suit for current mutex lock with yield
Coldwings 2fedbe5
async awaiter for executor & workpool
Coldwings e6fead9
fix pool dialer leaks socket client
Coldwings 4d914d5
async awaiter
Coldwings 260acce
Fix objcache ut, waits acquires done by semaphore
Coldwings File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Copyright 2022 The Photon Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <easy/easy_io.h> | ||
#include <easy/easy_uthread.h> | ||
#include <photon/thread/awaiter.h> | ||
|
||
namespace photon { | ||
|
||
struct EasyContext {}; | ||
|
||
template <> | ||
struct Awaiter<EasyContext> { | ||
easy_comutex_t mtx; | ||
Awaiter() { | ||
easy_comutex_init(&mtx); | ||
easy_comutex_cond_lock(&mtx); | ||
} | ||
~Awaiter() { easy_comutex_cond_unlock(&mtx); } | ||
void suspend() { easy_comutex_cond_wait(&mtx); } | ||
void resume() { | ||
easy_comutex_cond_lock(&mtx); | ||
easy_comutex_cond_signal(&mtx); | ||
easy_comutex_cond_unlock(&mtx); | ||
} | ||
}; | ||
|
||
} // namespace photon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../common/executor/easyawaiter.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../thread/awaiter.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
Copyright 2022 The Photon Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <errno.h> | ||
#include <photon/thread/thread.h> | ||
|
||
#include <atomic> | ||
#include <future> | ||
|
||
namespace photon { | ||
|
||
// Special context that supports calling executor in photon thread | ||
struct PhotonContext {}; | ||
|
||
// Context for stdthread calling executor | ||
struct StdContext {}; | ||
|
||
// Special context that can automaticlly choose `PhotonContext` or `StdContext` | ||
// by if photon initialized in current environment | ||
struct AutoContext {}; | ||
|
||
template <typename T> | ||
struct Awaiter; | ||
|
||
template <> | ||
struct Awaiter<PhotonContext> { | ||
photon::semaphore sem; | ||
Awaiter() {} | ||
void suspend() { sem.wait(1); } | ||
void resume() { sem.signal(1); } | ||
}; | ||
|
||
template <> | ||
struct Awaiter<StdContext> { | ||
int err; | ||
std::promise<void> p; | ||
std::future<void> f; | ||
Awaiter() : f(p.get_future()) {} | ||
void suspend() { f.get(); } | ||
void resume() { return p.set_value(); } | ||
}; | ||
|
||
template <> | ||
struct Awaiter<AutoContext> { | ||
Awaiter<PhotonContext> pctx; | ||
Awaiter<StdContext> sctx; | ||
bool is_photon = false; | ||
Awaiter() : is_photon(photon::CURRENT) {} | ||
void suspend() { | ||
if (is_photon) | ||
pctx.suspend(); | ||
else | ||
sctx.suspend(); | ||
} | ||
void resume() { | ||
if (is_photon) | ||
pctx.resume(); | ||
else | ||
sctx.resume(); | ||
} | ||
}; | ||
} // namespace photon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处是用future promise代替了原来的cond variable嘛? future promise性能怎么样,最终会被实现成啥同步原语?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GCC的标准库(libstdc++)中,future的wait动作使用condition_variable的wait_for实现。