X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-session.c;h=536cdbccd46d6faa1e2c31cbc2035dc816122c12;hb=b192d4cc46d8bda166116432ee28042e95750052;hp=523cbf0444c9e298bd86e30efe79a7b306d3af66;hpb=142f890314a2279a383a70251e1579f277c408e3;p=src%2Fapp-framework-binder.git diff --git a/src/afb-session.c b/src/afb-session.c index 523cbf04..536cdbcc 100644 --- a/src/afb-session.c +++ b/src/afb-session.c @@ -324,7 +324,7 @@ struct afb_session *afb_session_get (const char *uuid, int *created) struct afb_session *afb_session_addref(struct afb_session *session) { if (session != NULL) - session->refcount++; + __atomic_add_fetch(&session->refcount, 1, __ATOMIC_RELAXED); return session; } @@ -332,11 +332,12 @@ void afb_session_unref(struct afb_session *session) { if (session != NULL) { assert(session->refcount != 0); - --session->refcount; - if (session->refcount == 0 && session->uuid[0] == 0) { - destroy (session); - pthread_mutex_destroy(&session->mutex); - free(session); + if (!__atomic_sub_fetch(&session->refcount, 1, __ATOMIC_RELAXED)) { + if (session->uuid[0] == 0) { + destroy (session); + pthread_mutex_destroy(&session->mutex); + free(session); + } } } }