From cb07198d95b9fa84474f624af0eda8ae97960a70 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Mon, 26 Nov 2018 00:24:34 +0100 Subject: Created a lock for collections. --- src/core/collections.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/collections.c b/src/core/collections.c index 2f28857..d045e5a 100644 --- a/src/core/collections.c +++ b/src/core/collections.c @@ -43,7 +43,7 @@ static GType *_collection_definitions = NULL; static uint32_t _collection_definitions_count = 0; /* Verrou pour des accès atomiques */ -/* ... */ +G_LOCK_DEFINE_STATIC(_collec_mutex); @@ -63,7 +63,7 @@ uint32_t register_collection_type(GType items) { uint32_t result; /* Identifiant à retourner */ - /* TODO : lock */ + G_LOCK(_collec_mutex); result = _collection_definitions_count++; @@ -72,7 +72,7 @@ uint32_t register_collection_type(GType items) _collection_definitions[result] = items; - /* TODO : unlock */ + G_UNLOCK(_collec_mutex); return result; @@ -168,6 +168,8 @@ GList *create_collections_list(void) result = NULL; + G_LOCK(_collec_mutex); + for (i = 0; i < _collection_definitions_count; i++) { collec = g_object_new(_collection_definitions[i], NULL); @@ -176,6 +178,8 @@ GList *create_collections_list(void) } + G_UNLOCK(_collec_mutex); + return result; } -- cgit v0.11.2-87-g4458