2020-12-22 07:36:53 +01:00
|
|
|
// Copyright 2021 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2021-04-04 04:11:46 +02:00
|
|
|
#include "core/hle/kernel/k_auto_object.h"
|
2020-12-22 07:36:53 +01:00
|
|
|
#include "core/hle/result.h"
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
|
|
class KernelCore;
|
|
|
|
class Synchronization;
|
2020-12-31 08:01:08 +01:00
|
|
|
class KThread;
|
2020-12-22 07:36:53 +01:00
|
|
|
|
|
|
|
/// Class that represents a Kernel object that a thread can be waiting on
|
2021-04-04 04:11:46 +02:00
|
|
|
class KSynchronizationObject : public KAutoObjectWithList {
|
|
|
|
KERNEL_AUTOOBJECT_TRAITS(KSynchronizationObject, KAutoObject);
|
|
|
|
|
2020-12-22 07:36:53 +01:00
|
|
|
public:
|
|
|
|
struct ThreadListNode {
|
|
|
|
ThreadListNode* next{};
|
2020-12-31 08:01:08 +01:00
|
|
|
KThread* thread{};
|
2020-12-22 07:36:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]] static ResultCode Wait(KernelCore& kernel, s32* out_index,
|
|
|
|
KSynchronizationObject** objects, const s32 num_objects,
|
|
|
|
s64 timeout);
|
|
|
|
|
2021-05-29 08:49:07 +02:00
|
|
|
void Finalize() override;
|
2021-04-04 04:11:46 +02:00
|
|
|
|
2020-12-22 07:36:53 +01:00
|
|
|
[[nodiscard]] virtual bool IsSignaled() const = 0;
|
|
|
|
|
2020-12-31 08:01:08 +01:00
|
|
|
[[nodiscard]] std::vector<KThread*> GetWaitingThreadsForDebugging() const;
|
2020-12-22 07:36:53 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit KSynchronizationObject(KernelCore& kernel);
|
2021-05-29 08:49:07 +02:00
|
|
|
~KSynchronizationObject() override;
|
2020-12-22 07:36:53 +01:00
|
|
|
|
2021-04-04 04:11:46 +02:00
|
|
|
virtual void OnFinalizeSynchronizationObject() {}
|
|
|
|
|
2020-12-22 07:36:53 +01:00
|
|
|
void NotifyAvailable(ResultCode result);
|
|
|
|
void NotifyAvailable() {
|
|
|
|
return this->NotifyAvailable(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ThreadListNode* thread_list_head{};
|
|
|
|
ThreadListNode* thread_list_tail{};
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Kernel
|