Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #3996: impl gettid for macOS & cygwin64. #3997

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 13 additions & 1 deletion trunk/src/app/srs_app_threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ using namespace std;
#include <unistd.h>
#include <fcntl.h>

#if defined(SRS_OSX) || defined(SRS_CYGWIN64)
#if defined(SRS_OSX)
pid_t gettid() {
uint64_t tid;
return pthread_threadid_np(NULL, &tid) ? 0 : tid;
}
#elif defined(SRS_CYGWIN64)
pid_t gettid() {
return 0;
}
Expand Down Expand Up @@ -550,6 +555,12 @@ SrsThreadPool::~SrsThreadPool()
::close(pid_fd);
pid_fd = -1;
}

while(!threads_.empty()) {
SrsThreadEntry* entry = threads_.back();
srs_freep(entry);
threads_.pop_back();
}
}

// Setup the thread-local variables, MUST call when each thread starting.
Expand Down Expand Up @@ -799,6 +810,7 @@ void* SrsThreadPool::start(void* arg)
entry->err = srs_error_new(ERROR_THREAD_FINISHED, "finished normally");
}

srs_st_destroy();
// We do not use the return value, the err has been set to entry->err.
return NULL;
}
Expand Down
58 changes: 58 additions & 0 deletions trunk/src/utest/srs_utest_thread_pool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// 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;
}

#ifndef SRS_CYGWIN64

VOID TEST(ThreadPoolTest, tid) {
#if 0
srs_error_t err;
SrsThreadPool* thread_pool_1 = new SrsThreadPool();
SrsThreadPool* thread_pool_2 = new SrsThreadPool();

EXPECT_TRUE((err = thread_pool_1->initialize()) == srs_success);
srs_freep(err);

EXPECT_TRUE((err = thread_pool_2->initialize()) == srs_success);
srs_freep(err);

EXPECT_TRUE((err = thread_pool_1->execute("hybrid", dummy_loop, (void*)NULL)) == srs_success);
srs_freep(err);

EXPECT_TRUE((err = thread_pool_2->execute("hybrid", dummy_loop, (void*)NULL)) == srs_success);
srs_freep(err);

err = thread_pool_1->run();
srs_freep(err);
err = thread_pool_2->run();
srs_freep(err);

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);
#endif

srs_error_t err;
EXPECT_TRUE((err = _srs_thread_pool->initialize()) == srs_success);
srs_freep(err);

//EXPECT_TRUE((err = _srs_thread_pool->execute("hybrid", dummy_loop, (void*)NULL)) == srs_success);
//srs_freep(err);

//err = _srs_thread_pool->run();
srs_freep(err);
}

#endif
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

Loading