2014-05-21 05:03:45 +02:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-11-19 09:49:13 +01:00
|
|
|
// Refer to the license.txt file included.
|
2014-05-21 05:03:45 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
2018-07-31 14:06:09 +02:00
|
|
|
|
|
|
|
union ResultCode;
|
2014-05-21 05:03:45 +02:00
|
|
|
|
2019-03-14 05:29:54 +01:00
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
2014-05-21 05:03:45 +02:00
|
|
|
|
2019-03-14 05:29:54 +01:00
|
|
|
namespace Kernel {
|
2015-01-23 02:12:19 +01:00
|
|
|
|
2018-04-20 21:42:29 +02:00
|
|
|
class Mutex final {
|
2015-01-23 02:12:19 +01:00
|
|
|
public:
|
2019-03-14 05:29:54 +01:00
|
|
|
explicit Mutex(Core::System& system);
|
|
|
|
~Mutex();
|
|
|
|
|
2018-04-20 19:01:14 +02:00
|
|
|
/// Flag that indicates that a mutex still has threads waiting for it.
|
|
|
|
static constexpr u32 MutexHasWaitersFlag = 0x40000000;
|
|
|
|
/// Mask of the bits in a mutex address value that contain the mutex owner.
|
|
|
|
static constexpr u32 MutexOwnerMask = 0xBFFFFFFF;
|
|
|
|
|
|
|
|
/// Attempts to acquire a mutex at the specified address.
|
2019-03-14 05:29:54 +01:00
|
|
|
ResultCode TryAcquire(VAddr address, Handle holding_thread_handle,
|
|
|
|
Handle requesting_thread_handle);
|
2018-04-20 19:01:14 +02:00
|
|
|
|
2020-02-25 22:37:12 +01:00
|
|
|
/// Unlocks a mutex for owner at address
|
2020-05-09 00:53:13 +02:00
|
|
|
std::pair<ResultCode, std::shared_ptr<Thread>> Unlock(std::shared_ptr<Thread> owner,
|
|
|
|
VAddr address);
|
2020-02-25 22:37:12 +01:00
|
|
|
|
2018-04-20 19:01:14 +02:00
|
|
|
/// Releases the mutex at the specified address.
|
2019-03-14 05:29:54 +01:00
|
|
|
ResultCode Release(VAddr address);
|
2018-04-20 19:01:14 +02:00
|
|
|
|
2015-01-23 02:12:19 +01:00
|
|
|
private:
|
2019-03-14 05:29:54 +01:00
|
|
|
Core::System& system;
|
2015-01-23 02:12:19 +01:00
|
|
|
};
|
2014-05-21 05:03:45 +02:00
|
|
|
|
2018-01-01 20:02:26 +01:00
|
|
|
} // namespace Kernel
|