condition_variable.c 918 B

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/common/condition_variable.h>
  6. int aws_condition_variable_wait_pred(
  7. struct aws_condition_variable *condition_variable,
  8. struct aws_mutex *mutex,
  9. aws_condition_predicate_fn *pred,
  10. void *pred_ctx) {
  11. int err_code = 0;
  12. while (!err_code && !pred(pred_ctx)) {
  13. err_code = aws_condition_variable_wait(condition_variable, mutex);
  14. }
  15. return err_code;
  16. }
  17. int aws_condition_variable_wait_for_pred(
  18. struct aws_condition_variable *condition_variable,
  19. struct aws_mutex *mutex,
  20. int64_t time_to_wait,
  21. aws_condition_predicate_fn *pred,
  22. void *pred_ctx) {
  23. int err_code = 0;
  24. while (!err_code && !pred(pred_ctx)) {
  25. err_code = aws_condition_variable_wait_for(condition_variable, mutex, time_to_wait);
  26. }
  27. return err_code;
  28. }