diff --git a/src/misc.h b/src/misc.h index af40ab16..4c99cc2b 100644 --- a/src/misc.h +++ b/src/misc.h @@ -124,6 +124,13 @@ private: } } + RegionLock& operator << (std::ostream&(*pManip)(std::ostream&)) { + if (logger != nullptr) + logger->write(region_id, pManip); + + return *this; + } + template RegionLock& operator << (const T& value) { if (logger != nullptr) @@ -159,6 +166,29 @@ private: return id; } + void write(RegionId id, std::ostream&(*pManip)(std::ostream&)) { + std::lock_guard lock(mutex); + + if (regions.empty()) + return; + + if (id == regions.front().id) { + // We can just directly print to the output because + // we are at the front of the region queue. + out << *pManip; + } else { + // We have to schedule the print until previous regions are + // processed + auto* region = find_region_nolock(id); + if (region == nullptr) + return; + + std::stringstream ss; + ss << *pManip; + region->pending_parts.emplace_back(std::move(ss).str()); + } + } + template void write(RegionId id, const T& value) { std::lock_guard lock(mutex);