Skip to content
Snippets Groups Projects
Commit d3062e61 authored by Tim Wickberg's avatar Tim Wickberg
Browse files

Add verify_lock() function.

Allows for annotations such as
xassert(verify_lock(CONFIG_LOCK, READ_LOCK));
to ensure that the calling thread has the correct locks in
place to head off potential race conditions / corruption.
parent 4167c253
No related branches found
No related tags found
No related merge requests found
......@@ -102,6 +102,11 @@ static bool _clear_locks(slurmctld_lock_t lock_levels)
return true;
}
extern bool verify_lock(lock_datatype_t datatype, lock_level_t level)
{
return (((lock_level_t *) &thread_locks)[datatype] >= level);
}
#endif
/* init_locks - create locks used for slurmctld data structure access
......
......@@ -91,6 +91,8 @@
#ifndef _SLURMCTLD_LOCKS_H
#define _SLURMCTLD_LOCKS_H
#include <stdbool.h>
/* levels of locking required for each data structure */
typedef enum {
NO_LOCK,
......@@ -125,6 +127,10 @@ typedef enum {
ENTITY_COUNT
} lock_datatype_t;
#ifndef NDEBUG
extern bool verify_lock(lock_datatype_t datatype, lock_level_t level);
#endif
#define read_lock(data_type) (data_type * 4 + 0)
#define write_lock(data_type) (data_type * 4 + 1)
#define write_wait_lock(data_type) (data_type * 4 + 2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment