From 6a55e3eb4d60eaec704d9525ad4f17628004b38b Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 27 Sep 2011 13:25:14 +0200 Subject: Add a mutex for each Reflection --- src/reflist.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/reflist.c') 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 #include #include +#include #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); +} -- cgit v1.2.3