Skip to content
Snippets Groups Projects
Commit 3d6fe212 authored by Alexander van Amesfoort's avatar Alexander van Amesfoort
Browse files

Task #5441: COBALT RSP raw support: improve LCS/Stream StringStream. Fixes...

Task #5441: COBALT RSP raw support: improve LCS/Stream StringStream. Fixes tTABTranspose, which exposed the deadlock introduced in r38093. StringStream is still broken wrt thread-safety and remaining data (but a little less than it was), but not used in operations, only for tests. It sucks, but it'll have to do for now.
parent 9869238d
No related branches found
No related tags found
No related merge requests found
//# StringStream.cc:
//#
//# Copyright (C) 2008
//# Copyright (C) 2008, 2017
//# ASTRON (Netherlands Institute for Radio Astronomy)
//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
//#
......@@ -40,21 +40,25 @@ size_t StringStream::tryRead(void *ptr, size_t size)
{
Cancellation::point(); // keep behaviour consistent with real I/O streams
{
ScopedLock sl(itsMutex);
// still wrong for !USE_THREADS wrt stringstream exception vs EndOfStreamException, but !USE_THREADS is obsolete anyway
// NOTE: still wrong for !USE_THREADS and wrt less than size bytes avail and stringstream error vs EndOfStreamException, but !USE_THREADS is obsolete anyway. Need CondVar instead of Semaphore and drop !USE_THREADS.
#ifdef USE_THREADS
if (!dataWritten.down(size)) {
// stream closed and avail < size
size_t avail = dataWritten.getValue();
if (avail == 0) // size > 0
THROW(EndOfStreamException, "Stream has been closed");
size = avail;
dataWritten.down(size);
}
if (!dataWritten.down(size)) {
ScopedLock sl(itsMutex);
size_t avail = dataWritten.getValue();
if (avail == 0) // size > 0
THROW(EndOfStreamException, "Stream has been closed");
size = avail;
dataWritten.down(size);
itsBuffer.read(static_cast<char*>(ptr), size);
return size;
}
#endif
{
ScopedLock sl(itsMutex);
itsBuffer.read(static_cast<char*>(ptr), size);
}
......@@ -89,29 +93,30 @@ size_t StringStream::tryReadv(const struct iovec *iov, int iovcnt)
size += iov[i].iov_len;
}
{
ScopedLock sl(itsMutex);
// still wrong for !USE_THREADS wrt stringstream exception vs EndOfStreamException, but !USE_THREADS is obsolete anyway
// NOTE: still wrong for !USE_THREADS and wrt less than size bytes avail and stringstream error vs EndOfStreamException, but !USE_THREADS is obsolete anyway. Need CondVar instead of Semaphore and drop !USE_THREADS.
#ifdef USE_THREADS
if (!dataWritten.down(size)) {
// stream closed and avail < size
size_t avail = dataWritten.getValue();
if (avail == 0) // size > 0
THROW(EndOfStreamException, "Stream has been closed");
size = avail;
dataWritten.down(size);
for (int i = 0; i < iovcnt && avail > 0; i++) {
size_t len = avail < iov[i].iov_len ? avail : iov[i].iov_len;
itsBuffer.read(static_cast<char*>(iov[i].iov_base), len);
avail -= len;
}
return size;
if (!dataWritten.down(size)) {
ScopedLock sl(itsMutex);
// stream closed and avail < size
size_t avail = dataWritten.getValue();
if (avail == 0) // size > 0
THROW(EndOfStreamException, "Stream has been closed");
size = avail;
dataWritten.down(size);
for (int i = 0; i < iovcnt && avail > 0; i++) {
size_t len = avail < iov[i].iov_len ? avail : iov[i].iov_len;
itsBuffer.read(static_cast<char*>(iov[i].iov_base), len);
avail -= len;
}
return size;
}
#endif
{
ScopedLock sl(itsMutex);
for (int i = 0; i < iovcnt; i++) {
itsBuffer.read(static_cast<char*>(iov[i].iov_base), iov[i].iov_len);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment