[*] Solve possible spinlock during exception under conin callback and print

[*] Update linkage
This commit is contained in:
Reece Wilson 2022-05-30 09:46:24 +01:00
parent c88925fa27
commit db3f41233b
3 changed files with 42 additions and 31 deletions

View File

@ -21,9 +21,9 @@ namespace Aurora::Async
{
struct ProcessInfo
{
ProcessInfo(bool finished) : type(finished ? ETickType::eFinished : ETickType::eFailed) {}
ProcessInfo(ETickType type) : type(type) {}
ProcessInfo(const AuList<AuSPtr<IWorkItem>> &blockedBy) : type(ETickType::eSchedule), waitFor(blockedBy) {}
inline ProcessInfo(bool finished) : type(finished ? ETickType::eFinished : ETickType::eFailed) {}
inline ProcessInfo(ETickType type) : type(type) {}
inline ProcessInfo(const AuList<AuSPtr<IWorkItem>> &blockedBy) : type(ETickType::eSchedule), waitFor(blockedBy) {}
// ...
ETickType type;

View File

@ -8,16 +8,16 @@ namespace Aurora::Async
AuFunction<void()> callback;
AuFunction<void()> shutdown; // error
BasicWorkStdFunc(AuFunction<void()> &&callback, AuFunction<void()> &&shutdown) : callback(std::move(callback)), shutdown(std::move(shutdown))
inline BasicWorkStdFunc(AuFunction<void()> &&callback, AuFunction<void()> &&shutdown) : callback(std::move(callback)), shutdown(std::move(shutdown))
{}
BasicWorkStdFunc(AuFunction<void()> &&callback) : callback(std::move(callback))
inline BasicWorkStdFunc(AuFunction<void()> &&callback) : callback(std::move(callback))
{}
BasicWorkStdFunc(const AuFunction<void()> &callback) : callback(callback)
inline BasicWorkStdFunc(const AuFunction<void()> &callback) : callback(callback)
{}
BasicWorkStdFunc(const AuFunction<void()> &callback, const AuFunction<void()> &shutdown) : callback(callback), shutdown(shutdown)
inline BasicWorkStdFunc(const AuFunction<void()> &callback, const AuFunction<void()> &shutdown) : callback(callback), shutdown(shutdown)
{}
private:
@ -92,7 +92,7 @@ namespace Aurora::Async
#define ASYNC_FINISH { if constexpr (AuIsSame_v<T, bool>) { return true; } }
template<typename T = void, typename... Args, AU_TEMPLATE_ENABLE_WHEN(AuIsSame_v<T, bool> || AuIsVoid_v<T>)>
static AuFunction<T(Args&&...)> TranslateAsyncFunctionToDispatcherWithThread(WorkerId_t id, AuFunction<void(Args...)> func)
static AuFunction<T(Args&&...)> TranslateAsyncFunctionToDispatcherWithThread(WorkerPId_t id, AuFunction<void(Args...)> func)
{
if (!func) return {};
return [=](Args&&... in) -> T
@ -117,7 +117,7 @@ namespace Aurora::Async
/// Async app only
template<typename B = void, typename T, typename... Args, AU_TEMPLATE_ENABLE_WHEN(AuIsSame_v<T, bool> || AuIsVoid_v<T>)>
static AuFunction<T(AuFunction<void(const B&)>, Args...)> TranslateAsyncReturnableFunctionToDispatcherWithThread(WorkerId_t id, AuFunction<B(Args...)> func)
static AuFunction<T(AuFunction<void(const B&)>, Args...)> TranslateAsyncReturnableFunctionToDispatcherWithThread(WorkerPId_t id, AuFunction<B(Args...)> func)
{
return [=](AuFunction<T(const B&)> callback, Args... in) -> T
{

View File

@ -103,7 +103,7 @@ namespace Aurora::Console::ConsoleStd
static AuList<NoncanonicalInput> gCanonicalBuffer;
//static AuThreadPrimitives::MutexUnique_t gRingLock = AuThreadPrimitives::MutexUnique();
static AuThreadPrimitives::SpinLock gRingLock;// = AuThreadPrimitives::MutexUnique();
static AuThreadPrimitives::SpinLock gRingLock {};// = AuThreadPrimitives::MutexUnique();
#if defined(AURORA_IS_MODERNNT_DERIVED)
@ -747,7 +747,7 @@ namespace Aurora::Console::ConsoleStd
}
}
static void ProcessLines()
static void ProcessLines(AuList<AuString> &lines)
{
AuMach index = 0, startIdx = 0;
@ -774,12 +774,10 @@ namespace Aurora::Console::ConsoleStd
if (line.size())
{
Console::DispatchRawLine(line);
lines.push_back(line);
}
}
ConsoleTTY::OnEnter();
if (index != 0)
{
const auto remainingBytes = gLineIndex - startIdx;
@ -803,32 +801,45 @@ namespace Aurora::Console::ConsoleStd
static Locale::Encoding::TextStreamEncoder stream(Locale::GetInternalCodePage());
#endif
AU_LOCK_GUARD(&gRingLock);
AuList<AuString> lines;
auto ret = stream.DecodeUTF8(gLineEncodedBuffer, gEncodedIndex, gLineBuffer.data() + gLineIndex, gLineBuffer.size() - gLineIndex);
// increment backline buffer
{
const auto remainingBytes = gEncodedIndex - ret.first;
if (remainingBytes)
AU_LOCK_GUARD(gRingLock);
auto ret = stream.DecodeUTF8(gLineEncodedBuffer, gEncodedIndex, gLineBuffer.data() + gLineIndex, gLineBuffer.size() - gLineIndex);
// increment backline buffer
{
AuMemmove(gLineEncodedBuffer, &gLineEncodedBuffer[ret.first], remainingBytes);
const auto remainingBytes = gEncodedIndex - ret.first;
if (remainingBytes)
{
AuMemmove(gLineEncodedBuffer, &gLineEncodedBuffer[ret.first], remainingBytes);
}
gEncodedIndex = remainingBytes;
}
gEncodedIndex = remainingBytes;
// increment frontline buffer
{
gLineIndex += ret.second;
}
if (gLoopSource)
{
gLoopSource->Set();
}
ProcessLines(lines);
}
// increment frontline buffer
if (lines.size())
{
gLineIndex += ret.second;
for (const auto &line : lines)
{
Console::DispatchRawLine(line);
}
ConsoleTTY::OnEnter();
}
if (gLoopSource)
{
gLoopSource->Set();
}
ProcessLines();
}
static AuUInt32 SyncReadConsole()