mutex.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 final : 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 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. int lock_count; ///< Number of times the mutex has been acquired
  24. std::string name; ///< Name of mutex (optional)
  25. SharedPtr<Thread> holding_thread; ///< Thread that has acquired the mutex
  26. bool ShouldWait() override;
  27. void Acquire() override;
  28. /**
  29. * Acquires the specified mutex for the specified thread
  30. * @param thread Thread that will acquire the mutex
  31. */
  32. void Acquire(SharedPtr<Thread> thread);
  33. void Release();
  34. private:
  35. Mutex();
  36. ~Mutex() override;
  37. };
  38. /**
  39. * Releases all the mutexes held by the specified thread
  40. * @param thread Thread that is holding the mutexes
  41. */
  42. void ReleaseThreadMutexes(Thread* thread);
  43. } // namespace