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; friend class KLightSession;
KClientPort *parentPort = nullptr; KClientPort *parentPort = nullptr;
bool isRemoteActive = false;
}; };
MESOSPHERE_AUTO_OBJECT_DEFINE_INCREF(LightClientSession); MESOSPHERE_AUTO_OBJECT_DEFINE_INCREF(LightClientSession);

View file

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

View file

@ -24,6 +24,14 @@ class KLightSession final :
virtual ~KLightSession(); virtual ~KLightSession();
Result Initialize(); 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); MESOSPHERE_AUTO_OBJECT_DEFINE_INCREF(LightSession);

View file

@ -242,6 +242,14 @@ class KThread final :
void CancelKernelSync(); void CancelKernelSync();
/// Takes effect immediately /// Takes effect immediately
void CancelKernelSync(Result res); 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 /// Takes effect when critical section is left
void HandleSyncObjectSignaled(KSynchronizationObject *syncObj); void HandleSyncObjectSignaled(KSynchronizationObject *syncObj);
@ -295,7 +303,7 @@ private:
uint basePriority = 64, priority = 64; uint basePriority = 64, priority = 64;
int currentCoreId = -1; int currentCoreId = -1;
ulong affinityMask = 0; ulong affinityMask = 0;
bool cancelled = false; bool isSyncCancelled = false;
bool isWaitingSync = false; bool isWaitingSync = false;
uiptr wantedMutex = 0; uiptr wantedMutex = 0;
KThread *wantedMutexOwner = nullptr; KThread *wantedMutexOwner = nullptr;

View file

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

View file

@ -1,11 +1,13 @@
#include <mesosphere/processes/KLightServerSession.hpp> #include <mesosphere/processes/KLightServerSession.hpp>
#include <mesosphere/processes/KLightSession.hpp>
#include <mesosphere/threading/KScopedCriticalSection.hpp>
namespace mesosphere namespace mesosphere
{ {
KLightServerSession::~KLightServerSession() KLightServerSession::~KLightServerSession()
{ {
//TODO Terminate(true);
} }
bool KLightServerSession::IsSignaled() const bool KLightServerSession::IsSignaled() const
@ -13,5 +15,30 @@ bool KLightServerSession::IsSignaled() const
return false; // TODO 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() Result KLightSession::Initialize()
{ {
SetClientServerParent(); SetClientServerParent();
client.isRemoteActive = true; isClientAlive = true;
server.isRemoteActive = true; isServerAlive = true;
SetResourceOwner(KCoreContext::GetCurrentInstance().GetCurrentProcess()); SetResourceOwner(KCoreContext::GetCurrentInstance().GetCurrentProcess());
return ResultSuccess(); 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()) { if (IsDying()) {
return ResultKernelThreadTerminating(); return ResultKernelThreadTerminating();
} }
if (cancelled) { if (isSyncCancelled) {
return ResultKernelCancelled(); return ResultKernelCancelled();
} }