@cryptotaxi247 / netdata / commits / ec8255911

Change remaining pthread_ cases (#20746)

* Change a few more pthread_mutex_t, pthread_cond_t * One more

Stelios Fragkakis committed Jul 31, 2025 at 16:25 UTC ec8255911bc17bd71ab6bec1dcda3490230406d1
3 files changed +20 -20
src/collectors/ebpf.plugin/ebpf.h
+1 -1
@@ -309,7 +309,7 @@ extern struct config collector_config;
309 extern netdata_ebpf_cgroup_shm_t shm_ebpf_cgroup;
310 extern int shm_fd_ebpf_cgroup;
311 extern sem_t *shm_sem_ebpf_cgroup;
312 -extern pthread_mutex_t mutex_cgroup_shm;
312 +extern netdata_mutex_t mutex_cgroup_shm;
313 extern size_t ebpf_all_pids_count;
314 extern ebpf_plugin_stats_t plugin_statistics;
315 #ifdef LIBBPF_MAJOR_VERSION
src/libnetdata/functions_evloop/functions_evloop.h
+1 -1
@@ -153,7 +153,7 @@ static inline void pluginsd_function_progress_to_stdout(const char *transaction,
153 fflush(stdout);
154 }
155
156 -static inline void send_newline_and_flush(pthread_mutex_t *mutex) {
156 +static inline void send_newline_and_flush(netdata_mutex_t *mutex) {
157 netdata_mutex_lock(mutex);
158 fprintf(stdout, "\n");
159 fflush(stdout);
src/libnetdata/locks/benchmark.c
+18 -18
@@ -19,7 +19,7 @@ typedef struct {
19 } thread_stats_t;
20
21 typedef struct {
22 - pthread_cond_t cond; // Individual condition for each thread
22 + netdata_cond_t cond; // Individual condition for each thread
23 netdata_mutex_t cond_mutex; // Individual mutex for each thread
24 uint64_t run_flag; // Individual run flag for each thread
25 } thread_control_t;
@@ -81,11 +81,11 @@ static void print_summary(const summary_stats_t *summary) {
81 fprintf(stderr, "\n");
82 }
83
84 -static void wait_for_signal(pthread_cond_t *cond, pthread_mutex_t *mutex, uint64_t *flag) {
85 - pthread_mutex_lock(mutex);
84 +static void wait_for_signal(netdata_cond_t *cond, netdata_mutex_t *mutex, uint64_t *flag) {
85 + netdata_mutex_lock(mutex);
86 while (*flag == 0)
87 - pthread_cond_wait(cond, mutex);
88 - pthread_mutex_unlock(mutex);
87 + netdata_cond_wait(cond, mutex);
88 + netdata_mutex_unlock(mutex);
89 }
90
91 static void benchmark_thread(void *arg) {
@@ -104,22 +104,22 @@ static void benchmark_thread(void *arg) {
104
105 switch(ctx->type) {
106 case LOCK_MUTEX: {
107 - pthread_mutex_t *mutex = ctx->lock;
107 + netdata_mutex_t *mutex = ctx->lock;
108 while (thread_control->run_flag) {
109 - pthread_mutex_lock(mutex);
109 + netdata_mutex_lock(mutex);
110 ctx->control->protected_counter++;
111 - pthread_mutex_unlock(mutex);
111 + netdata_mutex_unlock(mutex);
112 local_counter++;
113 }
114 break;
115 }
116
117 case LOCK_RWLOCK: {
118 - pthread_rwlock_t *rwlock = ctx->lock;
118 + netdata_rwlock_t *rwlock = ctx->lock;
119 while (thread_control->run_flag) {
120 - pthread_rwlock_wrlock(rwlock);
120 + netdata_rwlock_wrlock(rwlock);
121 ctx->control->protected_counter++;
122 - pthread_rwlock_unlock(rwlock);
122 + netdata_rwlock_wrunlock(rwlock);
123 local_counter++;
124 }
125 break;
@@ -241,10 +241,10 @@ static void run_test(const char *name, int threads, thread_context_t *contexts,
241 // Signal only the threads we need for this test
242 for(int i = 0; i < threads; i++) {
243 thread_control_t *thread_control = &control->thread_controls[i];
244 - pthread_mutex_lock(&thread_control->cond_mutex);
244 + netdata_mutex_lock(&thread_control->cond_mutex);
245 thread_control->run_flag = 1;
246 - pthread_cond_signal(&thread_control->cond);
247 - pthread_mutex_unlock(&thread_control->cond_mutex);
246 + netdata_cond_signal(&thread_control->cond);
247 + netdata_mutex_unlock(&thread_control->cond_mutex);
248 }
249
250 // Wait for test duration
@@ -341,8 +341,8 @@ int locks_stress_test(void) {
341 for(int i = 0; i < NUM_LOCK_TYPES; i++) {
342 // Initialize per-thread condition variables and mutexes
343 for(int j = 0; j < MAX_THREADS; j++) {
344 - pthread_cond_init(&controls[i].thread_controls[j].cond, NULL);
345 - pthread_mutex_init(&controls[i].thread_controls[j].cond_mutex, NULL);
344 + netdata_cond_init(&controls[i].thread_controls[j].cond);
345 + netdata_mutex_init(&controls[i].thread_controls[j].cond_mutex);
346 controls[i].thread_controls[j].run_flag = 0;
347 }
348 }
@@ -409,7 +409,7 @@ int locks_stress_test(void) {
409 thread_control_t *thread_control = &controls[type].thread_controls[i];
410 netdata_mutex_lock(&thread_control->cond_mutex);
411 thread_control->run_flag = STOP_SIGNAL;
412 - pthread_cond_signal(&thread_control->cond);
412 + netdata_cond_signal(&thread_control->cond);
413 netdata_mutex_unlock(&thread_control->cond_mutex);
414 }
415 }
@@ -425,7 +425,7 @@ int locks_stress_test(void) {
425 // Cleanup condition variables and mutexes
426 for(int type = 0; type < NUM_LOCK_TYPES; type++) {
427 for(int i = 0; i < MAX_THREADS; i++) {
428 - pthread_cond_destroy(&controls[type].thread_controls[i].cond);
428 + netdata_cond_destroy(&controls[type].thread_controls[i].cond);
429 netdata_mutex_destroy(&controls[type].thread_controls[i].cond_mutex);
430 }
431 free(threads[type]);