- avoid dependency on resip/rutil library

This commit is contained in:
Dmytro Bogovych 2018-08-13 11:32:38 +03:00
parent 5b3c57b750
commit 018ddf81df
2 changed files with 19 additions and 22 deletions

View File

@ -44,23 +44,20 @@ SocketHeap::~SocketHeap()
void SocketHeap::start() void SocketHeap::start()
{ {
#if defined(USE_RESIP_INTEGRATION) if (!mWorkerThread)
if (!mId) mWorkerThread = std::make_shared<std::thread>(&SocketHeap::thread, this);
run();
#else
#endif
} }
void SocketHeap::stop() void SocketHeap::stop()
{ {
#if defined(USE_RESIP_INTEGRATION) if (mWorkerThread)
if (mId)
{ {
shutdown(); mShutdown = true;
// Wait for worker thread if (mWorkerThread->joinable())
join(); mWorkerThread->join();
mWorkerThread.reset();
} }
#endif
} }
void SocketHeap::setRange(unsigned short start, unsigned short finish) void SocketHeap::setRange(unsigned short start, unsigned short finish)
@ -222,7 +219,7 @@ void SocketHeap::thread()
/*#ifdef __linux__ /*#ifdef __linux__
// TODO: make epoll implementation for massive polling // TODO: make epoll implementation for massive polling
#else*/ #else*/
mId = ThreadIf::selfId(); mThreadId = std::this_thread::get_id();
while (!isShutdown()) while (!isShutdown())
{ {
@ -288,7 +285,7 @@ void SocketHeap::thread()
else else
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
mId = 0;
mShutdown = false; mShutdown = false;
//#endif //#endif
} }

View File

@ -29,11 +29,7 @@ public:
}; };
// Class allocates new UDP sockets and tracks incoming packets on them. It runs in separate thread // Class allocates new UDP sockets and tracks incoming packets on them. It runs in separate thread
#ifdef USE_RESIP_INTEGRATION class SocketHeap
class SocketHeap: public resip::ThreadIf
#else
class SocketHeap: public std::thread
#endif
{ {
public: public:
enum Multiplex enum Multiplex
@ -43,7 +39,7 @@ public:
}; };
SocketHeap(unsigned short start, unsigned short finish); SocketHeap(unsigned short start, unsigned short finish);
~SocketHeap(); virtual ~SocketHeap();
static SocketHeap& instance(); static SocketHeap& instance();
@ -104,9 +100,13 @@ protected:
char mTempPacket[MAX_UDPPACKET_SIZE]; char mTempPacket[MAX_UDPPACKET_SIZE];
int mId = 0; std::shared_ptr<std::thread> mWorkerThread;
//bool isShutdown() const { return mShutdown; }
virtual void thread(); std::thread::id mThreadId;
bool mShutdown = false;
bool isShutdown() const { return mShutdown; }
void thread();
// Processes mDeleteVector -> updates mSocketMap, removes socket items and closes sockets specified in mDeleteVector // Processes mDeleteVector -> updates mSocketMap, removes socket items and closes sockets specified in mDeleteVector
void processDeleted(); void processDeleted();