sgx_condition_variable.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //===-------------------- condition_variable.cpp --------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "__config"
  10. #include "condition_variable"
  11. #include "system_error"
  12. #include "cassert"
  13. _LIBCPP_BEGIN_NAMESPACE_STD
  14. condition_variable::~condition_variable()
  15. {
  16. sgx_thread_cond_destroy(&__cv_);
  17. }
  18. void
  19. condition_variable::notify_one() _NOEXCEPT
  20. {
  21. sgx_thread_cond_signal(&__cv_);
  22. }
  23. void
  24. condition_variable::notify_all() _NOEXCEPT
  25. {
  26. sgx_thread_cond_broadcast(&__cv_);
  27. }
  28. void
  29. condition_variable::wait(unique_lock<mutex>& lk) _NOEXCEPT
  30. {
  31. if (!lk.owns_lock())
  32. __throw_system_error(EPERM,
  33. "condition_variable::wait: mutex not locked");
  34. int ec = sgx_thread_cond_wait(&__cv_, lk.mutex()->native_handle());
  35. if (ec)
  36. __throw_system_error(ec, "condition_variable wait failed");
  37. }
  38. _LIBCPP_END_NAMESPACE_STD