Skip to content

Commit

Permalink
#840 en #845 supplemental
Browse files Browse the repository at this point in the history
  • Loading branch information
MaartenHilferink committed Dec 18, 2024
1 parent fbebfcb commit c742c20
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 81 deletions.
1 change: 1 addition & 0 deletions rtc/dll/src/act/MainThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ void operation_queue::Process()
for (auto& oper : operQueue)
{
try {
SuspendTrigger::Resume();
oper();
}
catch (...)
Expand Down
152 changes: 89 additions & 63 deletions rtc/dll/src/dbg/DebugStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,91 @@ void MsgDispatch(MsgData* msgData, bool moreToCome)

namespace { // DebugOutStreamBuff is local

void FlushMsg(MsgData* msgData)
{
SizeT minorSkipCount = 0, majorSkipCount = 0;

UInt32 printedLines = 0;
SeverityTypeID st = msgData->m_SeverityType;
MsgCategory msgCat = msgData->m_MsgCategory;
auto msgTxt = msgData->m_Txt;
auto i = msgTxt.begin(), e = msgTxt.end();
while (i != e)
{
assert(e[-1] == 0); // guaranteed by caller to have a completed Line.
assert(st <= SeverityTypeID::ST_DispError);
if (e - i >= 1024000 && (st < SeverityTypeID::ST_MajorTrace || st == SeverityTypeID::ST_MajorTrace && printedLines > 16)) // filter out large trace sections
if (st <= SeverityTypeID::ST_MinorTrace)
++minorSkipCount;
else
++majorSkipCount;
else
{
if (minorSkipCount || majorSkipCount) {
auto skipMsg = mySSPrintF("... skipped %I64u minor and %I64u major trace lines", UInt64(minorSkipCount), UInt64(majorSkipCount));
auto summaryData = MsgData{
majorSkipCount ? SeverityTypeID::ST_MajorTrace : SeverityTypeID::ST_MinorTrace
, msgCat
, false
, msgData->m_ThreadID
, msgData->m_DateTime
, std::move(skipMsg)
};
MsgDispatch(&summaryData, false);
minorSkipCount = majorSkipCount = 0;
}
while (true)
{
auto eolPtr = std::find(i, e, '\n');
if (eolPtr != i)
{
auto eosPtr = eolPtr; if (eosPtr[-1] == char(0)) --eosPtr;
msgData->m_Txt = SharedStr(i, eosPtr); // TODO: can we avoid this extra string copy by forwarding a CharPtrRange ?
MsgDispatch(msgData, eolPtr != e);
msgData->m_IsFollowup = true;
}
if (eolPtr == e)
break;

i = ++eolPtr;
}
++printedLines;
}
i = std::find(i, e, char(0));
++i;
}
}

static std::vector< MsgData > s_FlushPipeline;

void ProcessMsgDataPipeline()
{
assert(IsMainThread());

if (!s_nrRtcStreamLocks)
return;

std::vector< MsgData > localFlushPileLine;
{
leveled_critical_section::scoped_lock lock(*g_DebugStream);
auto localFlushPileLine = std::move(s_FlushPipeline);
}
for (auto& msgData : localFlushPileLine)
FlushMsg(&msgData);
}

void PostLogMsg(MsgData&& msgData)
{
if (!s_nrRtcStreamLocks)
return;

assert(!g_DebugStream->try_lock());

if (s_FlushPipeline.empty())
PostMainThreadOper(ProcessMsgDataPipeline);
s_FlushPipeline.emplace_back(std::move(msgData));
}

struct DebugOutStreamBuff : VectorOutStreamBuff
{
bool LineEmpty() const
Expand Down Expand Up @@ -167,78 +252,19 @@ namespace { // DebugOutStreamBuff is local
return;

assert(m_Data.end()[-1] == char(0));
MsgData msgData(m_Severity, m_MsgCat, false, GetThreadID(), StreamableDateTime(), SharedStr(begin_ptr(m_Data), end_ptr(m_Data)));
PostMainThreadOper([msg = std::move(msgData)] () mutable
{
if (!s_nrRtcStreamLocks)
return;
leveled_critical_section::scoped_lock lock(*g_DebugStream);
DebugOutStreamBuff::Flush(&msg);
}
);

PostLogMsg(MsgData(m_Severity, m_MsgCat, false, GetThreadID(), StreamableDateTime(), SharedStr(begin_ptr(m_Data), end_ptr(m_Data))));
m_Data.clear();
}
bool AtEnd() const override { return false; }
static void Flush(MsgData* msgData)
{
SizeT minorSkipCount = 0, majorSkipCount = 0;

UInt32 printedLines = 0;
SeverityTypeID st = msgData->m_SeverityType;
MsgCategory msgCat = msgData->m_MsgCategory;
auto msgTxt = msgData->m_Txt;
auto i = msgTxt.begin(), e = msgTxt.end();
while (i!=e)
{
assert(e[-1]==0); // guaranteed by caller to have a completed Line.
assert(st <= SeverityTypeID::ST_DispError);
if (e - i >= 1024000 && (st < SeverityTypeID::ST_MajorTrace || st == SeverityTypeID::ST_MajorTrace && printedLines > 16)) // filter out large trace sections
if (st <= SeverityTypeID::ST_MinorTrace)
++minorSkipCount;
else
++majorSkipCount;
else
{
if (minorSkipCount || majorSkipCount) {
auto skipMsg = mySSPrintF("... skipped %I64u minor and %I64u major trace lines", UInt64(minorSkipCount), UInt64(majorSkipCount));
auto summaryData = MsgData{
majorSkipCount ? SeverityTypeID::ST_MajorTrace : SeverityTypeID::ST_MinorTrace
, msgCat
, false
, msgData->m_ThreadID
, msgData->m_DateTime
, std::move(skipMsg)
};
MsgDispatch(&summaryData, false);
minorSkipCount = majorSkipCount = 0;
}
while (true)
{
auto eolPtr = std::find(i, e, '\n');
if (eolPtr != i)
{
auto eosPtr = eolPtr; if (eosPtr[-1] == char(0)) --eosPtr;
msgData->m_Txt = SharedStr(i, eosPtr); // TODO: can we avoid this extra string copy by forwarding a CharPtrRange ?
MsgDispatch(msgData, eolPtr != e);
msgData->m_IsFollowup = true;
}
if (eolPtr == e)
break;

i = ++eolPtr;
}
++printedLines;
}
i = std::find(i, e, char(0));
++i;
}
}

protected:
SeverityTypeID m_Severity = SeverityTypeID::ST_MinorTrace;
MsgCategory m_MsgCat = MsgCategory::progress;
};

static_ptr<DebugOutStreamBuff> g_DebugStreamBuff;

} // end anonymous namespace

/********** DebugOutStream Singleton **********/
Expand Down
2 changes: 1 addition & 1 deletion shv/dll/src/GraphicLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ SizeT GraphicLayer::Feature2EntityIndex(SizeT featureIndex) const
assert(ic);
assert(ic->HasExtKey() || ic->HasGeoRel());

auto featureLoc = ic->GetTiledLocation(featureIndex);
auto featureLoc = ic->GetTileDataLocation(featureIndex);
if (!IsDefined(featureLoc.first))
return UNDEFINED_VALUE(SizeT);

Expand Down
17 changes: 15 additions & 2 deletions shv/dll/src/GridLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,19 @@ CrdRect GridLayer::CalcSelectedFullWorldRect() const
return AsWorldExtents(Convert<CrdRect>(selectRect), GetGeoCrdUnit());
}

CrdRect GetWorldExtentsInTile(const IRect& tileRect, const UnitProjection* proj, tile_id offset)
{
assert(IsDefined(offset));

IPoint gridLoc = Range_GetValue_naked(tileRect, offset);

return
AsWorldExtents(
Convert<CrdRect>(IRect(gridLoc, gridLoc + IPoint(1, 1))),
proj
);
}

CrdRect GetWorldExtents(const AbstrUnit* geoCrdUnit, const IRect& geoCrdRect, const UnitProjection* proj, feature_id featureIndex)
{
assert(IsDefined(featureIndex));
Expand Down Expand Up @@ -1113,11 +1126,11 @@ bool GridLayer::Draw(GraphDrawer& d) const
for (tile_offset minFE = 0, maxFE = geoCrdUnit->GetTileCount(t); minFE!=maxFE; ++minFE)
if (indexCollector.GetEntityIndex(minFE) == fe)
{
CrdRect focusWorldRect = ::GetWorldExtents(geoCrdUnit, tileRect, proj, minFE);
CrdRect focusWorldRect = GetWorldExtentsInTile(tileRect, proj, minFE);

while (minFE+1!=maxFE && indexCollector.GetEntityIndex(minFE + 1) == fe)
{
CrdRect nextWorldRect = ::GetWorldExtents(geoCrdUnit, tileRect, proj, minFE+1);
CrdRect nextWorldRect = GetWorldExtentsInTile(tileRect, proj, minFE+1);
if ( nextWorldRect.first .Row() != focusWorldRect.first .Row()
|| nextWorldRect.second.Row() != focusWorldRect.second.Row()
|| nextWorldRect.first.Col() > focusWorldRect.second.Col())
Expand Down
4 changes: 2 additions & 2 deletions shv/dll/src/IndexCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ auto IndexCollector::GetDataRead(tile_id t) const -> DataArray<entity_id>::locke
return const_array_checked_cast<entity_id>(lock.GetRefObj())->GetDataRead(t);
}

tile_loc IndexCollector::GetTiledLocation(SizeT index) const
tile_loc IndexCollector::GetTileDataLocation(SizeT index) const
{
return m_TileData->GetTiledLocation(index);
return m_TileData->GetTileDataLocation(index);
}

tile_id IndexCollector::GetNrTiles() const
Expand Down
2 changes: 1 addition & 1 deletion shv/dll/src/IndexCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct IndexCollector : public SharedBase
DataReadLock GetDataItemReadLock() const;
auto GetDataRead(tile_id t) const->DataArray<entity_id>::locked_cseq_t;
tile_id GetNrTiles() const;
tile_loc GetTiledLocation(SizeT index) const;
tile_loc GetTileDataLocation(SizeT index) const;

bool HasExtKey() const { return m_ExtKeyAttr; }
bool HasGeoRel() const { return m_GeoRelAttr; }
Expand Down
10 changes: 3 additions & 7 deletions shv/dll/src/TableControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,14 @@ SizeT TableControl::NrRows() const

SizeT TableControl::GetRecNo(SizeT rowNr) const
{
if (!IsDefined(rowNr) || rowNr >= NrRows())
return UNDEFINED_VALUE(SizeT);

if (m_State.Get(TCF_FlipSortOrder))
rowNr = (NrRows() - (rowNr+1));
if (!m_SelIndexAttr)
return rowNr;
return getRecNo(rowNr);

if (!const_cast<TableControl*>(this)->PrepareDataOrUpdateViewLater(m_SelIndexAttr.get_ptr()))
return UNDEFINED_VALUE(SizeT);

PreparedDataReadLock lck(m_SelIndexAttr, "TableControl::GetRecNo");
return m_SelIndexAttr->GetRefObj()->GetValueAsSizeT(rowNr);
return getRecNo(rowNr);
}

SizeT TableControl::nrRows() const
Expand Down
21 changes: 17 additions & 4 deletions tic/dll/src/OperationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,13 @@ garbage_t runOperationContexts()
return cancelGarbage;
}

static std::atomic<bool> s_RunOperationContextsScheduled = false;

void RunOperationContexts()
{
// if (IsMainThread() && InterestRetainContextBase::IsActive())
s_RunOperationContextsScheduled = false;

// if (IsMainThread() && InterestRetainContextBase::IsActive())
// return;
if (s_RunOperationContextsCount)
return;
Expand All @@ -397,6 +401,13 @@ void RunOperationContexts()
receivedGarbage = runOperationContexts();
}

void ScheduleRunOperationContexts()
{
if (s_RunOperationContextsScheduled.exchange(true))
return;
PostMainThreadOper(RunOperationContexts);
}

// *****************************************************************************
// Section: OperatorContextBase
// *****************************************************************************
Expand Down Expand Up @@ -836,7 +847,7 @@ garbage_t OperationContext::separateResources(task_status status)

releaseBin |= disconnect();
// releaseBin |= runOperationContexts();
releaseBin |= make_any_scoped_exit( &RunOperationContexts ); // do this after releasing interests and related resources of suppliers
releaseBin |= make_any_scoped_exit( &ScheduleRunOperationContexts ); // do this after releasing interests and related resources of suppliers
cv_TaskCompleted.notify_all();

return releaseBin;
Expand Down Expand Up @@ -1370,7 +1381,11 @@ task_status OperationContext::Join()
freediecount.emplace();

if (!isFirstTime)
{
RunOperationContexts(); // OPTIMIZE, CONSISTENCY: Some tasks finished without calling this. Find out why and avoid wasting idle thread time; maybe all threads are waiting in a Join without new and current tasks being activated
if (IsMetaThread())
ProcessMainThreadOpers();
}

leveled_std_section::unique_lock lock(cs_ThreadMessing);
if (m_Status > task_status::running)
Expand All @@ -1384,8 +1399,6 @@ task_status OperationContext::Join()
prioritize(prioritizedContexts, this->shared_from_this());
}
cv_TaskCompleted.wait_for(lock.m_BaseLock, std::chrono::milliseconds(200), [this]() { return m_Status > task_status::running; });
if (IsMetaThread())
ProcessMainThreadOpers();
isFirstTime = false;
}

Expand Down
2 changes: 1 addition & 1 deletion tic/dll/src/TreeItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2540,7 +2540,7 @@ void TreeItem::UpdateMetaInfoImpl2() const
}
// validate units with refObject if it wasn't copied by the parent
}
ProcessMainThreadOpers();
// ProcessMainThreadOpers();
}
catch (...)
{
Expand Down

0 comments on commit c742c20

Please sign in to comment.