Imported Upstream version 3.2.2
[debian/gnuradio] / mblock / src / lib / mbi_runtime_lock.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2007,2008 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef INCLUDED_MBI_RUNTIME_LOCK_H
23 #define INCLUDED_MBI_RUNTIME_LOCK_H
24
25 #include <mblock/runtime.h>
26 #include <mb_mblock_impl.h>
27 #include <boost/utility.hpp>
28
29 /*!
30  * \brief acquire and release big runtime lock
31  *
32  * As an alternative to:
33  * {
34  *   rt->lock();
35  *   .....
36  *   rt->unlock();
37  * }
38  *
39  * you can use a single instance of the mbi_runtime_lock class:
40  *
41  * {
42  *   mbi_runtime_lock l(rt);
43  *   ....
44  * }
45  *
46  * This has the advantage that rt->unlock() will be called automatically
47  * when an exception is thrown.
48  */
49
50 class mbi_runtime_lock : boost::noncopyable {
51   mb_runtime_base       *d_rt;
52 public:
53   mbi_runtime_lock(mb_runtime_base *rt) : d_rt(rt) { d_rt->lock(); }
54   mbi_runtime_lock(mb_mblock_impl *mi) : d_rt(mi->runtime()) { d_rt->lock(); }
55   mbi_runtime_lock(mb_mblock *mb) : d_rt(mb->impl()->runtime()) { d_rt->lock(); }
56   ~mbi_runtime_lock(void) { d_rt->unlock(); }
57
58 };
59
60 #endif /* INCLUDED_MBI_RUNTIME_LOCK_H */
61