mutex.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. 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(SharedPtr<Thread> thread);
  35. void Release();
  36. private:
  37. Mutex();
  38. ~Mutex() override;
  39. };
  40. /**
  41. * Releases all the mutexes held by the specified thread
  42. * @param thread Thread that is holding the mutexes
  43. */
  44. void ReleaseThreadMutexes(Thread* thread);
  45. } // namespace