synchronization_object.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <algorithm>
  5. #include "common/assert.h"
  6. #include "common/common_types.h"
  7. #include "common/logging/log.h"
  8. #include "core/core.h"
  9. #include "core/hle/kernel/kernel.h"
  10. #include "core/hle/kernel/object.h"
  11. #include "core/hle/kernel/process.h"
  12. #include "core/hle/kernel/synchronization.h"
  13. #include "core/hle/kernel/synchronization_object.h"
  14. #include "core/hle/kernel/thread.h"
  15. namespace Kernel {
  16. SynchronizationObject::SynchronizationObject(KernelCore& kernel) : Object{kernel} {}
  17. SynchronizationObject::~SynchronizationObject() = default;
  18. void SynchronizationObject::Signal() {
  19. kernel.Synchronization().SignalObject(*this);
  20. }
  21. void SynchronizationObject::AddWaitingThread(std::shared_ptr<Thread> thread) {
  22. auto itr = std::find(waiting_threads.begin(), waiting_threads.end(), thread);
  23. if (itr == waiting_threads.end())
  24. waiting_threads.push_back(std::move(thread));
  25. }
  26. void SynchronizationObject::RemoveWaitingThread(std::shared_ptr<Thread> thread) {
  27. auto itr = std::find(waiting_threads.begin(), waiting_threads.end(), thread);
  28. // If a thread passed multiple handles to the same object,
  29. // the kernel might attempt to remove the thread from the object's
  30. // waiting threads list multiple times.
  31. if (itr != waiting_threads.end())
  32. waiting_threads.erase(itr);
  33. }
  34. void SynchronizationObject::ClearWaitingThreads() {
  35. waiting_threads.clear();
  36. }
  37. const std::vector<std::shared_ptr<Thread>>& SynchronizationObject::GetWaitingThreads() const {
  38. return waiting_threads;
  39. }
  40. } // namespace Kernel