Skip to content

Commit 5a58784

Browse files
authored
atomic.h: Rename gettid() -> mdbm_gettid() to avoid conflicts (#11)
* atomic.h: Rename gettid() -> mdbm_gettid() to avoid conflicts Recent versions of glibc contain a gettid syscall wrapper, starting with 2.30. This causes the following compile error on anything that includes it, such as Ubuntu LTS 20.04. Rename the function to fix it. This should also return a int32_t instead of uint32_t to match the actual kernel and glibc definitions. In file included from mdbm.c:47: atomic.h:102:24: error: conflicting types for 'gettid' 102 | static inline uint32_t gettid() { | ^~~~~~ In file included from /usr/include/unistd.h:1170, from mdbm.c:29: /usr/include/x86_64-linux-gnu/bits/unistd_ext.h:34:16: note: previous declaration of 'gettid' was here 34 | extern __pid_t gettid (void) __THROW; | ^~~~~~ * Add missing rename (OOPS)
1 parent fa0a158 commit 5a58784

File tree

8 files changed

+27
-23
lines changed

8 files changed

+27
-23
lines changed

src/lib/atomic.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,27 @@ static inline void atomic_pause() {
9494
}
9595

9696

97-
/* returns (linux-specific) thread-id (for single-thread processes it's just PID) */
98-
static inline uint32_t gettid() {
99-
/* AUTO_TSC("gettid()"); */
97+
/*
98+
returns (linux-specific) thread-id (for single-thread processes it's just PID).
99+
Renamed to not conflict with glibc 2.30's gettid wrapper.
100+
On Linux gettid returns pid_t which is int32_t.
101+
*/
102+
static inline int32_t mdbm_gettid() {
103+
/* AUTO_TSC("mdbm_gettid()"); */
100104
#ifdef __linux__
101105
return syscall(SYS_gettid);
102106
#else
103107
/* Horrible hack, but pthread_self is not unique across processes, */
104108
/* and some OS don't expose any other unique id. */
105109
/* xor-fold pthread_self() pointer down to 16-bits */
106-
uint32_t tid;
110+
uint32_t tid_unsigned;
107111
uint64_t pself = (uint64_t)pthread_self();
108112
pself = pself ^ (pself >> 32);
109113
pself = pself ^ (pself >> 16);
110114
/* add in PID to help unique-ify */
111115
/* NOTE: tiger and later OSX have PID #s up to 10k. */
112116
tid = ((pself & 0xffff) << 16) + getpid();
113-
return tid;
117+
return (int32_t) tid_unsigned;
114118
#endif
115119
}
116120

src/lib/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ int mdbm_log_vlog_at (const char* file, int line, int level, const char* format,
157157

158158
gettimeofday(&tv, NULL);
159159
#ifdef __linux__
160-
pid = gettid();
160+
pid = mdbm_gettid();
161161
#else
162162
pid = getpid();
163163
#endif

src/lib/mdbm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8267,7 +8267,7 @@ open_tmp_test_file(const char *file, uint32_t siz, char *buf)
82678267
{
82688268
int created = 0, fd = -1;
82698269

8270-
snprintf(buf, MAXPATHLEN, "%s%d.map", file, gettid()); /* assuming buf is big enough */
8270+
snprintf(buf, MAXPATHLEN, "%s%d.map", file, mdbm_gettid()); /* assuming buf is big enough */
82718271

82728272
fd = open(buf, O_RDWR|O_NOATIME);
82738273
if (fd < 0) {

src/lib/mdbm_lock.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ do_lock_x(MDBM* db, int pageno, int nonblock, int check)
473473
int do_check = 0; /* If an integrity check needs to be done. */
474474
int upgraded = 0; /* If the lock was implicitly upgraded (prev EXCL owner died). */
475475
int part_num = -1;
476-
//fprintf(stderr, "@@@ do_lock_x pid:%d tid:%d, excl_nest:%d part_nest:%d part_count:%d pageno:%d\n", getpid(), gettid(), exclusive_nest, part_nest, part_count, pageno);
476+
//fprintf(stderr, "@@@ do_lock_x pid:%d tid:%d, excl_nest:%d part_nest:%d part_count:%d pageno:%d\n", getpid(), mdbm_gettid(), exclusive_nest, part_nest, part_count, pageno);
477477
/*fprintf(stderr, "do_lock_x, part_count:%d\n", part_count); */
478478
if (part_count > 1) { /* shared/indexed locking (vs single-lock) */
479479
if (pageno == MDBM_LOCK_EXCLUSIVE || pageno == MDBM_LOCK_SHARED) {
@@ -485,11 +485,11 @@ do_lock_x(MDBM* db, int pageno, int nonblock, int check)
485485

486486
if (pageno == MDBM_LOCK_EXCLUSIVE || exclusive_nest > 0) {
487487
if (!exclusive_nest && part_nest>0) {
488-
//fprintf(stderr, "@@@ do_lock_x-upgrade pid:%d tid:%d, \n", getpid(), gettid());
488+
//fprintf(stderr, "@@@ do_lock_x-upgrade pid:%d tid:%d, \n", getpid(), mdbm_gettid());
489489
/*NOTE("Upgrade(TRY)"); */
490490
TRY_OR_LOCK_TIMED_ERR(MLOCK_UPGRADE, part_num, "mlock_upgrade()");
491491
} else { /* exclusive lock already held, bump count */
492-
//fprintf(stderr, "@@@ do_lock_x-exclusive pid:%d tid:%d\n",getpid(), gettid());
492+
//fprintf(stderr, "@@@ do_lock_x-exclusive pid:%d tid:%d\n",getpid(), mdbm_gettid());
493493
/*NOTE("Lock(ASYNC) EXCLUSIVE"); */
494494
TRY_OR_LOCK_TIMED_ERR(MLOCK_EXCLUSIVE, part_num, "mlock_lock(exclusive)");
495495
if (1 == locks->getHeldCount(MLOCK_EXCLUSIVE, true)) {
@@ -505,27 +505,27 @@ do_lock_x(MDBM* db, int pageno, int nonblock, int check)
505505
exclusive_nest, part_nest, part_count);
506506
return -1;
507507
} else {
508-
/*fprintf(stderr, "@@@ do_lock_x-part pid:%d tid:%d, part_num:%d\n", getpid(), gettid(), part_num); */
508+
/*fprintf(stderr, "@@@ do_lock_x-part pid:%d tid:%d, part_num:%d\n", getpid(), mdbm_gettid(), part_num); */
509509
/* don't worry about blocking... should already be held... */
510510
locks->lock(MLOCK_INDEX, MLOCK_BLOCK, part_num, do_check, upgraded);
511511
}
512512
} else {
513513
if (pageno == MDBM_LOCK_SHARED) {
514514
/*NOTE("Lock(ASYNC) ANY SHARED"); */
515-
//fprintf(stderr, "@@@ do_lock_x-shared pid:%d tid:%d, \n", getpid(), gettid());
515+
//fprintf(stderr, "@@@ do_lock_x-shared pid:%d tid:%d, \n", getpid(), mdbm_gettid());
516516
TRY_OR_LOCK_TIMED_ERR(MLOCK_SHARED, MLOCK_ANY, "mlock_lock(shared)");
517517
} else {
518518
/*NOTE("Lock(ASYNC) PART"); */
519519
/*lock_error(db,"Lock(ASYNC) Part (page:%d part:%d)",pageno,part_num); */
520520
/*print_trace(); */
521-
/*fprintf(stderr, "@@@ do_lock_x-index pid:%d tid:%d part_num:%d, \n", getpid(), gettid(), part_num); */
521+
/*fprintf(stderr, "@@@ do_lock_x-index pid:%d tid:%d part_num:%d, \n", getpid(), mdbm_gettid(), part_num); */
522522
TRY_OR_LOCK_TIMED_ERR(MLOCK_INDEX, part_num, "mlock_lock(index)");
523523
}
524524
prot = 1;
525525
}
526526
} else { /* Single lock (not partitioned/shared) */
527527
/*NOTE("Lock(ASYNC) SINGLE"); */
528-
//fprintf(stderr, "@@@ do_lock_x-single pid:%d tid:%d, \n", getpid(), gettid());
528+
//fprintf(stderr, "@@@ do_lock_x-single pid:%d tid:%d, \n", getpid(), mdbm_gettid());
529529
TRY_OR_LOCK_TIMED_ERR(MLOCK_EXCLUSIVE, part_num, "mlock_lock(single)");
530530
if (locks->getHeldCount(MLOCK_EXCLUSIVE, true) == 1) {
531531
prot = 1;
@@ -777,7 +777,7 @@ do_unlock_x(MDBM* db)
777777
int exclusive_nest = locks->getHeldCount(MLOCK_EXCLUSIVE, true);
778778
int part_nest = locks->getHeldCount(MLOCK_INDEX, true);
779779
int share_nest = locks->getHeldCount(MLOCK_SHARED, true);
780-
//fprintf(stderr, "@@@ do_unlock_x pid:%d tid:%d, excl_nest:%d part_nest:%d share_nest:%d\n", getpid(), gettid(), exclusive_nest, part_nest, share_nest);
780+
//fprintf(stderr, "@@@ do_unlock_x pid:%d tid:%d, excl_nest:%d part_nest:%d share_nest:%d\n", getpid(), mdbm_gettid(), exclusive_nest, part_nest, share_nest);
781781
if (exclusive_nest > 0) {
782782
/* exclusive lock is held... release it */
783783
if (locks->unlock(MLOCK_EXCLUSIVE) < 0) {

src/lib/multi_lock.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class TlsData {
9393
TlsEntry *te = (TlsEntry*)pthread_getspecific(key_);
9494
if (!te) {
9595
te = new TlsEntry;
96-
te->tid = gettid();
96+
te->tid = mdbm_gettid();
9797
//fprintf(stderr, "TlsData tid:%llu \n", tid);
9898
install_atfork();
9999
pthread_setspecific(key_, (void*)te);
@@ -301,7 +301,7 @@ inline int PMutex::Lock(bool blocking, owner_t tid) {
301301
// PRINT_LOCK_TRACE(blocking?"TRY Lock(BLOCK)":"TRY Lock(ASYNC)");
302302
//#endif
303303
// CHECKPOINTV(" Lock(%s) any:%u owner:" OWNER_FMT " %p", blocking?"BLOCK":"ASYNC", rec->count, rec->owner, rec);
304-
//uint32_t tid = gettid();
304+
//int32_t tid = mdbm_gettid();
305305
//owner_t tid = get_thread_id();
306306
int ret = -1;
307307
if (tid == rec->owner) {
@@ -357,7 +357,7 @@ inline int PMutex::Lock(bool blocking, owner_t tid) {
357357

358358
inline int PMutex::Unlock(owner_t tid) {
359359
AUTO_TSC("PMutex::Unlock()");
360-
//uint32_t tid = gettid();
360+
//int32_t tid = mdbm_gettid();
361361
//owner_t tid = get_thread_id();
362362
//#ifdef TRACE_LOCKS
363363
// PRINT_LOCK_TRACE("TRY Unlock()");
@@ -1507,7 +1507,7 @@ void MLock::DumpLockState(FILE* file) {
15071507
if (!file) {
15081508
file = stderr;
15091509
}
1510-
fprintf(file, "Begin Lock state (for non-zero locks) (pid:%d, tid:%d self:%llx uuid:" OWNER_FMT " ):\n", getpid(), gettid(), (long long unsigned)pthread_self(), get_thread_id());
1510+
fprintf(file, "Begin Lock state (for non-zero locks) (pid:%d, tid:%d self:%llx uuid:" OWNER_FMT " ):\n", getpid(), mdbm_gettid(), (long long unsigned)pthread_self(), get_thread_id());
15111511
fprintf(file, " BaseLocks:%d Core:%d Shared/Partitioned:%d mode:%s (%d)\n", base, 1, parts, MLockTypeToStr(GetLockType()), GetLockType());
15121512
for (int i=0; i<base; ++i) {
15131513
local = locks.locks[i]->GetLocalCount();

src/test/unit-test/test_lockbase.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ LockBaseTestSuite::parChildLockPartitions(CommonParams &params, const string &db
964964
<< " child locker got ret="<<ret<< " expected=" << params.expectedRet()
965965
<< " dbName=" << dbName
966966
<< " pid=" << getpid()
967-
<< " tid=" << gettid()
967+
<< " tid=" << mdbm_gettid()
968968
<< endl << flush;
969969

970970
if (ret == params.expectedRet()) {

src/test/unit-test/test_lockv3.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,7 +2228,7 @@ void* LockV3TestSuite::LockV3TestSuite::thrdIterates(void *arg)
22282228

22292229
// iterate the DB - when done send an ACK to the parent
22302230
MDBM_ITER iter;
2231-
//fprintf(stderr, "@@@ === child pid:%d tid:%d about to iterate\n", getpid(), gettid());
2231+
//fprintf(stderr, "@@@ === child pid:%d tid:%d about to iterate\n", getpid(), mdbm_gettid());
22322232
//mdbm_lock_dump(params->dbh());
22332233
datum key = mdbm_firstkey_r(params->dbh(), &iter);
22342234
while (key.dsize != 0) {
@@ -2281,7 +2281,7 @@ LockV3TestSuite::thrdLockAndChildIterates(CommonParams &parParams, int childOpen
22812281
CPPUNIT_ASSERT_MESSAGE(errMsg.insert(0, prefix), (ret == parParams.expectedRet()));
22822282
}
22832283

2284-
//fprintf(stderr, "@@@ === parent pid:%d tid:%d about to tell child to iterate\n", getpid(), gettid());
2284+
//fprintf(stderr, "@@@ === parent pid:%d tid:%d about to tell child to iterate\n", getpid(), mdbm_gettid());
22852285
//mdbm_lock_dump(dbh);
22862286
// tell child to iterate
22872287
parSendFD.sendMsg(_Continue);

src/test/unit-test/test_other.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ void MdbmUnitTestOther::testMLock() {
11881188
// MDBM* db = (MDBM*)mdbm;
11891189
// struct mdbm_locks *db_locks = db->db_locks;
11901190
// mlock_t* locks = db_locks->db_mlocks;
1191-
// uint32_t tid = gettid();
1191+
// int32_t tid = mdbm_gettid();
11921192

11931193
CPPUNIT_ASSERT(0 == db_part_owned(mdbm));
11941194
CPPUNIT_ASSERT(0 == db_multi_part_locked(mdbm));

0 commit comments

Comments
 (0)