TCMTLock.h

Go to the documentation of this file.
00001 //*******************************************************************************
00002 //
00003 // *******   ***   ***               *
00004 //    *     *     *                  *
00005 //    *    *      *                *****
00006 //    *    *       ***  *   *   **   *    **    ***
00007 //    *    *          *  * *   *     *   ****  * * *
00008 //    *     *         *   *      *   * * *     * * *
00009 //    *      ***   ***    *     **   **   **   *   *
00010 //                        *
00011 //*******************************************************************************
00012 // see http://sourceforge.net/projects/tcsystem/ for details.
00013 // Copyright (C) 2003 - 2008 Thomas Goessler. All Rights Reserved. 
00014 //*******************************************************************************
00015 //
00016 // TCSystem is the legal property of its developers.
00017 // Please refer to the COPYRIGHT file distributed with this source distribution.
00018 // 
00019 // This library is free software; you can redistribute it and/or             
00020 // modify it under the terms of the GNU Lesser General Public                
00021 // License as published by the Free Software Foundation; either              
00022 // version 2.1 of the License, or (at your option) any later version.        
00023 //                                                                           
00024 // This library is distributed in the hope that it will be useful,           
00025 // but WITHOUT ANY WARRANTY; without even the implied warranty of            
00026 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         
00027 // Lesser General Public License for more details.                           
00028 //                                                                           
00029 // You should have received a copy of the GNU Lesser General Public          
00030 // License along with this library; if not, write to the Free Software       
00031 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
00032 //*******************************************************************************
00033 //  $Id: TCMTLock.h 870 2008-07-21 14:15:33Z the_____tiger $
00034 //*******************************************************************************
00035 
00036 #ifndef _TC_MT_LOCK_H_
00037 #define _TC_MT_LOCK_H_
00038 
00039 #include "TCNonCopyable.h"
00040 
00041 namespace TC
00042 {
00043 namespace MT
00044 {
00094    template <class T>
00095    class LockerRef: protected NonCopyAble
00096    {
00097    public:
00104        LockerRef(T& critical)
00105        :m_critical(critical)
00106        {
00107            m_critical.Lock();
00108        }
00109 
00114        ~LockerRef()
00115        {
00116            m_critical.UnLock();
00117        }
00118 
00119    private:
00121        T& m_critical;
00122    };
00123 
00128    template <class T>
00129    class LockerPtr: protected NonCopyAble
00130    {
00131    public:
00138        LockerPtr(T critical)
00139        :m_critical(critical)
00140        {
00141            m_critical->Lock();
00142        }
00143 
00148        ~LockerPtr()
00149        {
00150            m_critical->UnLock();
00151        }
00152 
00153    private:
00155        T m_critical;
00156    };
00157 
00162 } // namespace MT
00163 } // namespace TC
00164 
00165 
00166 #endif // _TC_MT_LOCK_H_

Copyright (c) Thomas Goessler 2003 - 2008