File indexing completed on 2025-01-31 10:02:08
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_SPIRIT_UTILITY_SCOPED_LOCK_HPP
0009 #define BOOST_SPIRIT_UTILITY_SCOPED_LOCK_HPP
0010
0011
0012 #include <boost/spirit/home/classic/namespace.hpp>
0013 #include <boost/spirit/home/classic/core/composite/composite.hpp>
0014 #include <boost/thread/lock_types.hpp>
0015
0016
0017 namespace boost { namespace spirit {
0018
0019 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 template <typename MutexT, typename ParserT>
0030 struct scoped_lock_parser
0031 : public unary< ParserT, parser< scoped_lock_parser<MutexT, ParserT> > >
0032 {
0033 typedef scoped_lock_parser<MutexT, ParserT> self_t;
0034 typedef MutexT mutex_t;
0035 typedef ParserT parser_t;
0036
0037 template <typename ScannerT>
0038 struct result
0039 {
0040 typedef typename parser_result<parser_t, ScannerT>::type type;
0041 };
0042
0043 scoped_lock_parser(mutex_t &m, parser_t const &p)
0044 : unary< ParserT, parser< scoped_lock_parser<MutexT, ParserT> > >(p)
0045 , mutex(m)
0046 {}
0047
0048
0049 template <typename ScannerT>
0050 typename parser_result<self_t, ScannerT>::type
0051 parse(ScannerT const &scan) const
0052 {
0053 typedef boost::unique_lock<mutex_t> scoped_lock_t;
0054 scoped_lock_t lock(mutex);
0055 return this->subject().parse(scan);
0056 }
0057
0058 mutex_t &mutex;
0059 };
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 template <typename MutexT>
0070 struct scoped_lock_parser_gen
0071 {
0072 typedef MutexT mutex_t;
0073 explicit scoped_lock_parser_gen(mutex_t &m) : mutex(m) {}
0074
0075 template<typename ParserT>
0076 scoped_lock_parser
0077 <
0078 MutexT,
0079 typename as_parser<ParserT>::type
0080 >
0081 operator[](ParserT const &p) const
0082 {
0083 typedef ::BOOST_SPIRIT_CLASSIC_NS::as_parser<ParserT> as_parser_t;
0084 typedef typename as_parser_t::type parser_t;
0085
0086 return scoped_lock_parser<mutex_t, parser_t>
0087 (mutex, as_parser_t::convert(p));
0088 }
0089
0090 mutex_t &mutex;
0091 };
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101 template <typename MutexT>
0102 scoped_lock_parser_gen<MutexT>
0103 scoped_lock_d(MutexT &mutex)
0104 {
0105 return scoped_lock_parser_gen<MutexT>(mutex);
0106 }
0107
0108 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0109
0110 }}
0111 #endif