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 <pthread.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
|
#include <signal.h>
|
||||||
#if TD_FREEBSD || TD_OPENBSD || TD_NETBSD
|
#if TD_FREEBSD || TD_OPENBSD || TD_NETBSD
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#endif
|
#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 *),
|
int ThreadPthread::do_pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *),
|
||||||
void *arg) {
|
void *arg) {
|
||||||
return pthread_create(thread, attr, start_routine, arg);
|
return pthread_create(thread, attr, start_routine, arg);
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
class ThreadPthread {
|
class ThreadPthread {
|
||||||
public:
|
public:
|
||||||
ThreadPthread() = default;
|
ThreadPthread() = default;
|
||||||
@ -63,6 +64,8 @@ class ThreadPthread {
|
|||||||
|
|
||||||
using id = pthread_t;
|
using id = pthread_t;
|
||||||
|
|
||||||
|
static void send_real_time_signal(id thread_id, int real_time_signal_number);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MovableValue<bool> is_inited_;
|
MovableValue<bool> is_inited_;
|
||||||
pthread_t thread_;
|
pthread_t thread_;
|
||||||
@ -85,6 +88,7 @@ class ThreadPthread {
|
|||||||
namespace this_thread_pthread {
|
namespace this_thread_pthread {
|
||||||
ThreadPthread::id get_id();
|
ThreadPthread::id get_id();
|
||||||
} // namespace this_thread_pthread
|
} // namespace this_thread_pthread
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
class ThreadStl {
|
class ThreadStl {
|
||||||
public:
|
public:
|
||||||
ThreadStl() = default;
|
ThreadStl() = default;
|
||||||
@ -33,6 +34,7 @@ class ThreadStl {
|
|||||||
~ThreadStl() {
|
~ThreadStl() {
|
||||||
join();
|
join();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Function, class... Args>
|
template <class Function, class... Args>
|
||||||
explicit ThreadStl(Function &&f, Args &&...args) {
|
explicit ThreadStl(Function &&f, Args &&...args) {
|
||||||
thread_ = std::thread([args = std::make_tuple(decay_copy(std::forward<Function>(f)),
|
thread_ = std::thread([args = std::make_tuple(decay_copy(std::forward<Function>(f)),
|
||||||
@ -48,12 +50,15 @@ class ThreadStl {
|
|||||||
thread_.join();
|
thread_.join();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void detach() {
|
void detach() {
|
||||||
if (thread_.joinable()) {
|
if (thread_.joinable()) {
|
||||||
thread_.detach();
|
thread_.detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_name(CSlice name) {
|
void set_name(CSlice name) {
|
||||||
|
// not supported
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned hardware_concurrency() {
|
static unsigned hardware_concurrency() {
|
||||||
@ -62,6 +67,10 @@ class ThreadStl {
|
|||||||
|
|
||||||
using id = std::thread::id;
|
using id = std::thread::id;
|
||||||
|
|
||||||
|
static void send_real_time_signal(id thread_id, int real_time_signal_number) {
|
||||||
|
// not supported
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::thread thread_;
|
std::thread thread_;
|
||||||
|
|
||||||
@ -70,9 +79,11 @@ class ThreadStl {
|
|||||||
return std::forward<T>(v);
|
return std::forward<T>(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace this_thread_stl {
|
namespace this_thread_stl {
|
||||||
using std::this_thread::get_id;
|
using std::this_thread::get_id;
|
||||||
} // namespace this_thread_stl
|
} // namespace this_thread_stl
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user