make ObQSyncLock read priority

This commit is contained in:
obdev 2023-03-14 16:11:07 +00:00 committed by ob-robot
parent 26e1fb4b74
commit 5e391b5bea
2 changed files with 10 additions and 3 deletions

View File

@ -50,11 +50,16 @@ int ObQSyncLock::wrlock()
if (!ATOMIC_BCAS(&write_flag_, 0, 1)) {
sched_yield();
} else {
// write priority try sync to succ
while (!qsync_.try_sync()) {
bool sync_success = false;
for (int64_t i = 0; !sync_success && i < TRY_SYNC_COUNT; i++) {
sync_success = qsync_.try_sync();
}
if (sync_success) {
break;
} else {
ATOMIC_STORE(&write_flag_, 0);
sched_yield();
}
break;
}
} while (true);
return common::OB_SUCCESS;

View File

@ -33,6 +33,8 @@ public:
int wrlock();
void wrunlock();
int try_rdlock();
private:
static const int64_t TRY_SYNC_COUNT = 16;
private:
int64_t write_flag_ CACHE_ALIGNED;
common::ObDynamicQSync qsync_;