mutex.h

00001 /*
00002  * mutex.h
00003  * This file is part of dbPager Classes Library (DCL)
00004  *
00005  * Copyright (c) 2008 Dennis Prochko <wolfsoft@mail.ru>
00006  *
00007  * DCL 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 version 3.
00010  *
00011  * DCL is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with DCL; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor,
00019  * Boston, MA  02110-1301  USA
00020  */
00021 
00022 #ifndef _MUTEX_H_
00023 #define _MUTEX_H_
00024 
00025 #include <dcl/exception.h>
00026 
00027 namespace dbp {
00028 
00030 
00033 class mutex_exception: public dbp::exception {
00034 public:
00035         mutex_exception(const std::string &msg = "") throw():
00036           dbp::exception(msg) { }
00037 };
00038 
00039 class mutex_int {
00040         friend class mutex;
00041         friend class event;
00042 public:
00043         virtual ~mutex_int() { }
00044         virtual void enter() = 0;
00045         virtual bool try_enter() = 0;
00046         virtual void leave() = 0;
00047 protected:
00048         virtual void* handle() = 0;
00049 };
00050 
00052 
00057 class mutex: public mutex_int {
00058         friend class event;
00059 public:
00061         mutex();
00063         virtual ~mutex();
00065 
00070         virtual void enter();
00072 
00078         virtual bool try_enter();
00080 
00085         virtual void leave();
00086 protected:
00087         virtual void* handle();
00088 private:
00089         mutex_int *pimpl;
00090 };
00091 
00093 
00099 class mutex_guard {
00100 public:
00102 
00105         mutex_guard(mutex&);
00107 
00110         virtual ~mutex_guard();
00111 private:
00112         mutex &_mutex;
00113 };
00114 
00115 } //namespace
00116 
00117 #endif /*_MUTEX_H_*/
00118 

 
Support This Project
SourceForge.net Logo