Skip to content

Commit

Permalink
(#4): Remove network thread, set a dedicated thread under Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
aisouard committed Mar 28, 2017
1 parent 13b3172 commit cb8cae8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
26 changes: 12 additions & 14 deletions src/globals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

#include <nan.h>

#if WEBRTC_WIN
#ifdef WIN32
#include <webrtc/base/win32socketinit.h>
#include <webrtc/base/win32socketserver.h>
#include <Windows.h>
#endif

#include <webrtc/base/ssladapter.h>
#include <iostream>
#include "globals.h"

EventQueue *Globals::_eventQueue = NULL;
rtc::Thread *Globals::_networkThread = NULL;
rtc::Thread *Globals::_signalingThread = NULL;
rtc::Thread *Globals::_workerThread = NULL;
rtc::RTCCertificateGenerator *Globals::_certificateGenerator = NULL;
Expand All @@ -38,31 +38,30 @@ bool Globals::Init() {

#if WEBRTC_WIN
rtc::EnsureWinsockInit();
rtc::Win32Thread w32_thread;
rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread);
#endif

rtc::InitializeSSL();
rtc::InitRandom(rtc::Time());

_networkThread = new rtc::Thread();
_signalingThread = new rtc::Thread();
_workerThread = new rtc::Thread();

_networkThread->SetName("network_thread", NULL);
_signalingThread->SetName("signaling_thread", NULL);
_workerThread->SetName("worker_thread", NULL);

if (!_signalingThread->Start() ||
!_workerThread->Start() ||
!_networkThread->Start()) {
!_workerThread->Start()) {
return false;
}

_certificateGenerator =
new rtc::RTCCertificateGenerator(_signalingThread, _workerThread);

_peerConnectionFactory =
webrtc::CreatePeerConnectionFactory(_networkThread, _workerThread,
_signalingThread, NULL, NULL, NULL);
webrtc::CreatePeerConnectionFactory(_workerThread, _signalingThread,
NULL, NULL, NULL);
return true;
}

Expand All @@ -71,16 +70,13 @@ void Globals::Cleanup(void* args) {

delete _certificateGenerator;

_signalingThread->SetAllowBlockingCalls(true);
_signalingThread->Stop();

_workerThread->SetAllowBlockingCalls(true);
_workerThread->Stop();

if (rtc::ThreadManager::Instance()->CurrentThread() == _signalingThread) {
rtc::ThreadManager::Instance()->SetCurrentThread(NULL);
}

_signalingThread->Stop();
_workerThread->Stop();

delete _signalingThread;
delete _workerThread;

Expand All @@ -90,6 +86,8 @@ void Globals::Cleanup(void* args) {
rtc::CleanupSSL();

delete _eventQueue;

_eventQueue = NULL;
}

EventQueue *Globals::GetEventQueue() {
Expand Down
1 change: 0 additions & 1 deletion src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class Globals {

private:
static EventQueue *_eventQueue;
static rtc::Thread *_networkThread;
static rtc::Thread *_signalingThread;
static rtc::Thread *_workerThread;
static rtc::RTCCertificateGenerator *_certificateGenerator;
Expand Down

0 comments on commit cb8cae8

Please sign in to comment.