Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove callback severance on 5-to-3 adapter #329

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 6 additions & 26 deletions include/aws/mqtt/private/v5/mqtt5_to_mqtt3_adapter_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ enum aws_mqtt5_to_mqtt3_adapter_operation_type {
AWS_MQTT5TO3_AOT_UNSUBSCRIBE,
};

struct aws_mqtt5_to_mqtt3_adapter_operation_vtable {
void (*fail_fn)(void *impl, int error_code);
};

struct aws_mqtt5_to_mqtt3_adapter_operation_base {
struct aws_allocator *allocator;
struct aws_ref_count ref_count;
const struct aws_mqtt5_to_mqtt3_adapter_operation_vtable *vtable;

void *impl;

/*
Expand Down Expand Up @@ -224,15 +230,6 @@ struct aws_mqtt_client_connection_5_impl {
struct aws_mqtt5_listener *listener;
struct aws_event_loop *loop;

/*
* An event-loop-internal flag that we can read to check to see if we're in the scope of a callback
* that has already locked the adapter's lock. Can only be referenced from the event loop thread.
*
* We use the flag to avoid deadlock in a few cases where we can re-enter the adapter logic from within a callback.
* It also provides a nice solution for the fact that we cannot safely upgrade a read lock to a write lock.
*/
bool in_synchronous_callback;

/*
* The current adapter state based on the sequence of connect(), disconnect(), and connection completion events.
* This affects how the adapter reacts to incoming mqtt5 events. Under certain conditions, we may change
Expand Down Expand Up @@ -260,23 +257,6 @@ struct aws_mqtt_client_connection_5_impl {
*/
struct aws_ref_count internal_refs;

/*
* We use the adapter lock to guarantee that we can synchronously sever all callbacks from the mqtt5 client even
* though adapter shutdown is an asynchronous process. This means the lock is held during callbacks which is a
* departure from our normal usage patterns. We prevent deadlock (due to logical re-entry) by using the
* in_synchronous_callback flag.
*
* We hold a read lock when invoking callbacks and a write lock when setting terminated from false to true.
*/
struct aws_rw_lock lock;

/*
* Synchronized data protected by the adapter lock.
*/
struct {
bool terminated;
} synced_data;

struct aws_mqtt5_to_mqtt3_adapter_operation_table operational_state;

struct aws_mqtt_subscription_set *subscriptions;
Expand Down
Loading