Skip to content

Commit

Permalink
issue #3996: impl gettid for macOS & cygwin64.
Browse files Browse the repository at this point in the history
  • Loading branch information
suzp1984 committed Mar 19, 2024
1 parent 954b1b7 commit ef63393
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion trunk/configure
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ if [[ $SRS_UTEST == YES ]]; then
MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_kernel" "srs_utest_core"
"srs_utest_config" "srs_utest_rtmp" "srs_utest_http" "srs_utest_avc" "srs_utest_reload"
"srs_utest_mp4" "srs_utest_service" "srs_utest_app" "srs_utest_rtc" "srs_utest_config2"
"srs_utest_protocol" "srs_utest_protocol2" "srs_utest_kernel2")
"srs_utest_protocol" "srs_utest_protocol2" "srs_utest_kernel2" "srs_utest_thread_pool")
if [[ $SRS_SRT == YES ]]; then
MODULE_FILES+=("srs_utest_srt")
fi
Expand Down
9 changes: 7 additions & 2 deletions trunk/src/app/srs_app_threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ using namespace std;
#include <unistd.h>
#include <fcntl.h>

#if defined(SRS_OSX) || defined(SRS_CYGWIN64)
#if defined(SRS_OSX)
pid_t gettid() {
return 0;
uint64_t tid;
return pthread_threadid_np(NULL, &tid) ? 0 : tid;
}
#elif defined(SRS_CYGWIN64)
pid_t gettid() {
return pthread_self();
}
#else
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
Expand Down
29 changes: 29 additions & 0 deletions trunk/src/utest/srs_utest_thread_pool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Copyright (c) 2013-2024 The SRS Authors
//
// SPDX-License-Identifier: MIT
//
#include <srs_utest_thread_pool.hpp>
#include <pthread.h>

static srs_error_t dummy_loop(void*) {
return srs_success;
}


VOID TEST(ThreadPoolTest, tid) {
SrsThreadPool* thread_pool_1 = new SrsThreadPool();
SrsThreadPool* thread_pool_2 = new SrsThreadPool();

EXPECT_TRUE(thread_pool_1->execute("hybrid", dummy_loop, (void*)NULL) == srs_success);
EXPECT_TRUE(thread_pool_2->execute("hybrid", dummy_loop, (void*)NULL) == srs_success);
usleep(100);

EXPECT_GT(thread_pool_1->hybrid()->tid, 0);
EXPECT_GT(thread_pool_2->hybrid()->tid, 0);

EXPECT_NE(thread_pool_1->hybrid()->tid, thread_pool_2->hybrid()->tid);

srs_freep(thread_pool_1);
srs_freep(thread_pool_2);
}
15 changes: 15 additions & 0 deletions trunk/src/utest/srs_utest_thread_pool.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Copyright (c) 2013-2024 The SRS Authors
//
// SPDX-License-Identifier: MIT
//

#ifndef SRS_UTEST_THREAD_POOL
#define SRS_UTEST_THREAD_POOL

#include <srs_utest.hpp>

#include <srs_app_threads.hpp>

#endif // SRS_UTEST_THREAD_POOL

0 comments on commit ef63393

Please sign in to comment.