semaphore: Updates for Switch.

This commit is contained in:
bunnei
2018-01-06 15:55:40 -05:00
parent 6f6d9af408
commit 91f10a1460
2 changed files with 31 additions and 21 deletions

View File

@ -17,12 +17,14 @@ 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
* @param guest_addr Address of the object tracking the semaphore in guest memory. If specified,
* this semaphore will update the guest object when its state changes.
* @param mutex_addr Optional address of a guest mutex associated with this semaphore, used by
* the OS for implementing events.
* @param name Optional name of semaphore.
* @return The created semaphore.
*/
static ResultVal<SharedPtr<Semaphore>> Create(s32 initial_count, s32 max_count, VAddr address,
static ResultVal<SharedPtr<Semaphore>> Create(VAddr guest_addr, VAddr mutex_addr = 0,
std::string name = "Unknown");
std::string GetTypeName() const override {
@ -39,8 +41,10 @@ public:
s32 max_count; ///< Maximum number of simultaneous holders the semaphore can have
s32 available_count; ///< Number of free slots left in the semaphore
VAddr address;
std::string name; ///< Name of semaphore (optional)
VAddr guest_addr; ///< Address of the guest semaphore value
VAddr mutex_addr; ///< (optional) Address of guest mutex value associated with this semaphore,
///< used for implementing events
bool ShouldWait(Thread* thread) const override;
void Acquire(Thread* thread) override;
@ -55,6 +59,9 @@ public:
private:
Semaphore();
~Semaphore() override;
/// Updates the state of the object tracking this semaphore in guest memory
void UpdateGuestState();
};
} // namespace
} // namespace Kernel