void bt_gap_unref(struct bt_gap *gap) { if (!gap) return; if (__sync_sub_and_fetch(&gap->ref_count, 1)) return; gap->mgmt_ready = false; mgmt_cancel_all(gap->mgmt); mgmt_unregister_all(gap->mgmt); if (gap->ready_destroy) gap->ready_destroy(gap->ready_data); mgmt_unref(gap->mgmt); free(gap); }
void mgmt_unref(struct mgmt *mgmt) { if (!mgmt) return; if (__sync_sub_and_fetch(&mgmt->ref_count, 1)) return; mgmt_unregister_all(mgmt); mgmt_cancel_all(mgmt); g_queue_free(mgmt->reply_queue); g_queue_free(mgmt->request_queue); if (mgmt->write_watch > 0) g_source_remove(mgmt->write_watch); if (mgmt->read_watch > 0) g_source_remove(mgmt->read_watch); g_io_channel_unref(mgmt->io); mgmt->io = NULL; if (mgmt->close_on_unref) close(mgmt->fd); if (mgmt->debug_destroy) mgmt->debug_destroy(mgmt->debug_data); g_free(mgmt->buf); mgmt->buf = NULL; if (!mgmt->in_notify) { g_free(mgmt); return; } mgmt->destroyed = true; }
void mgmt_unref(struct mgmt *mgmt) { if (!mgmt) return; if (__sync_sub_and_fetch(&mgmt->ref_count, 1)) return; mgmt_unregister_all(mgmt); mgmt_cancel_all(mgmt); queue_destroy(mgmt->reply_queue, NULL); queue_destroy(mgmt->request_queue, NULL); io_set_write_handler(mgmt->io, NULL, NULL, NULL); io_set_read_handler(mgmt->io, NULL, NULL, NULL); io_destroy(mgmt->io); mgmt->io = NULL; if (mgmt->close_on_unref) close(mgmt->fd); if (mgmt->debug_destroy) mgmt->debug_destroy(mgmt->debug_data); free(mgmt->buf); mgmt->buf = NULL; if (!mgmt->in_notify) { queue_destroy(mgmt->notify_list, NULL); queue_destroy(mgmt->pending_list, NULL); free(mgmt); return; } mgmt->destroyed = true; }