condition_variable.cpp 784 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-04-27 flybreak the first version.
  9. */
  10. #include "condition_variable"
  11. namespace std
  12. {
  13. void condition_variable::wait(unique_lock<mutex>& lock)
  14. {
  15. int err = pthread_cond_wait(&_m_cond, lock.mutex()->native_handle());
  16. if (err)
  17. {
  18. throw_system_error(err, "condition_variable::wait: failed to wait on a condition");
  19. }
  20. }
  21. void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk)
  22. {
  23. // TLS currently not available
  24. mutex* mut = lk.release();
  25. mut->unlock();
  26. cond.notify_all();
  27. }
  28. } // namespace std