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 --- doc/reference/CrystFEL-sections.txt | 2 ++ src/reflist.c | 27 +++++++++++++++++++++++++++ src/reflist.h | 2 ++ 3 files changed, 31 insertions(+) diff --git a/doc/reference/CrystFEL-sections.txt b/doc/reference/CrystFEL-sections.txt index 62acf0d8..060ecf97 100644 --- a/doc/reference/CrystFEL-sections.txt +++ b/doc/reference/CrystFEL-sections.txt @@ -45,6 +45,8 @@ set_temp2 copy_data num_reflections tree_depth +lock_reflection +unlock_reflection
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); +} diff --git a/src/reflist.h b/src/reflist.h index a49d4a61..65c8ef0b 100644 --- a/src/reflist.h +++ b/src/reflist.h @@ -103,5 +103,7 @@ extern Reflection *next_refl(Reflection *refl, RefListIterator *iter); /* Misc */ extern int num_reflections(RefList *list); extern int tree_depth(RefList *list); +extern void lock_reflection(Reflection *refl); +extern void unlock_reflection(Reflection *refl); #endif /* REFLIST_H */ -- cgit v1.2.3