aboutsummaryrefslogtreecommitdiff
path: root/src/reflist.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2011-09-27 13:25:14 +0200
committerThomas White <taw@physics.org>2012-02-22 15:27:37 +0100
commit6a55e3eb4d60eaec704d9525ad4f17628004b38b (patch)
treed75783df703fd7f7fb74b71eb983cbde960946fd /src/reflist.c
parentbebd2d95386b057403326ebf438d660522875e4e (diff)
Add a mutex for each Reflection
Diffstat (limited to 'src/reflist.c')
-rw-r--r--src/reflist.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/reflist.c b/src/reflist.c
index 45cd132e..d17dca2f 100644
--- a/src/reflist.c
+++ b/src/reflist.c
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
+#include <pthread.h>
#include "reflist.h"
#include "utils.h"
@@ -103,6 +104,7 @@ struct _reflection {
enum _nodecol col; /* Colour (red or black) */
/* Payload */
+ pthread_mutex_t lock; /* Protects the contents of "data" */
struct _refldata data;
};
@@ -133,6 +135,7 @@ static Reflection *new_node(unsigned int serial)
new->child[0] = NULL;
new->child[1] = NULL;
new->col = RED;
+ pthread_mutex_init(&new->lock, NULL);
return new;
}
@@ -959,3 +962,27 @@ int tree_depth(RefList *list)
{
return recursive_depth(list->head);
}
+
+
+/**
+ * lock_reflection:
+ * @refl: A %Reflection
+ *
+ * Acquires a lock on the reflection.
+ */
+void lock_reflection(Reflection *refl)
+{
+ pthread_mutex_lock(&refl->lock);
+}
+
+
+/**
+ * unlock_reflection:
+ * @refl: A %Reflection
+ *
+ * Releases a lock on the reflection.
+ */
+void unlock_reflection(Reflection *refl)
+{
+ pthread_mutex_unlock(&refl->lock);
+}