summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-01-31 16:21:24 +0100
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-01-31 16:21:24 +0100
commit509ac16d892aeb5091f68620247f6815d2e4b5f5 (patch)
treec4adebce7791c10c4c362b77f32d4a339e8c8125 /src/knowledge/knowledge.c
parent1373211465c34015ee900e097aa87fbffb401187 (diff)
Switched to sockets, continuing implementation...
Diffstat (limited to 'src/knowledge/knowledge.c')
-rw-r--r--src/knowledge/knowledge.c26
1 files changed, 22 insertions, 4 deletions
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 <stdlib.h>
#include <string.h>
+#include <stdio.h>
#include <stdint.h> /* 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));
}