meso: Implement KLightServerSession dtor

This commit is contained in:
TuxSH 2018-11-12 09:54:22 +01:00 committed by Michael Scire
parent 9c8f818c29
commit be3550d382
8 changed files with 60 additions and 10 deletions

View file

@ -21,7 +21,6 @@ class KLightClientSession final : public KAutoObject, public IClient<KLightSessi
friend class KLightSession;
KClientPort *parentPort = nullptr;
bool isRemoteActive = false;
};
MESOSPHERE_AUTO_OBJECT_DEFINE_INCREF(LightClientSession);

View file

@ -38,12 +38,13 @@ class KLightServerSession final :
virtual bool IsSignaled() const override;
private:
friend class KLightSession;
void Terminate(bool fromServer);
KThread::WaitList senderThreads{}, receiverThreads{};
SharedPtr<KThread> currentSender{}, currentReceiver{};
bool isRemoteActive = false;
SharedPtr<KThread> currentSender{};
KThread *currentReceiver = nullptr;
};
MESOSPHERE_AUTO_OBJECT_DEFINE_INCREF(LightServerSession);

View file

@ -24,6 +24,14 @@ class KLightSession final :
virtual ~KLightSession();
Result Initialize();
private:
friend class KLightClientSession;
friend class KLightServerSession;
void Terminate(bool fromServer);
bool isClientAlive = false;
bool isServerAlive = false;
};
MESOSPHERE_AUTO_OBJECT_DEFINE_INCREF(LightSession);

View file

@ -242,6 +242,14 @@ class KThread final :
void CancelKernelSync();
/// Takes effect immediately
void CancelKernelSync(Result res);
/// Needs to be in kernel sync
bool IsInKernelSync() const { return currentWaitList != nullptr; }
/// User sync
constexpr bool IsWaitingSync() const { return isWaitingSync; }
void SetWaitingSync(bool isWaitingSync) { this->isWaitingSync = isWaitingSync; }
constexpr bool IsSyncCancelled() const { return isSyncCancelled; }
void SetSyncCancelled(bool isSyncCancelled) { this->isSyncCancelled = isSyncCancelled; }
/// Takes effect when critical section is left
void HandleSyncObjectSignaled(KSynchronizationObject *syncObj);
@ -295,7 +303,7 @@ private:
uint basePriority = 64, priority = 64;
int currentCoreId = -1;
ulong affinityMask = 0;
bool cancelled = false;
bool isSyncCancelled = false;
bool isWaitingSync = false;
uiptr wantedMutex = 0;
KThread *wantedMutexOwner = nullptr;

View file

@ -1,11 +1,13 @@
#include <mesosphere/processes/KLightClientSession.hpp>
#include <mesosphere/processes/KLightSession.hpp>
#include <mesosphere/threading/KScopedCriticalSection.hpp>
namespace mesosphere
{
KLightClientSession::~KLightClientSession()
{
//TODO
parent->Terminate(false);
}

View file

@ -1,11 +1,13 @@
#include <mesosphere/processes/KLightServerSession.hpp>
#include <mesosphere/processes/KLightSession.hpp>
#include <mesosphere/threading/KScopedCriticalSection.hpp>
namespace mesosphere
{
KLightServerSession::~KLightServerSession()
{
//TODO
Terminate(true);
}
bool KLightServerSession::IsSignaled() const
@ -13,5 +15,30 @@ bool KLightServerSession::IsSignaled() const
return false; // TODO
}
void KLightServerSession::Terminate(bool fromServer)
{
SharedPtr<KThread> curSender{std::move(currentSender)};
{
KScopedCriticalSection critsec{};
if (fromServer) {
parent->isServerAlive = false; // buggy in official kernel -- where it sets it outside of critical section
} else {
parent->isClientAlive = false;
}
if (curSender != nullptr) {
kassert(curSender->GetSchedulingStatus() == KThread::SchedulingStatus::Paused && curSender->IsInKernelSync());
curSender->CancelKernelSync(ResultKernelConnectionClosed()); //TODO check
currentSender = nullptr;
currentReceiver = nullptr;
}
for (auto &&sender : senderThreads) {
kassert(sender.GetSchedulingStatus() == KThread::SchedulingStatus::Paused && sender.IsInKernelSync());
sender.CancelKernelSync(ResultKernelConnectionClosed()); //TODO check
}
KThread::ResumeAllFromKernelSync(receiverThreads);
}
}
}

View file

@ -11,11 +11,16 @@ KLightSession::~KLightSession()
Result KLightSession::Initialize()
{
SetClientServerParent();
client.isRemoteActive = true;
server.isRemoteActive = true;
isClientAlive = true;
isServerAlive = true;
SetResourceOwner(KCoreContext::GetCurrentInstance().GetCurrentProcess());
return ResultSuccess();
}
void KLightSession::Terminate(bool fromServer)
{
server.Terminate(fromServer);
}
}

View file

@ -151,7 +151,7 @@ Result KThread::WaitSynchronizationImpl(int &outId, KSynchronizationObject **syn
if (IsDying()) {
return ResultKernelThreadTerminating();
}
if (cancelled) {
if (isSyncCancelled) {
return ResultKernelCancelled();
}