diff options
-rw-r--r-- | doc/reference/CrystFEL-sections.txt | 2 | ||||
-rw-r--r-- | src/reflist.c | 27 | ||||
-rw-r--r-- | src/reflist.h | 2 |
3 files changed, 31 insertions, 0 deletions
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 </SECTION> <SECTION> 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); +} 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 */ |