Skip to content

Commit

Permalink
sync upstream cppmyth (2.9.6)
Browse files Browse the repository at this point in the history
  • Loading branch information
janbar committed Nov 13, 2017
1 parent 376cdb0 commit 5e3e854
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/cppmyth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ endif ()

###############################################################################
# set lib version here
set (CPPMYTH_LIB_VERSION "2.9.5")
set (CPPMYTH_LIB_VERSION "2.9.6")
set (CPPMYTH_LIB_SOVERSION "2")

###############################################################################
Expand Down
36 changes: 28 additions & 8 deletions lib/cppmyth/src/private/os/threads/threadpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ CThreadPool::~CThreadPool()
for (std::set<CWorkerThread*>::iterator it = m_pool.begin(); it != m_pool.end(); ++it)
(*it)->StopThread(false);
// Wake sleeper
m_queueContent.Broadcast();
m_queueFill.Broadcast();
// Waiting all finalized
m_condition.Wait(m_mutex, m_empty);
}
Expand All @@ -91,7 +91,7 @@ bool CThreadPool::Enqueue(CWorker* worker)
if (m_waitingCount)
{
// Wake a thread
m_queueContent.Signal();
m_queueFill.Signal();
return true;
}
else
Expand Down Expand Up @@ -132,6 +132,22 @@ unsigned CThreadPool::QueueSize() const
return static_cast<unsigned>(m_queue.size());
}

bool CThreadPool::IsQueueEmpty() const
{
CLockGuard lock(m_mutex);
return m_queue.empty();
}

bool CThreadPool::waitEmpty(unsigned millisec)
{
return IsQueueEmpty() || m_queueEmpty.Wait(millisec);
}

bool CThreadPool::waitEmpty()
{
return IsQueueEmpty() || m_queueEmpty.Wait();
}

void CThreadPool::Suspend()
{
CLockGuard lock(m_mutex);
Expand Down Expand Up @@ -185,11 +201,15 @@ CWorker* CThreadPool::PopQueue(CWorkerThread* _thread)
{
(void)_thread;
CLockGuard lock(m_mutex);
if (!m_suspended && !m_queue.empty())
if (!m_suspended)
{
CWorker* worker = m_queue.front();
m_queue.pop();
return worker;
m_queueEmpty.Signal();
if (!m_queue.empty())
{
CWorker* worker = m_queue.front();
m_queue.pop();
return worker;
}
}
return NULL;
}
Expand All @@ -201,7 +221,7 @@ void CThreadPool::WaitQueue(CWorkerThread* _thread)
++m_waitingCount;
unsigned millisec = m_keepAlive;
lock.Unlock();
m_queueContent.Wait(millisec);
m_queueFill.Wait(millisec);
lock.Lock();
--m_waitingCount;
}
Expand Down Expand Up @@ -254,6 +274,6 @@ void CThreadPool::__resize()
}
// Wake up the waiting threads to stop
if (m_waitingCount)
m_queueContent.Broadcast();
m_queueFill.Broadcast();
}
}
6 changes: 5 additions & 1 deletion lib/cppmyth/src/private/os/threads/threadpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ namespace OS
unsigned Size() const;

unsigned QueueSize() const;
bool IsQueueEmpty() const;
bool waitEmpty(unsigned millisec);
bool waitEmpty();

void Suspend();
void Resume();
Expand All @@ -78,7 +81,8 @@ namespace OS
std::set<CWorkerThread*> m_pool;
mutable CMutex m_mutex;
CCondition<volatile bool> m_condition;
CEvent m_queueContent;
CEvent m_queueFill;
CEvent m_queueEmpty;

CWorker* PopQueue(CWorkerThread* _thread);
void WaitQueue(CWorkerThread* _thread);
Expand Down
2 changes: 1 addition & 1 deletion lib/cppmyth/src/private/sajson.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace sajson {
return text;
}

const size_t length() const {
size_t length() const {
return _length;
}

Expand Down

0 comments on commit 5e3e854

Please sign in to comment.