Copilot commented on code in PR #3053:
URL: https://github.com/apache/brpc/pull/3053#discussion_r2249128687
##########
src/bthread/rwlock.cpp:
##########
@@ -53,18 +53,29 @@ static int rwlock_rdlock_impl(bthread_rwlock_t* __restrict
rwlock,
// Don't sample when contention profiler is off.
if (NULL == bthread::g_cp) {
- return bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ int rc = bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ if (rc != 0){
Review Comment:
[nitpick] Missing space before opening brace. Should be 'if (rc != 0) {' to
follow consistent formatting style.
```suggestion
if (rc != 0) {
```
##########
src/bthread/rwlock.cpp:
##########
@@ -53,18 +53,29 @@ static int rwlock_rdlock_impl(bthread_rwlock_t* __restrict
rwlock,
// Don't sample when contention profiler is off.
if (NULL == bthread::g_cp) {
- return bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ int rc = bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ if (rc != 0){
+ ((butil::atomic<int>*)&rwlock->reader_count)->fetch_add(-1,
butil::memory_order_relaxed);
+ }
+ return rc;
}
// Ask Collector if this (contended) locking should be sampled.
const size_t sampling_range = bvar::is_collectable(&bthread::g_cp_sl);
if (!bvar::is_sampling_range_valid(sampling_range)) { // Don't sample.
- return bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ int rc = bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ if (rc != 0){
+ ((butil::atomic<int>*)&rwlock->reader_count)->fetch_add(-1,
butil::memory_order_relaxed);
+ }
+ return rc;
}
// Sample.
const int64_t start_ns = butil::cpuwide_time_ns();
int rc = bthread_sem_timedwait(&rwlock->reader_sema, abstime);
const int64_t end_ns = butil::cpuwide_time_ns();
+ if (rc != 0){
Review Comment:
[nitpick] Missing space before opening brace. Should be 'if (rc != 0) {' to
follow consistent formatting style.
```suggestion
if (rc != 0) {
```
##########
src/bthread/rwlock.cpp:
##########
@@ -53,18 +53,29 @@ static int rwlock_rdlock_impl(bthread_rwlock_t* __restrict
rwlock,
// Don't sample when contention profiler is off.
if (NULL == bthread::g_cp) {
- return bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ int rc = bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ if (rc != 0){
+ ((butil::atomic<int>*)&rwlock->reader_count)->fetch_add(-1,
butil::memory_order_relaxed);
+ }
+ return rc;
}
// Ask Collector if this (contended) locking should be sampled.
const size_t sampling_range = bvar::is_collectable(&bthread::g_cp_sl);
if (!bvar::is_sampling_range_valid(sampling_range)) { // Don't sample.
- return bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ int rc = bthread_sem_timedwait(&rwlock->reader_sema, abstime);
+ if (rc != 0){
Review Comment:
[nitpick] Missing space before opening brace. Should be 'if (rc != 0) {' to
follow consistent formatting style.
```suggestion
if (rc != 0) {
```
--
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]