1 | /* |
2 | * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"). |
5 | * You may not use this file except in compliance with the License. |
6 | * A copy of the License is located at |
7 | * |
8 | * http://aws.amazon.com/apache2.0 |
9 | * |
10 | * or in the "license" file accompanying this file. This file is distributed |
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
12 | * express or implied. See the License for the specific language governing |
13 | * permissions and limitations under the License. |
14 | */ |
15 | |
16 | #include <aws/common/condition_variable.h> |
17 | |
18 | int aws_condition_variable_wait_pred( |
19 | struct aws_condition_variable *condition_variable, |
20 | struct aws_mutex *mutex, |
21 | aws_condition_predicate_fn *pred, |
22 | void *pred_ctx) { |
23 | |
24 | int err_code = 0; |
25 | while (!err_code && !pred(pred_ctx)) { |
26 | err_code = aws_condition_variable_wait(condition_variable, mutex); |
27 | } |
28 | |
29 | return err_code; |
30 | } |
31 | |
32 | int aws_condition_variable_wait_for_pred( |
33 | struct aws_condition_variable *condition_variable, |
34 | struct aws_mutex *mutex, |
35 | int64_t time_to_wait, |
36 | aws_condition_predicate_fn *pred, |
37 | void *pred_ctx) { |
38 | |
39 | int err_code = 0; |
40 | while (!err_code && !pred(pred_ctx)) { |
41 | err_code = aws_condition_variable_wait_for(condition_variable, mutex, time_to_wait); |
42 | } |
43 | |
44 | return err_code; |
45 | } |
46 | |