parent
8bea9f4455
commit
762eb9ca33
|
|
@ -167,7 +167,10 @@ endif (USE_AMR_CODEC)
|
|||
target_link_libraries(rtphone
|
||||
ice_stack jrtplib g729_codec gsm_codec
|
||||
gsmhr_codec g722_codec srtp resiprocate
|
||||
helper_lib audio_lib webrtc speexdsp
|
||||
helper_lib
|
||||
audio_lib
|
||||
webrtc
|
||||
speexdsp
|
||||
opus
|
||||
uuid
|
||||
${OPENSSL_SSL}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,11 @@ long SyncHelper::increment(long *value)
|
|||
void ThreadHelper::setName(const std::string &name)
|
||||
{
|
||||
#if defined(TARGET_LINUX)
|
||||
pthread_setname_np(pthread_self(), name.c_str());
|
||||
int retcode = pthread_setname_np(pthread_self(), name.c_str());
|
||||
if (retcode != 0)
|
||||
{
|
||||
std::cerr << "Failed to set Linux thread name" << std::endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,11 +11,12 @@
|
|||
#include <functional>
|
||||
#include <stdexcept>
|
||||
#include <optional>
|
||||
#include "HL_Sync.h"
|
||||
|
||||
class ThreadPool
|
||||
{
|
||||
public:
|
||||
ThreadPool(size_t);
|
||||
ThreadPool(size_t, const std::string&);
|
||||
template<class F, class... Args>
|
||||
auto enqueue(F&& f, Args&&... args)
|
||||
-> std::future<typename std::result_of<F(Args...)>::type>;
|
||||
|
|
@ -31,16 +32,18 @@ private:
|
|||
std::mutex queue_mutex;
|
||||
std::condition_variable condition;
|
||||
bool stop, pause;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
// the constructor just launches some amount of workers
|
||||
inline ThreadPool::ThreadPool(size_t threads)
|
||||
: stop(false), pause(false)
|
||||
inline ThreadPool::ThreadPool(size_t threads, const std::string& name)
|
||||
: stop(false), pause(false), name(name)
|
||||
{
|
||||
for(size_t i = 0;i<threads;++i)
|
||||
workers.emplace_back(
|
||||
[this]
|
||||
[this, i]
|
||||
{
|
||||
ThreadHelper::setName(this->name + std::to_string(i));
|
||||
for(;;)
|
||||
{
|
||||
std::function<void()> task; bool task_assigned = false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue