Boost-Graph

 view release on metacpan or  search on metacpan

include/boost/thread/read_write_mutex.hpp  view on Meta::CPAN

// Copyright (C)  2002-2003
// David Moore, William E. Kempf, Michael Glassford
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without fee,
// provided that the above copyright notice appear in all copies and
// that both that copyright notice and this permission notice appear
// in supporting documentation.  David Moore makes no representations
// about the suitability of this software for any purpose.
// It is provided "as is" without express or implied warranty.

// A Boost::threads implementation of a synchronization
//   primitive which can allow multiple readers or a single
//   writer to have access to a shared resource.

#ifndef BOOST_READ_WRITE_MUTEX_JDM030602_HPP
#define BOOST_READ_WRITE_MUTEX_JDM030602_HPP

#include <boost/thread/detail/config.hpp>

#include <boost/utility.hpp>
#include <boost/detail/workaround.hpp>

#include <boost/thread/mutex.hpp>
#include <boost/thread/detail/lock.hpp>
#include <boost/thread/detail/read_write_lock.hpp>
#include <boost/thread/condition.hpp>

namespace boost {

namespace read_write_scheduling_policy {
    enum read_write_scheduling_policy_enum
    {
        writer_priority,               //Prefer writers; can starve readers
        reader_priority,               //Prefer readers; can starve writers
        alternating_many_reads,        //Alternate readers and writers; before a writer, release all queued readers 
        alternating_single_read        //Alternate readers and writers; before a writer, release only one queued reader
    };
} // namespace read_write_scheduling_policy

namespace detail {

namespace thread {

// Shared implementation construct for explicit Scheduling Policies
// This implementation is susceptible to self-deadlock, though....
template<typename Mutex>
struct read_write_mutex_impl
{
    typedef Mutex mutex_type;
    typedef detail::thread::scoped_lock<Mutex> scoped_lock;
    typedef detail::thread::scoped_try_lock<Mutex> scoped_try_lock;
    typedef detail::thread::scoped_timed_lock<Mutex> scoped_timed_lock;

    read_write_mutex_impl(read_write_scheduling_policy::read_write_scheduling_policy_enum sp);
#if !BOOST_WORKAROUND(__BORLANDC__,<= 0x564)
    ~read_write_mutex_impl();
#endif

    Mutex m_prot;

    const read_write_scheduling_policy::read_write_scheduling_policy_enum m_sp;
    int m_state; //-1 = write lock; 0 = unlocked; >0 = read locked

    boost::condition m_waiting_writers;
    boost::condition m_waiting_readers;
    boost::condition m_waiting_promotion;
    int m_num_waiting_writers;
    int m_num_waiting_readers;
    bool m_state_waiting_promotion;

    int m_num_waking_writers;



( run in 1.453 second using v1.01-cache-2.11-cpan-39bf76dae61 )