Add thread::send_real_time_signal.

This commit is contained in:
levlam 2022-08-22 00:46:22 +03:00
parent 959c7261c1
commit 28594d38e4
3 changed files with 22 additions and 0 deletions

View File

@ -14,6 +14,7 @@ char disable_linker_warning_about_empty_file_thread_pthread_cpp TD_UNUSED;
#include <pthread.h>
#include <sched.h>
#include <signal.h>
#if TD_FREEBSD || TD_OPENBSD || TD_NETBSD
#include <sys/sysctl.h>
#endif
@ -82,6 +83,12 @@ void ThreadPthread::detach() {
}
}
void ThreadPthread::send_real_time_signal(id thread_id, int real_time_signal_number) {
#ifdef SIGRTMIN
pthread_kill(thread_id, SIGRTMIN + real_time_signal_number);
#endif
}
int ThreadPthread::do_pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *),
void *arg) {
return pthread_create(thread, attr, start_routine, arg);

View File

@ -26,6 +26,7 @@
namespace td {
namespace detail {
class ThreadPthread {
public:
ThreadPthread() = default;
@ -63,6 +64,8 @@ class ThreadPthread {
using id = pthread_t;
static void send_real_time_signal(id thread_id, int real_time_signal_number);
private:
MovableValue<bool> is_inited_;
pthread_t thread_;
@ -85,6 +88,7 @@ class ThreadPthread {
namespace this_thread_pthread {
ThreadPthread::id get_id();
} // namespace this_thread_pthread
} // namespace detail
} // namespace td

View File

@ -23,6 +23,7 @@
namespace td {
namespace detail {
class ThreadStl {
public:
ThreadStl() = default;
@ -33,6 +34,7 @@ class ThreadStl {
~ThreadStl() {
join();
}
template <class Function, class... Args>
explicit ThreadStl(Function &&f, Args &&...args) {
thread_ = std::thread([args = std::make_tuple(decay_copy(std::forward<Function>(f)),
@ -48,12 +50,15 @@ class ThreadStl {
thread_.join();
}
}
void detach() {
if (thread_.joinable()) {
thread_.detach();
}
}
void set_name(CSlice name) {
// not supported
}
static unsigned hardware_concurrency() {
@ -62,6 +67,10 @@ class ThreadStl {
using id = std::thread::id;
static void send_real_time_signal(id thread_id, int real_time_signal_number) {
// not supported
}
private:
std::thread thread_;
@ -70,9 +79,11 @@ class ThreadStl {
return std::forward<T>(v);
}
};
namespace this_thread_stl {
using std::this_thread::get_id;
} // namespace this_thread_stl
} // namespace detail
} // namespace td