shanhe72101 opened a new issue, #3051:
URL: https://github.com/apache/brpc/issues/3051
**Describe the bug**
apache_brpc/src/bthread/rwlock.cpp
函数rwlock_rdlock_impl
首先会给reader_count加1,超时失败并未恢复计数
因为没有替代方案,严重影响项目进度,跪求大佬们尽快响应,感激不尽!
**To Reproduce**
**Expected behavior**
**Versions**
OS: Ubuntu 24.04.1 LTS
Compiler: gcc 13.3
brpc:1.11.0
protobuf:
**Additional context/screenshots**
为了能够使用std::unique_lock和std::shared_lock管理锁,封装了一个代理类,希望官方能够原生支持,或者推出自己的unique_lock和shared_lock,感谢
class SharedTimedButex {
public:
void lock() {
rwlock.wrlock();
}
bool try_lock() {
return rwlock.try_wrlock();
}
template<typename _Rep, typename _Period>
bool try_lock_for(const std::chrono::duration<_Rep, _Period>&
delay_time) {
struct timespec ts;
get_timespec_after_ms(&ts, delay_time);
return rwlock.timed_wrlock(&ts);
}
void unlock() {
rwlock.unlock();
}
void lock_shared() {
rwlock.rdlock();
}
bool try_lock_shared() {
return rwlock.try_rdlock();
}
template<typename _Rep, typename _Period>
bool try_lock_shared_for(const std::chrono::duration<_Rep, _Period>&
delay_time) {
struct timespec ts;
get_timespec_after_ms(&ts, delay_time);
return rwlock.timed_rdlock(&ts);
}
void unlock_shared() {
rwlock.unlock();
}
private:
template<typename _Rep, typename _Period>
void get_timespec_after_ms(struct timespec* ts, const
std::chrono::duration<_Rep, _Period>& delay_time) {
const auto delay_ns =
std::chrono::duration_cast<std::chrono::nanoseconds>(delay_time).count();
clock_gettime(CLOCK_REALTIME, ts);
ts->tv_sec += delay_ns / std::nano::den;
ts->tv_nsec += delay_ns % std::nano::den;
if (ts->tv_nsec >= std::nano::den) {
ts->tv_sec += 1;
ts->tv_nsec %= std::nano::den;
}
}
bthread::RWLock rwlock;
};
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]