From 509ac16d892aeb5091f68620247f6815d2e4b5f5 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Tue, 31 Jan 2017 16:21:24 +0100 Subject: Switched to sockets, continuing implementation... --- src/knowledge/knowledge.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/knowledge/knowledge.c') diff --git a/src/knowledge/knowledge.c b/src/knowledge/knowledge.c index 463d40b..c9bfc2a 100644 --- a/src/knowledge/knowledge.c +++ b/src/knowledge/knowledge.c @@ -1,5 +1,6 @@ #include #include +#include #include /* defines SIZE_MAX */ #include "../pipe/pipe.h" @@ -9,8 +10,10 @@ /** Basic functions of the ZoO_knowledge structure ****************************/ /* See: "knowledge.h" */ -void ZoO_knowledge_initialize (struct ZoO_knowledge k [const static 1]) +int ZoO_knowledge_initialize (struct ZoO_knowledge k [const restrict static 1]) { + int error; + k->words = (struct ZoO_knowledge_word *) NULL; k->words_length = 0; k->words_sorted = (ZoO_index *) NULL; @@ -18,6 +21,22 @@ void ZoO_knowledge_initialize (struct ZoO_knowledge k [const static 1]) k->sequences = (ZoO_index **) NULL; k->sequences_length = 0; k->sequences_sorted = (ZoO_index *) NULL; + + error = pthread_mutex_init(&(k->mutex), (const pthread_mutexattr_t *) NULL); + + if (error != 0) + { + fprintf + ( + stderr, + "[F] Unable to initialize knowledge mutex: %s.\n", + strerror(error) + ); + + return -1; + } + + return 0; } int ZoO_knowledge_lock_access @@ -26,8 +45,7 @@ int ZoO_knowledge_lock_access const struct ZoO_pipe io [const restrict static 1] ) { - /* TODO */ - return 0; + return pthread_mutex_lock(&(k->mutex)); } void ZoO_knowledge_unlock_access @@ -36,5 +54,5 @@ void ZoO_knowledge_unlock_access const struct ZoO_pipe io [const restrict static 1] ) { - /* TODO */ + pthread_mutex_unlock(&(k->mutex)); } -- cgit v1.2.3-70-g09d2