Skip to content

Commit ba4c971

Browse files
committed
issue #3996: impl gettid for macOS & cygwin64.
1 parent 954b1b7 commit ba4c971

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

trunk/configure

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ if [[ $SRS_UTEST == YES ]]; then
464464
MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_kernel" "srs_utest_core"
465465
"srs_utest_config" "srs_utest_rtmp" "srs_utest_http" "srs_utest_avc" "srs_utest_reload"
466466
"srs_utest_mp4" "srs_utest_service" "srs_utest_app" "srs_utest_rtc" "srs_utest_config2"
467-
"srs_utest_protocol" "srs_utest_protocol2" "srs_utest_kernel2")
467+
"srs_utest_protocol" "srs_utest_protocol2" "srs_utest_kernel2" "srs_utest_thread_pool")
468468
if [[ $SRS_SRT == YES ]]; then
469469
MODULE_FILES+=("srs_utest_srt")
470470
fi

trunk/src/app/srs_app_threads.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,14 @@ using namespace std;
3636
#include <unistd.h>
3737
#include <fcntl.h>
3838

39-
#if defined(SRS_OSX) || defined(SRS_CYGWIN64)
39+
#if defined(SRS_OSX)
4040
pid_t gettid() {
41-
return 0;
41+
uint64_t tid;
42+
return pthread_threadid_np(NULL, &tid) ? 0 : tid;
43+
}
44+
#elif defined(SRS_CYGWIN64)
45+
pid_t gettid() {
46+
return pthread_getsequence_np(pthread_self());
4247
}
4348
#else
4449
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// Copyright (c) 2013-2024 The SRS Authors
3+
//
4+
// SPDX-License-Identifier: MIT
5+
//
6+
#include <srs_utest_thread_pool.hpp>
7+
#include <pthread.h>
8+
9+
static srs_error_t dummy_loop(void*) {
10+
return srs_success;
11+
}
12+
13+
14+
VOID TEST(ThreadPoolTest, tid) {
15+
SrsThreadPool* thread_pool_1 = new SrsThreadPool();
16+
SrsThreadPool* thread_pool_2 = new SrsThreadPool();
17+
18+
EXPECT_TRUE(thread_pool_1->execute("hybrid", dummy_loop, (void*)NULL) == srs_success);
19+
EXPECT_TRUE(thread_pool_2->execute("hybrid", dummy_loop, (void*)NULL) == srs_success);
20+
usleep(100);
21+
22+
EXPECT_GT(thread_pool_1->hybrid()->tid, 0);
23+
EXPECT_GT(thread_pool_2->hybrid()->tid, 0);
24+
25+
EXPECT_NE(thread_pool_1->hybrid()->tid, thread_pool_2->hybrid()->tid);
26+
27+
srs_freep(thread_pool_1);
28+
srs_freep(thread_pool_2);
29+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// Copyright (c) 2013-2024 The SRS Authors
3+
//
4+
// SPDX-License-Identifier: MIT
5+
//
6+
7+
#ifndef SRS_UTEST_THREAD_POOL
8+
#define SRS_UTEST_THREAD_POOL
9+
10+
#include <srs_utest.hpp>
11+
12+
#include <srs_app_threads.hpp>
13+
14+
#endif // SRS_UTEST_THREAD_POOL
15+

0 commit comments

Comments
 (0)