feng-y opened a new issue #1243:
URL: https://github.com/apache/incubator-brpc/issues/1243


   **Describe the solution you'd like (描述你期望的解决方法)**
   `brpc::Join(CallId id) ` 增加一个参数支持,最长等待时间, `brpc::Join(CallId id, int64_t 
int64_t waiting_us) `
   
   **Describe alternatives you've considered (描述你想到的折衷方案)**
   `
   index 23046b25..caf99b40 100644
   --- a/src/bthread/id.cpp
   +++ b/src/bthread/id.cpp
   @@ -510,6 +510,10 @@ int bthread_id_cancel(bthread_id_t id) {
    }
   
    int bthread_id_join(bthread_id_t id) {
   +  return bthread_id_join(id, 0);
   +}
   +
   +int bthread_id_join(bthread_id_t id, int64_t us) {
        const bthread::IdResourceId slot = bthread::get_slot(id);
        bthread::Id* const meta = address_resource(slot);
        if (!meta) {
   @@ -526,9 +530,17 @@ int bthread_id_join(bthread_id_t id) {
            if (!has_ver) {
                break;
            }
   -        if (bthread::butex_wait(join_butex, expected_ver, NULL) < 0 &&
   -            errno != EWOULDBLOCK && errno != EINTR) {
   +        if (us > 0) {
   +          timespec abstime = butil::microseconds_to_timespec(us + 
butil::gettimeofday_ns());
   +          if (bthread::butex_wait(join_butex, expected_ver, &abstime) < 0 &&
   +              errno != EWOULDBLOCK && errno != EINTR) {
                return errno;
   +          }
   +        } else {
   +          if (bthread::butex_wait(join_butex, expected_ver, NULL) < 0 &&
   +              errno != EWOULDBLOCK && errno != EINTR) {
   +              return errno;
   +          }
            }
        }
        return 0;`
   
   **Additional context/screenshots (更多上下文/截图)**
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to