Add thread::send_real_time_signal.
This commit is contained in:
parent
959c7261c1
commit
28594d38e4
@ -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);
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user