-
Notifications
You must be signed in to change notification settings - Fork 4k
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
epoll bthread deal first #2819
base: master
Are you sure you want to change the base?
epoll bthread deal first #2819
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you 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. | ||
|
||
// bthread - An M:N threading library to make applications more concurrent. | ||
|
||
// Date: Thu Nov 14 13:40:57 CST 2024 | ||
#include "parking_lot.h" | ||
|
||
namespace bthread { | ||
|
||
butil::atomic<int> ParkingLot::_waiting_count{0}; | ||
|
||
} // namespace bthread |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ namespace bthread { | |
// Park idle workers. | ||
class BAIDU_CACHELINE_ALIGNMENT ParkingLot { | ||
public: | ||
static butil::atomic<int> _waiting_count; | ||
zhengJade marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里减少的是都繁忙情况下不要 signal,而不是说能够准确的 signal 阻塞的 pl,在比较繁忙的情况是实际上是不存在部分 wait,部分 wake 的,而且 sigal 的时候有返回值的,如果返回失败会接着 signal 另一个 pl |
||
class State { | ||
public: | ||
State(): val(0) {} | ||
|
@@ -57,14 +58,17 @@ class BAIDU_CACHELINE_ALIGNMENT ParkingLot { | |
// Wait for tasks. | ||
// If the `expected_state' does not match, wait() may finish directly. | ||
void wait(const State& expected_state) { | ||
_waiting_count++; | ||
futex_wait_private(&_pending_signal, expected_state.val, NULL); | ||
_waiting_count--; | ||
} | ||
|
||
// Wakeup suspended wait() and make them unwaitable ever. | ||
void stop() { | ||
_pending_signal.fetch_or(1); | ||
futex_wake_private(&_pending_signal, 10000); | ||
} | ||
|
||
private: | ||
// higher 31 bits for signalling, LSB for stopping. | ||
butil::atomic<int> _pending_signal; | ||
|
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.
这里应该是 g_edisp[i * FLAGS_event_dispatcher_num + j] 吧?
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.
是的,我本地二次修改的时候没提交上来