changed buffered output stream to wait() when flush()ing instead

of polling/sleeping.  changed CTCPSocket to not use thread
cancellation but to instead use m_connected to exit the thread.
also shortened poll timeout.
This commit is contained in:
crs
2002-06-02 22:57:50 +00:00
parent 1e988b3839
commit ad15393732
3 changed files with 33 additions and 33 deletions

View File

@@ -13,6 +13,7 @@
CBufferedOutputStream::CBufferedOutputStream(CMutex* mutex, IJob* closeCB) :
m_mutex(mutex),
m_closeCB(closeCB),
m_empty(mutex, true),
m_closed(false)
{
assert(m_mutex != NULL);
@@ -31,6 +32,9 @@ const void* CBufferedOutputStream::peek(UInt32 n)
void CBufferedOutputStream::pop(UInt32 n)
{
m_buffer.pop(n);
if (m_buffer.getSize() == 0) {
m_empty.broadcast();
}
}
UInt32 CBufferedOutputStream::getSize() const
@@ -67,14 +71,8 @@ UInt32 CBufferedOutputStream::write(
void CBufferedOutputStream::flush()
{
// wait until all data is written
while (getSizeWithLock() > 0) {
CThread::sleep(0.05);
CLock lock(m_mutex);
while (m_buffer.getSize() > 0) {
m_empty.wait();
}
}
UInt32 CBufferedOutputStream::getSizeWithLock() const
{
CLock lock(m_mutex);
return m_buffer.getSize();
}