mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-11 04:35:05 +01:00
Kernel: pass ref to sempahore
This commit is contained in:
parent
181646679c
commit
247249d5d3
@ -17,6 +17,7 @@ class Mutex;
|
||||
class CodeSet;
|
||||
class Process;
|
||||
class Thread;
|
||||
class Semaphore;
|
||||
|
||||
enum class ResetType {
|
||||
OneShot,
|
||||
@ -73,6 +74,16 @@ public:
|
||||
ResultVal<SharedPtr<Thread>> CreateThread(std::string name, VAddr entry_point, u32 priority,
|
||||
u32 arg, s32 processor_id, VAddr stack_top,
|
||||
SharedPtr<Process> owner_process);
|
||||
|
||||
/**
|
||||
* Creates a semaphore.
|
||||
* @param initial_count Number of slots reserved for other threads
|
||||
* @param max_count Maximum number of slots the semaphore can have
|
||||
* @param name Optional name of semaphore
|
||||
* @return The created semaphore
|
||||
*/
|
||||
ResultVal<SharedPtr<Semaphore>> CreateSemaphore(s32 initial_count, s32 max_count,
|
||||
std::string name = "Unknown");
|
||||
};
|
||||
|
||||
} // namespace Kernel
|
||||
|
@ -10,16 +10,16 @@
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
Semaphore::Semaphore() {}
|
||||
Semaphore::Semaphore(KernelSystem& kernel) {}
|
||||
Semaphore::~Semaphore() {}
|
||||
|
||||
ResultVal<SharedPtr<Semaphore>> Semaphore::Create(s32 initial_count, s32 max_count,
|
||||
ResultVal<SharedPtr<Semaphore>> KernelSystem::CreateSemaphore(s32 initial_count, s32 max_count,
|
||||
std::string name) {
|
||||
|
||||
if (initial_count > max_count)
|
||||
return ERR_INVALID_COMBINATION_KERNEL;
|
||||
|
||||
SharedPtr<Semaphore> semaphore(new Semaphore);
|
||||
SharedPtr<Semaphore> semaphore(new Semaphore(*this));
|
||||
|
||||
// When the semaphore is created, some slots are reserved for other threads,
|
||||
// and the rest is reserved for the caller thread
|
||||
|
@ -15,16 +15,6 @@ namespace Kernel {
|
||||
|
||||
class Semaphore final : public WaitObject {
|
||||
public:
|
||||
/**
|
||||
* Creates a semaphore.
|
||||
* @param initial_count Number of slots reserved for other threads
|
||||
* @param max_count Maximum number of slots the semaphore can have
|
||||
* @param name Optional name of semaphore
|
||||
* @return The created semaphore
|
||||
*/
|
||||
static ResultVal<SharedPtr<Semaphore>> Create(s32 initial_count, s32 max_count,
|
||||
std::string name = "Unknown");
|
||||
|
||||
std::string GetTypeName() const override {
|
||||
return "Semaphore";
|
||||
}
|
||||
@ -52,8 +42,10 @@ public:
|
||||
ResultVal<s32> Release(s32 release_count);
|
||||
|
||||
private:
|
||||
Semaphore();
|
||||
explicit Semaphore(KernelSystem& kernel);
|
||||
~Semaphore() override;
|
||||
|
||||
friend class KernelSystem;
|
||||
};
|
||||
|
||||
} // namespace Kernel
|
||||
|
@ -891,7 +891,8 @@ static ResultCode GetThreadId(u32* thread_id, Handle handle) {
|
||||
|
||||
/// Creates a semaphore
|
||||
static ResultCode CreateSemaphore(Handle* out_handle, s32 initial_count, s32 max_count) {
|
||||
CASCADE_RESULT(SharedPtr<Semaphore> semaphore, Semaphore::Create(initial_count, max_count));
|
||||
CASCADE_RESULT(SharedPtr<Semaphore> semaphore,
|
||||
Core::System::GetInstance().Kernel().CreateSemaphore(initial_count, max_count));
|
||||
semaphore->name = fmt::format("semaphore-{:08x}", Core::CPU().GetReg(14));
|
||||
CASCADE_RESULT(*out_handle, g_handle_table.Create(std::move(semaphore)));
|
||||
|
||||
|
@ -63,7 +63,7 @@ void SRV::EnableNotification(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp(ctx, 0x2, 0, 0);
|
||||
|
||||
notification_semaphore =
|
||||
Kernel::Semaphore::Create(0, MAX_PENDING_NOTIFICATIONS, "SRV:Notification").Unwrap();
|
||||
system.Kernel().CreateSemaphore(0, MAX_PENDING_NOTIFICATIONS, "SRV:Notification").Unwrap();
|
||||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
|
Loading…
Reference in New Issue
Block a user