Project stdui: "Simple Type Dialog User-Interface"

|
Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

cmutex.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Serge Lussier   *
00003  *   serge.lussier@videotron.ca   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 
00022 #include <cmutex.hxx>
00023 #include <iostream>
00024 
00025 namespace control {
00026 
00027 cmutex::cmutex():_mutex(0l),
00028  _init(false)
00029  {
00030 }
00031 
00032 
00033 cmutex::~cmutex()
00034 {
00035    std::cerr << __PRETTY_FUNCTION__ << std::endl << '{' << std::endl << "." << std::endl;
00036 
00037    if( _mutex ){
00038       unlock();
00039       pthread_mutex_destroy(_mutex);
00040       _mutex = 0l;
00041    }
00042 
00043    std::cerr << std::endl << '}' << std::endl;
00044 }
00045 
00046 
00047 
00048 
00049 
00054 bool cmutex::init()
00055 {
00056    _mutex= new pthread_mutex_t;
00057    pthread_mutex_init(_mutex, 0l);
00058    _init = true;
00059    __locked = false;
00060    return true;
00061 }
00062 
00063 
00067 bool cmutex::lock()
00068 {
00069    if(!_init) return false;
00070    if(__locked) return false;
00071    pthread_mutex_lock(_mutex);
00072    __locked = true;
00073    return true;
00074 }
00075 
00076 
00080 void cmutex::unlock()
00081 {
00082    if(!_init) return;
00083    if(!__locked) return ;
00084    pthread_mutex_unlock(_mutex);
00085    __locked = false;
00086 }
00087 }

API Documentation Generated by:  doxygen 1.4.0
About the author | Site started with trial version of DreamWeaver MX 2004 | Finalizing with  | Contact | ©2005, Serge Lussier ( Bretzel )