vg
tools for working with variation graphs
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
vg::GraphSynchronizer Class Reference

#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

PathIndexget_path_index (const string &path_name)
 
void update_path_indexes (const vector< Translation > &translations)
 

Protected Attributes

VGgraph
 The graph we manage. More...
 
mutex whole_graph_lock
 
condition_variable wait_for_region
 
map< string, PathIndexindexes
 
set< id_tlocked_nodes
 This holds all the node IDs that are currently locked by someone. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ GraphSynchronizer()

vg::GraphSynchronizer::GraphSynchronizer ( VG graph)

Create a GraphSynchronizer for synchronizing on parts of the given graph.

Member Function Documentation

◆ get_path_index()

PathIndex & vg::GraphSynchronizer::get_path_index ( const string &  path_name)
protected

Get the index for the given path name. Lock on the indexes and graph must be held already.

◆ get_path_sequence()

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.

◆ update_path_indexes()

void vg::GraphSynchronizer::update_path_indexes ( const vector< Translation > &  translations)
protected

Update all the path indexes according to the given translations. Lock on the indexes and graph must be held already.

◆ with_path_index()

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.

Member Data Documentation

◆ graph

VG& vg::GraphSynchronizer::graph
protected

The graph we manage.

◆ indexes

map<string, PathIndex> vg::GraphSynchronizer::indexes
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.

◆ locked_nodes

set<id_t> vg::GraphSynchronizer::locked_nodes
protected

This holds all the node IDs that are currently locked by someone.

◆ wait_for_region

condition_variable vg::GraphSynchronizer::wait_for_region
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.

◆ whole_graph_lock

mutex vg::GraphSynchronizer::whole_graph_lock
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.


The documentation for this class was generated from the following files: