2014-12-04 00:49:51 +01:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-12-04 00:49:51 +01:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-01-11 16:53:11 +01:00
|
|
|
#include <string>
|
2018-03-09 18:54:43 +01:00
|
|
|
#include <queue>
|
2014-12-04 00:49:51 +01:00
|
|
|
#include "common/common_types.h"
|
2018-08-02 04:40:00 +02:00
|
|
|
#include "core/hle/kernel/object.h"
|
2017-05-30 00:45:30 +02:00
|
|
|
#include "core/hle/kernel/wait_object.h"
|
2017-05-30 01:45:42 +02:00
|
|
|
#include "core/hle/result.h"
|
2014-12-04 00:49:51 +01:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2015-01-27 05:40:21 +01:00
|
|
|
class Semaphore final : public WaitObject {
|
2015-01-11 16:53:11 +01:00
|
|
|
public:
|
2019-03-23 21:04:19 +01:00
|
|
|
explicit Semaphore(KernelSystem& kernel);
|
|
|
|
~Semaphore() override;
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
std::string GetTypeName() const override {
|
|
|
|
return "Semaphore";
|
|
|
|
}
|
|
|
|
std::string GetName() const override {
|
|
|
|
return name;
|
|
|
|
}
|
2015-01-11 16:53:11 +01:00
|
|
|
|
2019-04-11 22:30:52 +02:00
|
|
|
static constexpr HandleType HANDLE_TYPE = HandleType::Semaphore;
|
2016-09-18 02:38:01 +02:00
|
|
|
HandleType GetHandleType() const override {
|
|
|
|
return HANDLE_TYPE;
|
|
|
|
}
|
2015-01-11 16:53:11 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
s32 max_count; ///< Maximum number of simultaneous holders the semaphore can have
|
|
|
|
s32 available_count; ///< Number of free slots left in the semaphore
|
|
|
|
std::string name; ///< Name of semaphore (optional)
|
2015-01-11 16:53:11 +01:00
|
|
|
|
2017-01-01 22:53:22 +01:00
|
|
|
bool ShouldWait(Thread* thread) const override;
|
|
|
|
void Acquire(Thread* thread) override;
|
2015-01-11 16:53:11 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Releases a certain number of slots from a semaphore.
|
|
|
|
* @param release_count The number of slots to release
|
|
|
|
* @return The number of free slots the semaphore had before this call
|
|
|
|
*/
|
|
|
|
ResultVal<s32> Release(s32 release_count);
|
|
|
|
};
|
2014-12-13 02:46:52 +01:00
|
|
|
|
2018-03-09 18:54:43 +01:00
|
|
|
} // namespace Kernel
|