mbi_runtime_lock.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2007,2008 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License along
00018  * with this program; if not, write to the Free Software Foundation, Inc.,
00019  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00020  */
00021 
00022 #ifndef INCLUDED_MBI_RUNTIME_LOCK_H
00023 #define INCLUDED_MBI_RUNTIME_LOCK_H
00024 
00025 #include <mblock/runtime.h>
00026 #include <mb_mblock_impl.h>
00027 #include <boost/utility.hpp>
00028 
00029 /*!
00030  * \brief acquire and release big runtime lock
00031  *
00032  * As an alternative to:
00033  * {
00034  *   rt->lock();
00035  *   .....
00036  *   rt->unlock();
00037  * }
00038  *
00039  * you can use a single instance of the mbi_runtime_lock class:
00040  *
00041  * {
00042  *   mbi_runtime_lock l(rt);
00043  *   ....
00044  * }
00045  *
00046  * This has the advantage that rt->unlock() will be called automatically
00047  * when an exception is thrown.
00048  */
00049 
00050 class mbi_runtime_lock : boost::noncopyable {
00051   mb_runtime_base       *d_rt;
00052 public:
00053   mbi_runtime_lock(mb_runtime_base *rt) : d_rt(rt) { d_rt->lock(); }
00054   mbi_runtime_lock(mb_mblock_impl *mi) : d_rt(mi->runtime()) { d_rt->lock(); }
00055   mbi_runtime_lock(mb_mblock *mb) : d_rt(mb->impl()->runtime()) { d_rt->lock(); }
00056   ~mbi_runtime_lock(void) { d_rt->unlock(); }
00057 
00058 };
00059 
00060 #endif /* INCLUDED_MBI_RUNTIME_LOCK_H */
00061 

Generated on Wed Jul 29 06:23:29 2009 for GNU Radio 3.2.2 C++ API by  doxygen 1.5.9