Skip to content

Commit b95c810

Browse files
committed
Use BRAVO lock for g_records_rwlock
1 parent c904642 commit b95c810

6 files changed

Lines changed: 67 additions & 65 deletions

File tree

include/records/P_RecCore.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "tscore/ink_thread.h"
2727
#include "tscore/ink_rwlock.h"
2828
#include "tscore/TextBuffer.h"
29+
#include "tscpp/util/Bravo.h"
2930

3031
#include "I_RecCore.h"
3132
#include "P_RecDefs.h"
@@ -39,7 +40,7 @@
3940
// records, record hash-table, and hash-table rwlock
4041
extern RecRecord *g_records;
4142
extern std::unordered_map<std::string, RecRecord *> g_records_ht;
42-
extern ink_rwlock g_records_rwlock;
43+
extern ts::bravo::shared_mutex g_records_rwlock;
4344
extern int g_num_records;
4445
extern RecModeT g_mode_type;
4546

include/tscore/ink_memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static inline size_t __attribute__((const)) ats_pagesize()
119119
long ret = sysconf(_SC_PAGESIZE);
120120
page_size = (size_t)((ret > -1) ? ret : 8192);
121121
#elif defined(HAVE_GETPAGESIZE)
122-
page_size = (size_t)getpagesize()
122+
page_size = (size_t)getpagesize();
123123
#else
124124
page_size = (size_t)8192;
125125
#endif

src/records/P_RecCore.cc

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ RecSetRecord(RecT rec_type, const char *name, RecDataT data_type, RecData *data,
144144
// FIXME: Most of the time we set, we don't actually need to wrlock
145145
// since we are not modifying the g_records_ht.
146146
if (lock) {
147-
ink_rwlock_wrlock(&g_records_rwlock);
147+
g_records_rwlock.lock();
148148
}
149149
if (auto it = g_records_ht.find(name); it != g_records_ht.end()) {
150150
r1 = it->second;
@@ -204,7 +204,7 @@ RecSetRecord(RecT rec_type, const char *name, RecDataT data_type, RecData *data,
204204

205205
Ldone:
206206
if (lock) {
207-
ink_rwlock_unlock(&g_records_rwlock);
207+
g_records_rwlock.unlock();
208208
}
209209

210210
return err;
@@ -284,7 +284,7 @@ RecReadStatsFile()
284284
ats_scoped_str snap_fpath(RecConfigReadPersistentStatsPath());
285285

286286
// lock our hash table
287-
ink_rwlock_wrlock(&g_records_rwlock);
287+
std::lock_guard lock(g_records_rwlock);
288288

289289
CheckSnapFileVersion(snap_fpath);
290290

@@ -323,7 +323,6 @@ RecReadStatsFile()
323323
}
324324
}
325325

326-
ink_rwlock_unlock(&g_records_rwlock);
327326
ats_free(m);
328327

329328
return REC_ERR_OKAY;
@@ -393,14 +392,11 @@ RecReadConfigFile()
393392
RecDebug(DL_Note, "Reading '%s'", g_rec_config_fpath);
394393

395394
// lock our hash table
396-
ink_rwlock_wrlock(&g_records_rwlock);
395+
std::lock_guard lock(g_records_rwlock);
397396

398397
// Parse the actual file and hash the values.
399398
RecConfigFileParse(g_rec_config_fpath, RecConsumeConfigEntry);
400399

401-
// release our hash table
402-
ink_rwlock_unlock(&g_records_rwlock);
403-
404400
return REC_ERR_OKAY;
405401
}
406402

@@ -410,12 +406,12 @@ RecReadYamlConfigFile()
410406
RecDebug(DL_Debug, "Reading '%s'", g_rec_config_fpath);
411407

412408
// lock our hash table
413-
ink_rwlock_wrlock(&g_records_rwlock); // review this lock maybe it should be done inside the API
409+
// review this lock maybe it should be done inside the API
410+
std::lock_guard lock(g_records_rwlock);
414411

415412
// Parse the actual file and hash the values.
416413
auto ret = RecYAMLConfigFileParse(g_rec_config_fpath, SetRecordFromYAMLNode);
417414

418-
ink_rwlock_unlock(&g_records_rwlock);
419415
return ret;
420416
}
421417

@@ -429,7 +425,7 @@ RecExecConfigUpdateCbs(unsigned int update_required_type)
429425
int i, num_records;
430426
RecUpdateT update_type = RECU_NULL;
431427

432-
ink_rwlock_rdlock(&g_records_rwlock);
428+
ts::bravo::shared_lock lock(g_records_rwlock);
433429

434430
num_records = g_num_records;
435431
for (i = 0; i < num_records; i++) {
@@ -463,8 +459,6 @@ RecExecConfigUpdateCbs(unsigned int update_required_type)
463459
rec_mutex_release(&(r->lock));
464460
}
465461

466-
ink_rwlock_unlock(&g_records_rwlock);
467-
468462
return update_type;
469463
}
470464

@@ -540,7 +534,7 @@ RecSetSyncRequired(char *name, bool lock)
540534
// FIXME: Most of the time we set, we don't actually need to wrlock
541535
// since we are not modifying the g_records_ht.
542536
if (lock) {
543-
ink_rwlock_wrlock(&g_records_rwlock);
537+
g_records_rwlock.lock();
544538
}
545539
if (auto it = g_records_ht.find(name); it != g_records_ht.end()) {
546540
r1 = it->second;
@@ -556,7 +550,7 @@ RecSetSyncRequired(char *name, bool lock)
556550
}
557551

558552
if (lock) {
559-
ink_rwlock_unlock(&g_records_rwlock);
553+
g_records_rwlock.unlock();
560554
}
561555

562556
return err;

0 commit comments

Comments
 (0)