vg
tools for working with variation graphs
|
#include <graph_synchronizer.hpp>
Classes | |
class | Lock |
Public Member Functions | |
GraphSynchronizer (VG &graph) | |
const string & | get_path_sequence (const string &path_name) |
void | with_path_index (const string &path_name, const function< void(const PathIndex &)> &to_run) |
Protected Member Functions | |
PathIndex & | get_path_index (const string &path_name) |
void | update_path_indexes (const vector< Translation > &translations) |
Protected Attributes | |
VG & | graph |
The graph we manage. More... | |
mutex | whole_graph_lock |
condition_variable | wait_for_region |
map< string, PathIndex > | indexes |
set< id_t > | locked_nodes |
This holds all the node IDs that are currently locked by someone. More... | |
Let threads get exclusive locks on subgraphs of a vg graph, for reading and editing. Whan a subgraph is locked, a copy is accessible through the lock object and the underlying graph can be edited (through the lock) without affecting any other locked subgraphs.
A thread may only hold a lock on a single subgraph at a time. Trying to lock another subgraph while you already have a subgraph locked is likely to result in a deadlock.
vg::GraphSynchronizer::GraphSynchronizer | ( | VG & | graph | ) |
Create a GraphSynchronizer for synchronizing on parts of the given graph.
|
protected |
Get the index for the given path name. Lock on the indexes and graph must be held already.
const string & vg::GraphSynchronizer::get_path_sequence | ( | const string & | path_name | ) |
Since internally we keep PathIndexes for paths in the graph, we expose this method for getting the strings for paths.
|
protected |
Update all the path indexes according to the given translations. Lock on the indexes and graph must be held already.
void vg::GraphSynchronizer::with_path_index | ( | const string & | path_name, |
const function< void(const PathIndex &)> & | to_run | ||
) |
We can actually let users run whatever function they want with an exclusive handle on a PathIndex, with the guarantee that the graph won't change while they're working.
|
protected |
The graph we manage.
|
protected |
We need indexes of all the paths that someone might want to use as a basis for locking. This holds a PathIndex for each path we touch by path name.
|
protected |
This holds all the node IDs that are currently locked by someone.
|
protected |
We have one condition variable where we have blocked all the threads that are waiting to lock subgraphs but couldn't the first time because we ran into already locked nodes. When nodes get unlocked, we wake them all up, and they each grab the mutex and check, one at a time, to see if they can have all their nodes this time.
|
protected |
We use this to lock the whole graph, for when we're exploring and trying to lock a context, or for when we're making an edit, or for when we're trying to lock a context, or for when we're working with the PathIndexes. It's only ever held during functions in this class or internal classes (monitor-style), so we don't need it to be a recursive mutex.