X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-session.c;h=8f8076156956feb5b1e90a966af75512d5717321;hb=f26355dd547b32124ce6439ad48487cb71278c76;hp=3befb92ec1c69ef63216876197aeab39431c4c69;hpb=5bffa91c6c719b828a317adfb913ce57dbb2c6f0;p=src%2Fapp-framework-binder.git diff --git a/src/afb-session.c b/src/afb-session.c index 3befb92e..8f807615 100644 --- a/src/afb-session.c +++ b/src/afb-session.c @@ -161,6 +161,7 @@ static void destroy (struct afb_session *session) assert (session != NULL); + remove_all_cookies(session); pthread_mutex_lock(&sessions.mutex); prv = &sessions.heads[(int)session->idx]; while (*prv) @@ -293,6 +294,8 @@ struct afb_session *afb_session_search (const char *uuid) pthread_mutex_lock(&sessions.mutex); cleanup(); session = search(uuid, pearson4(uuid)); + if (session) + __atomic_add_fetch(&session->refcount, 1, __ATOMIC_RELAXED); pthread_mutex_unlock(&sessions.mutex); return session; @@ -315,7 +318,7 @@ struct afb_session *afb_session_get (const char *uuid, int timeout, int *created else { idx = pearson4(uuid); session = search(uuid, idx); - if (session != NULL) { + if (session) { __atomic_add_fetch(&session->refcount, 1, __ATOMIC_RELAXED); pthread_mutex_unlock(&sessions.mutex); if (created) @@ -346,8 +349,11 @@ void afb_session_unref(struct afb_session *session) if (session != NULL) { assert(session->refcount != 0); if (!__atomic_sub_fetch(&session->refcount, 1, __ATOMIC_RELAXED)) { + pthread_mutex_lock(&session->mutex); if (session->uuid[0] == 0) destroy (session); + else + pthread_mutex_unlock(&session->mutex); } } } @@ -356,12 +362,16 @@ void afb_session_unref(struct afb_session *session) void afb_session_close (struct afb_session *session) { assert(session != NULL); + pthread_mutex_lock(&session->mutex); if (session->uuid[0] != 0) { session->uuid[0] = 0; - remove_all_cookies(session); - if (session->refcount == 0) + remove_all_cookies(session); + if (session->refcount == 0) { destroy (session); + return; + } } + pthread_mutex_unlock(&session->mutex); } // Sample Generic Ping Debug API