CppDB
cppdb/mutex.h
00001 
00002 //                                                                             
00003 //  Copyright (C) 2010-2011  Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>     
00004 //                                                                             
00005 //  Distributed under:
00006 //
00007 //                   the Boost Software License, Version 1.0.
00008 //              (See accompanying file LICENSE_1_0.txt or copy at 
00009 //                     http://www.boost.org/LICENSE_1_0.txt)
00010 //
00011 //  or (at your opinion) under:
00012 //
00013 //                               The MIT License
00014 //                 (See accompanying file MIT.txt or a copy at
00015 //              http://www.opensource.org/licenses/mit-license.php)
00016 //
00018 #ifndef CPPDB_MUTEX_H
00019 #define CPPDB_MUTEX_H
00020 
00021 #include <cppdb/defs.h>
00022 
00023 namespace cppdb {
00024 
00028         class CPPDB_API mutex {
00029                 mutex(mutex const &);
00030                 void operator=(mutex const  &);
00031         public:
00032                 class guard;
00034                 mutex();
00036                 ~mutex();
00038                 void lock();
00040                 void unlock();
00041         private:
00042                 void *mutex_impl_;
00043         };
00044 
00048         class mutex::guard {
00049                 guard(guard const &);
00050                 void operator=(guard const &);
00051         public:
00053                 guard(mutex &m) : m_(&m)
00054                 {
00055                         m_->lock();
00056                 }
00058                 ~guard()
00059                 {
00060                         m_->unlock();
00061                 }
00062         private:
00063                 mutex *m_;
00064         };
00065 }
00066 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator