summaryrefslogtreecommitdiffstats
path: root/contrib/restricted/aws/aws-c-common/source/promise.c
diff options
context:
space:
mode:
authorshadchin <[email protected]>2024-12-03 17:05:42 +0300
committershadchin <[email protected]>2024-12-03 18:21:15 +0300
commit6388569551ef4720bdcd3f07af43fedbecabc847 (patch)
tree279445f9bbee9b4f7b518fde918e49b4c00566c0 /contrib/restricted/aws/aws-c-common/source/promise.c
parent528eb8de83d25bf28f3d4a1202155523477ad4ac (diff)
Update contrib/restricted/aws/aws-c-common to 0.8.23
commit_hash:ee9e58d849fe0a4add15cf37c9a8899e88291b18
Diffstat (limited to 'contrib/restricted/aws/aws-c-common/source/promise.c')
-rw-r--r--contrib/restricted/aws/aws-c-common/source/promise.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/contrib/restricted/aws/aws-c-common/source/promise.c b/contrib/restricted/aws/aws-c-common/source/promise.c
index 444623d625d..7c8572457ea 100644
--- a/contrib/restricted/aws/aws-c-common/source/promise.c
+++ b/contrib/restricted/aws/aws-c-common/source/promise.c
@@ -82,8 +82,11 @@ void aws_promise_complete(struct aws_promise *promise, void *value, void (*dtor)
promise->value = value;
promise->dtor = dtor;
promise->complete = true;
- aws_mutex_unlock(&promise->mutex);
+ /* Notify before unlocking to prevent a race condition where the recipient spuriously
+ * awakens after the unlock, sees a fulfilled promise, and attempts to free its resources
+ * before the notification has actually occured. */
aws_condition_variable_notify_all(&promise->cv);
+ aws_mutex_unlock(&promise->mutex);
}
void aws_promise_fail(struct aws_promise *promise, int error_code) {
@@ -92,8 +95,8 @@ void aws_promise_fail(struct aws_promise *promise, int error_code) {
AWS_FATAL_ASSERT(!promise->complete && "aws_promise_fail: cannot complete a promise more than once");
promise->error_code = error_code;
promise->complete = true;
- aws_mutex_unlock(&promise->mutex);
aws_condition_variable_notify_all(&promise->cv);
+ aws_mutex_unlock(&promise->mutex);
}
int aws_promise_error_code(struct aws_promise *promise) {