mutex.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <string>
  6. #include "common/common_types.h"
  7. #include "core/hle/kernel/kernel.h"
  8. namespace Kernel {
  9. class Thread;
  10. class Mutex : public WaitObject {
  11. public:
  12. /**
  13. * Creates a mutex.
  14. * @param initial_locked Specifies if the mutex should be locked initially
  15. * @param name Optional name of mutex
  16. * @return Pointer to new Mutex object
  17. */
  18. static ResultVal<SharedPtr<Mutex>> Create(bool initial_locked, std::string name = "Unknown");
  19. std::string GetTypeName() const override { return "Mutex"; }
  20. std::string GetName() const override { return name; }
  21. static const HandleType HANDLE_TYPE = HandleType::Mutex;
  22. HandleType GetHandleType() const override { return HANDLE_TYPE; }
  23. bool initial_locked; ///< Initial lock state when mutex was created
  24. bool locked; ///< Current locked state
  25. std::string name; ///< Name of mutex (optional)
  26. SharedPtr<Thread> holding_thread; ///< Thread that has acquired the mutex
  27. bool ShouldWait() override;
  28. void Acquire() override;
  29. /**
  30. * Acquires the specified mutex for the specified thread
  31. * @param mutex Mutex that is to be acquired
  32. * @param thread Thread that will acquire the mutex
  33. */
  34. void Acquire(Thread* thread);
  35. void Release();
  36. private:
  37. Mutex() = default;
  38. };
  39. /**
  40. * Releases all the mutexes held by the specified thread
  41. * @param thread Thread that is holding the mutexes
  42. */
  43. void ReleaseThreadMutexes(Thread* thread);
  44. } // namespace