Skip to content

Commit bf949d5

Browse files
committed
fix other pthread_t arithmetic comparison
should use `pthread_equal(thread_id, PTHREAD_NULL)`, see the commit HEAD~3
1 parent b1ec27d commit bf949d5

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

src/audio/export.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@
4242
#include <unistd.h>
4343
#include <string.h> // for memcpy, strdup
4444

45+
#define WANT_PTHREAD_NULL
4546
#include "audio/types.h" // for audio_desc, audio_frame, AC_PCM
4647
#include "audio/utils.h"
4748
#include "audio/wav_writer.h"
49+
#include "compat/misc.h" // for PTHREAD_NULL
4850
#include "export.h"
4951
#include "utils/misc.h" // ug_strerror
5052
#include "utils/ring_buffer.h"
@@ -160,7 +162,7 @@ struct audio_export * audio_export_init(const char *filename)
160162

161163
unlink(filename);
162164
s->filename = strdup(filename);
163-
s->thread_id = 0;
165+
s->thread_id = PTHREAD_NULL;
164166
s->ring = NULL;
165167

166168
pthread_mutex_init(&s->lock, NULL);
@@ -179,7 +181,7 @@ void audio_export_destroy(struct audio_export *s)
179181
if (s == NULL) {
180182
return;
181183
}
182-
if (s->thread_id) {
184+
if (!pthread_equal(s->thread_id, PTHREAD_NULL)) {
183185
pthread_mutex_lock(&s->lock);
184186
s->should_exit_worker = true;
185187
s->new_work_ready = true;

src/compat/misc.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* in a separate file.
77
*/
88
/*
9-
* Copyright (c) 2021-2024 CESNET
9+
* Copyright (c) 2021-2025 CESNET, zájmové sdružení právnických osob
1010
* All rights reserved.
1111
*
1212
* Redistribution and use in source and binary forms, with or without
@@ -63,5 +63,12 @@
6363
#endif // !defined _WIN32
6464
#endif // defined WANT_FSEEKO
6565

66+
#ifdef WANT_PTHREAD_NULL
67+
#include <pthread.h>
68+
#ifndef PTHREAD_NULL // defined by POSIX v8
69+
#define PTHREAD_NULL ((pthread_t) { 0 })
70+
#endif
71+
#endif
72+
6673
#endif // defined COMPAT_MISC_H_20C709DB_F4A8_4744_A0A9_96036B277011
6774

src/video_capture/rtsp.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@
6262
#include <unistd.h> // for unlink
6363
#endif // defined _WIN32
6464

65+
#define WANT_PTHREAD_NULL
6566
#include "audio/types.h"
6667
#include "config.h" // for PACKAGE_BUGREPORT
6768
#include "compat/aligned_malloc.h" // for alignde_free, aligned_alloc
69+
#include "compat/misc.h" // for PTHREAD_NULL
6870
#include "compat/strings.h" // for strncasecmp
6971
#include "debug.h"
7072
#include "host.h"
@@ -604,6 +606,8 @@ vidcap_rtsp_init(struct vidcap_params *params, void **state) {
604606
if (s == NULL) {
605607
return VIDCAP_INIT_FAIL;
606608
}
609+
s->artsp_state.artsp_thread_id = PTHREAD_NULL;
610+
s->vrtsp_state.vrtsp_thread_id = PTHREAD_NULL;
607611

608612
//TODO now static codec assignment, to be dynamic as a function of supported codecs
609613
s->vrtsp_state.codec[0] = '\0';
@@ -1205,10 +1209,10 @@ vidcap_rtsp_done(void *state) {
12051209
pthread_cond_signal(&s->keepalive_cv);
12061210
pthread_cond_signal(&s->vrtsp_state.worker_cv);
12071211

1208-
if (s->vrtsp_state.vrtsp_thread_id) {
1212+
if (!pthread_equal(s->vrtsp_state.vrtsp_thread_id, PTHREAD_NULL)) {
12091213
pthread_join(s->vrtsp_state.vrtsp_thread_id, NULL);
12101214
}
1211-
if (s->keep_alive_rtsp_thread_id) {
1215+
if (!pthread_equal(s->keep_alive_rtsp_thread_id, PTHREAD_NULL)) {
12121216
pthread_join(s->keep_alive_rtsp_thread_id, NULL);
12131217
}
12141218

src/video_capture/screen_x11.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Martin Pulec <[email protected]>
44
*/
55
/*
6-
* Copyright (c) 2012-2023 CESNET, z.s.p.o.
6+
* Copyright (c) 2012-2025 CESNET, zájmové sdružení právnických osob
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -57,6 +57,8 @@
5757
#include <string.h> // for strchr, strstr, strcat, strdup
5858
#include <sys/time.h> // for gettimeofday, timeval
5959

60+
#define WANT_PTHREAD_NULL
61+
#include "compat/misc.h" // for PTHRAD_NLLL
6062
#include "debug.h"
6163
#include "host.h"
6264
#include "lib_common.h"
@@ -341,6 +343,7 @@ static int vidcap_screen_x11_init(struct vidcap_params *params, void **state)
341343
return VIDCAP_INIT_FAIL;
342344
}
343345
s->cpu_count = get_cpu_core_count();
346+
s->worker_id = PTHREAD_NULL;
344347

345348
#ifndef HAVE_XFIXES
346349
fprintf(stderr, "[Screen capture] Compiled without XFixes library, cursor won't be shown!\n");
@@ -376,7 +379,7 @@ static void vidcap_screen_x11_finish(void *state)
376379

377380
pthread_mutex_unlock(&s->lock);
378381

379-
if(s->worker_id) {
382+
if (!pthread_equal(s->worker_id, PTHREAD_NULL)) {
380383
pthread_join(s->worker_id, NULL);
381384
}
382385
}

src/video_capture/testcard2.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
# endif // defined HAVE_SDL3
6969
#endif
7070

71+
#define WANT_PTHREAD_NULL
7172
#include "audio/types.h" // for audio_frame
73+
#include "compat/misc.h" // for PTHREAD_NULL
7274
#include "compat/platform_semaphore.h" // for platform_sem_post, platform_s...
7375
#include "compat/usleep.h" // for usleep
7476
#include "debug.h" // for log_msg, LOG_LEVEL_ERROR, LOG...
@@ -106,11 +108,6 @@ enum {
106108
(struct video_desc){ 1920, 1080, UYVY, 24, PROGRESSIVE, 1 }
107109
#define MOD_NAME "[testcard2] "
108110

109-
// compat
110-
#ifndef PTHREAD_NULL // defined by POSIX v8
111-
#define PTHREAD_NULL ((pthread_t) { 0 })
112-
#endif
113-
114111
static void vidcap_testcard2_done(void *state);
115112
void * vidcap_testcard2_thread(void *args);
116113

0 commit comments

Comments
 (0)