summaryrefslogtreecommitdiff
blob: c9bfc2a263697ea8da5a8831e5af500b51ace7f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h> /* defines SIZE_MAX */

#include "../pipe/pipe.h"

#include "knowledge.h"

/** Basic functions of the ZoO_knowledge structure ****************************/

/* See: "knowledge.h" */
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;

   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
(
   struct ZoO_knowledge k [const restrict static 1],
   const struct ZoO_pipe io [const restrict static 1]
)
{
   return pthread_mutex_lock(&(k->mutex));
}

void ZoO_knowledge_unlock_access
(
   struct ZoO_knowledge k [const restrict static 1],
   const struct ZoO_pipe io [const restrict static 1]
)
{
   pthread_mutex_unlock(&(k->mutex));
}