/* This file defines the implementation of the Bridge class, a monitor-style
 * class for modeling cars going in two directions crossing a one-lane bridge.
 * It is incomplete at the moment - it bundles together state with a single
 * mutex, but the state is currently public and it doesn't implement any
 * of the multithreading logic.
 */

#ifndef BRIDGE_H
#define BRIDGE_H

#include <condition_variable>
#include <mutex>
#include <string>

class Bridge {
public:
    // Synchronizes access to all information in this object.
    std::mutex bridge_lock;

    // Number of cars currently crossing in each direction (only one of
    // these can be nonzero at any given time).
    size_t n_crossing_eastbound = 0;
    size_t n_crossing_westbound = 0;

    // Signaled to indicate that there are no longer any cars crossing
    // in the eastbound direction.
    std::condition_variable_any none_crossing_eastbound;

    // Signaled to indicate that there are no longer any cars crossing
    // in the westbound direction.
    std::condition_variable_any none_crossing_westbound;
};

#endif /* BRIDGE_H */
