Skip to content

Commit

Permalink
aws-crt-ffi v0.3.7 -> v0.3.8 (#112)
Browse files Browse the repository at this point in the history
Also: replace uses of `aws_promise` (removed in awslabs/aws-c-common#1110) with `aws_future`
  • Loading branch information
graebm committed Jun 13, 2024
1 parent 0ea1f04 commit a63485b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
22 changes: 11 additions & 11 deletions ext/crt.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ bool aws_php_thread_queue_drain(aws_php_thread_queue *queue) {
}

/* called on main thread after delivery */
static void s_thread_queue_complete_promise(void *data) {
struct aws_promise *promise = data;
aws_promise_complete(promise, NULL, NULL);
static void s_thread_queue_complete_future(void *data) {
struct aws_future_void *future = data;
aws_future_void_set_result(future);
}

/* called from worker thread to wait for the main thread to execute any queued work in PHP */
Expand All @@ -206,21 +206,21 @@ void aws_php_thread_queue_yield(aws_php_thread_queue *queue) {
if (aws_php_is_main_thread()) {
aws_php_thread_queue_drain(queue);
} else {
/* push a task onto the end of the queue, we will return once this task completes our promise */
struct aws_promise *queue_drained = aws_promise_new(aws_crt_default_allocator());
/* push a task onto the end of the queue, we will return once this task completes our future */
struct aws_future_void *queue_drained = aws_future_void_new(aws_crt_default_allocator());
aws_php_task queue_drained_task = {
.callback = s_thread_queue_complete_promise,
.callback = s_thread_queue_complete_future,
.data = queue_drained,
};
aws_php_thread_queue_push(queue, queue_drained_task);
aws_promise_wait(queue_drained);
aws_promise_release(queue_drained);
aws_future_void_wait(queue_drained, UINT64_MAX /*timeout*/);
aws_future_void_release(queue_drained);
}
}

/* called from PHP thread to wait on async queued jobs, one of which should complete the promise */
void aws_php_thread_queue_wait(aws_php_thread_queue *queue, struct aws_promise *promise) {
while (!aws_promise_is_complete(promise)) {
/* called from PHP thread to wait on async queued jobs, one of which should complete the future */
void aws_php_thread_queue_wait(aws_php_thread_queue *queue, struct aws_future_void *future) {
while (!aws_future_void_is_done(future)) {
aws_php_thread_queue_drain(queue);
}
}
Expand Down
6 changes: 3 additions & 3 deletions ext/php_aws_crt.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#include <aws/common/common.h>
#include <aws/common/mutex.h>
#include <aws/common/promise.h>
#include <aws/common/thread.h>
#include <aws/io/future.h>

/* ZEND_EXTENSION_API_NO from each branch of the PHP source */
#define AWS_PHP_EXTENSION_API_5_5 220121212
Expand Down Expand Up @@ -162,8 +162,8 @@ bool aws_php_thread_queue_drain(aws_php_thread_queue *queue);
/* called from worker thread to wait for the main thread to execute any queued work in PHP */
void aws_php_thread_queue_yield(aws_php_thread_queue *queue);

/* called from PHP thread to wait on async queued jobs, one of which MUST complete the promise */
void aws_php_thread_queue_wait(aws_php_thread_queue *queue, struct aws_promise *promise);
/* called from PHP thread to wait on async queued jobs, one of which MUST complete the future */
void aws_php_thread_queue_wait(aws_php_thread_queue *queue, struct aws_future_void *future);

/**
* generic dispatch mechanism to call a callback provided as a zval with arguments
Expand Down
18 changes: 9 additions & 9 deletions ext/signing.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ PHP_FUNCTION(aws_crt_signing_result_apply_to_http_request) {
}

typedef struct _signing_state {
struct aws_promise *promise;
struct aws_future_void *future;
zval *on_complete;
aws_crt_signing_result *signing_result;
int error_code;
Expand All @@ -284,7 +284,7 @@ static void s_sign_aws_complete(void *data) {
/* called from signing process in aws_sign_request_aws */
static void s_on_sign_request_aws_complete(aws_crt_signing_result *result, int error_code, void *user_data) {
signing_state *state = user_data;
struct aws_promise *promise = state->promise;
struct aws_future_void *future = state->future;

state->signing_result = result;
state->error_code = error_code;
Expand All @@ -301,9 +301,9 @@ static void s_on_sign_request_aws_complete(aws_crt_signing_result *result, int e
aws_php_thread_queue_yield(&s_aws_php_main_thread_queue);

if (error_code) {
aws_promise_fail(promise, error_code);
aws_future_void_set_error(future, error_code);
} else {
aws_promise_complete(promise, result, NULL);
aws_future_void_set_result(future);
}
}

Expand All @@ -318,23 +318,23 @@ PHP_FUNCTION(aws_crt_sign_request_aws) {
aws_crt_signable *signable = (void *)php_signable;
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;

struct aws_promise *promise = aws_promise_new(aws_crt_default_allocator());
struct aws_future_void *future = aws_future_void_new(aws_crt_default_allocator());
signing_state state = {
.promise = promise,
.future = future,
.on_complete = php_on_complete,
};
int ret = aws_crt_sign_request_aws(signable, signing_config, s_on_sign_request_aws_complete, &state);
if (ret != 0) {
int last_error = aws_crt_last_error();
aws_promise_fail(promise, last_error);
aws_future_void_set_error(future, last_error);
aws_php_throw_exception(
"aws_crt_sign_request_aws: error starting signing process: %s", aws_crt_error_name(last_error));
}

aws_php_thread_queue_wait(&s_aws_php_main_thread_queue, promise);
aws_php_thread_queue_wait(&s_aws_php_main_thread_queue, future);

done:
aws_promise_release(promise);
aws_future_void_release(future);
RETURN_LONG(ret);
}

Expand Down

0 comments on commit a63485b

Please sign in to comment.