Replaced older deprecated __sync calls for atomic ones.
Some checks failed
C build and Test / build (, macos-14, brew update && brew install ncurses gettext autoconf automake openssl@3 libmaxminddb jq) (push) Has been cancelled
C build and Test / build (, macos-latest, brew install ncurses gettext autoconf automake libmaxminddb openssl@3 jq) (push) Has been cancelled
C build and Test / build (, ubuntu-latest, sudo apt-get update && sudo apt-get install -y build-essential autoconf gettext autopoint libncursesw5-dev libssl-dev git libmaxminddb-dev jq) (push) Has been cancelled
C build and Test / build (--enable-debug, macos-14, brew update && brew install ncurses gettext autoconf automake openssl@3 libmaxminddb jq) (push) Has been cancelled
C build and Test / build (--enable-debug, macos-latest, brew install ncurses gettext autoconf automake libmaxminddb openssl@3 jq) (push) Has been cancelled
C build and Test / build (--enable-debug, ubuntu-latest, sudo apt-get update && sudo apt-get install -y build-essential autoconf gettext autopoint libncursesw5-dev libssl-dev git libmaxminddb-dev jq) (push) Has been cancelled
C build and Test / build (--enable-utf8 --enable-debug --with-getline, macos-14, brew update && brew install ncurses gettext autoconf automake openssl@3 libmaxminddb jq) (push) Has been cancelled
C build and Test / build (--enable-utf8 --enable-debug --with-getline, macos-latest, brew install ncurses gettext autoconf automake libmaxminddb openssl@3 jq) (push) Has been cancelled
C build and Test / build (--enable-utf8 --enable-debug --with-getline, ubuntu-latest, sudo apt-get update && sudo apt-get install -y build-essential autoconf gettext autopoint libncursesw5-dev libssl-dev git libmaxminddb-dev jq) (push) Has been cancelled
C build and Test / build (--enable-utf8 --with-getline --enable-asan, macos-14, brew update && brew install ncurses gettext autoconf automake openssl@3 libmaxminddb jq) (push) Has been cancelled
C build and Test / build (--enable-utf8 --with-getline --enable-asan, macos-latest, brew install ncurses gettext autoconf automake libmaxminddb openssl@3 jq) (push) Has been cancelled
C build and Test / build (--enable-utf8 --with-getline --enable-asan, ubuntu-latest, sudo apt-get update && sudo apt-get install -y build-essential autoconf gettext autopoint libncursesw5-dev libssl-dev git libmaxminddb-dev jq) (push) Has been cancelled
C build and Test / build (--with-getline --enable-asan, macos-14, brew update && brew install ncurses gettext autoconf automake openssl@3 libmaxminddb jq) (push) Has been cancelled
C build and Test / build (--with-getline --enable-asan, macos-latest, brew install ncurses gettext autoconf automake libmaxminddb openssl@3 jq) (push) Has been cancelled
C build and Test / build (--with-getline --enable-asan, ubuntu-latest, sudo apt-get update && sudo apt-get install -y build-essential autoconf gettext autopoint libncursesw5-dev libssl-dev git libmaxminddb-dev jq) (push) Has been cancelled
Docker / test (push) Has been cancelled
Docker / push (push) Has been cancelled
Semgrep / Scan (push) Has been cancelled

Should address #2836 and help compile in gcc 14 and ppc.
This commit is contained in:
Gerardo O 2025-05-28 17:18:41 -05:00
parent b089631dae
commit 11ac167c94
3 changed files with 45 additions and 17 deletions

View File

@ -1017,7 +1017,7 @@ inc_ii32 (khash_t (ii32) *hash, uint32_t key, uint32_t inc) {
kh_val (hash, k) = 0;
}
return __sync_add_and_fetch (&kh_val (hash, k), inc);
return __atomic_add_fetch (&kh_val (hash, k), inc, __ATOMIC_SEQ_CST);
}
/* Increase a uint64_t value given a string key.
@ -1110,7 +1110,7 @@ inc_si32 (khash_t (si32) *hash, const char *key, uint32_t inc) {
kh_val (hash, k) = 0;
}
return __sync_add_and_fetch (&kh_val (hash, k), inc);
return __atomic_add_fetch (&kh_val (hash, k), inc, __ATOMIC_SEQ_CST);
}
/* Insert a string key and auto increment int value.
@ -1202,7 +1202,7 @@ get_si32 (khash_t (si32) *hash, const char *key) {
k = kh_get (si32, hash, key);
/* key found, return current value */
if (k != kh_end (hash))
return __sync_add_and_fetch (&kh_val (hash, k), 0);
return __atomic_load_n (&kh_val (hash, k), __ATOMIC_SEQ_CST);
return 0;
}
@ -1300,7 +1300,7 @@ get_ii32 (khash_t (ii32) *hash, uint32_t key) {
k = kh_get (ii32, hash, key);
/* key found, return current value */
if (k != kh_end (hash))
return __sync_add_and_fetch (&kh_val (hash, k), 0);
return __atomic_load_n (&kh_val (hash, k), __ATOMIC_SEQ_CST);
return 0;
}

View File

@ -610,7 +610,7 @@ count_valid (int numdate) {
/* Keep track of all valid and processed log strings. */
void
count_process (GLog *glog) {
__sync_add_and_fetch (&glog->processed, 1);
__atomic_add_fetch (&glog->processed, 1, __ATOMIC_SEQ_CST);
lock_spinner ();
ht_inc_cnt_overall ("total_requests", 1);
unlock_spinner ();

View File

@ -1195,7 +1195,11 @@ parse_specifier (GLogItem *logitem, const char **str, const char *p, const char
if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE)
bandw = 0;
logitem->resp_size = bandw;
__sync_bool_compare_and_swap (&conf.bandwidth, 0, 1); /* set flag */
{
int expected = 0;
__atomic_compare_exchange_n (&conf.bandwidth, &expected, 1, false, __ATOMIC_SEQ_CST,
__ATOMIC_SEQ_CST);
}
free (tkn);
break;
/* referrer */
@ -1264,7 +1268,12 @@ parse_specifier (GLogItem *logitem, const char **str, const char *p, const char
logitem->serve_time = (serve_secs > 0) ? serve_secs * MILS : 0;
/* Determine if time-served data was stored on-disk. */
__sync_bool_compare_and_swap (&conf.serve_usecs, 0, 1); /* set flag */
{
int expected = 0;
__atomic_compare_exchange_n (&conf.serve_usecs, &expected, 1, false, __ATOMIC_SEQ_CST,
__ATOMIC_SEQ_CST);
}
free (tkn);
break;
/* time taken to serve the request, in seconds with a milliseconds
@ -1287,7 +1296,11 @@ parse_specifier (GLogItem *logitem, const char **str, const char *p, const char
logitem->serve_time = (serve_secs > 0) ? serve_secs * SECS : 0;
/* Determine if time-served data was stored on-disk. */
__sync_bool_compare_and_swap (&conf.serve_usecs, 0, 1); /* set flag */
{
int expected = 0;
__atomic_compare_exchange_n (&conf.serve_usecs, &expected, 1, false, __ATOMIC_SEQ_CST,
__ATOMIC_SEQ_CST);
}
free (tkn);
break;
/* time taken to serve the request, in microseconds */
@ -1304,7 +1317,11 @@ parse_specifier (GLogItem *logitem, const char **str, const char *p, const char
logitem->serve_time = serve_time;
/* Determine if time-served data was stored on-disk. */
__sync_bool_compare_and_swap (&conf.serve_usecs, 0, 1); /* set flag */
{
int expected = 0;
__atomic_compare_exchange_n (&conf.serve_usecs, &expected, 1, false, __ATOMIC_SEQ_CST,
__ATOMIC_SEQ_CST);
}
free (tkn);
break;
/* time taken to serve the request, in nanoseconds */
@ -1323,7 +1340,11 @@ parse_specifier (GLogItem *logitem, const char **str, const char *p, const char
logitem->serve_time = (serve_time > 0) ? serve_time / MILS : 0;
/* Determine if time-served data was stored on-disk. */
__sync_bool_compare_and_swap (&conf.serve_usecs, 0, 1); /* set flag */
{
int expected = 0;
__atomic_compare_exchange_n (&conf.serve_usecs, &expected, 1, false, __ATOMIC_SEQ_CST,
__ATOMIC_SEQ_CST);
}
free (tkn);
break;
/* UMS: Krypto (TLS) "ECDHE-RSA-AES128-GCM-SHA256" */
@ -1932,14 +1953,21 @@ parse_json_format (GLogItem *logitem, char *str) {
*/
static int
atomic_lpts_update (GLog *glog, GLogItem *logitem) {
int64_t oldts = 0, newts = 0;
/* atomic update loop */
newts = mktime (&logitem->dt); // Get timestamp from logitem->dt
while (!__sync_bool_compare_and_swap (&glog->lp.ts, oldts, newts)) {
oldts = glog->lp.ts; /* Reread glog->lp.ts if CAS failed */
if (oldts >= newts) {
break; /* No need to update if oldts is already greater */
int64_t newts = mktime (&logitem->dt); // Get timestamp from logitem->dt
int64_t oldts = __atomic_load_n (&glog->lp.ts, __ATOMIC_SEQ_CST);
int64_t expected;
while (oldts < newts) { // Only update if new timestamp is later
expected = oldts;
// Attempt to update glog->lp.ts from expected (oldts) to newts.
if (__atomic_compare_exchange_n (&glog->lp.ts, &expected, newts,
false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
break; // Successful update.
}
// If the CAS failed, expected now holds the current glog->lp.ts.
oldts = expected;
if (oldts >= newts)
break;
}
return newts;