STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... ATLSTL - Template Software for the Active Template Library COMSTL - The Standard Template Library meets the Component Object Model .netSTL - Standard Template Library meets the Microsoft.NET Common Language Runtime InetSTL - The Standard Template Library meets WinInet MFCSTL - Template Software for the Microsoft Foundation Classes UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

stlsoft_lock_scope.h

Go to the documentation of this file.
00001 /* 
00002  * File:        stlsoft_lock_scope.h (originally MLLock.h, ::SynesisStd)
00003  *
00004  * Purpose:     Synchronisation object lock scoping class.
00005  *
00006  * Created:     1st October 1994
00007  * Updated:     11th September 2004
00008  *
00009  * Home:        http://stlsoft.org/
00010  *
00011  * Copyright (c) 1994-2004, Matthew Wilson and Synesis Software
00012  * All rights reserved.
00013  *
00014  * Redistribution and use in source and binary forms, with or without
00015  * modification, are permitted provided that the following conditions are met:
00016  *
00017  * - Redistributions of source code must retain the above copyright notice, this
00018  *   list of conditions and the following disclaimer.
00019  * - Redistributions in binary form must reproduce the above copyright notice,
00020  *   this list of conditions and the following disclaimer in the documentation
00021  *   and/or other materials provided with the distribution.
00022  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
00023  *   any contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  * POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  * 
00039 
00040 
00044 
00045 #ifndef STLSOFT_INCL_H_STLSOFT_LOCK_SCOPE
00046 #define STLSOFT_INCL_H_STLSOFT_LOCK_SCOPE
00047 
00048 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00049 # define STLSOFT_VER_H_STLSOFT_LOCK_SCOPE_MAJOR     4
00050 # define STLSOFT_VER_H_STLSOFT_LOCK_SCOPE_MINOR     0
00051 # define STLSOFT_VER_H_STLSOFT_LOCK_SCOPE_REVISION  1
00052 # define STLSOFT_VER_H_STLSOFT_LOCK_SCOPE_EDIT      95
00053 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00054 
00055 /* 
00056  * Includes
00057  */
00058 
00059 #ifndef STLSOFT_INCL_H_STLSOFT
00060 # include "stlsoft.h"   // Include the STLSoft root header
00061 #endif /* !STLSOFT_INCL_H_STLSOFT */
00062 
00063 /* 
00064  * Namespace
00065  */
00066 
00067 #ifndef _STLSOFT_NO_NAMESPACE
00068 namespace stlsoft
00069 {
00070 #endif /* _STLSOFT_NO_NAMESPACE */
00071 
00072 /* 
00073  * Classes
00074  */
00075 
00076 // class lock_traits
00077 
00081 template<ss_typename_param_k L>
00082 struct lock_traits
00083 {
00084 public:
00086     typedef L               lock_type;
00088     typedef lock_traits<L>  class_type;
00089 
00090 // Operations
00091 public:
00093     static void lock(lock_type &c)
00094     {
00095         lock_instance(c);
00096     }
00097 
00099     static void unlock(lock_type &c)
00100     {
00101         unlock_instance(c);
00102     }
00103 };
00104 
00105 // class lock_invert_traits
00106 
00110 template<ss_typename_param_k L>
00111 struct lock_invert_traits
00112 {
00113 public:
00115     typedef L                       lock_type;
00117     typedef lock_invert_traits<L>   class_type;
00118 
00119 // Operations
00120 public:
00122     static void lock(lock_type &c)
00123     {
00124         unlock_instance(c);
00125     }
00126 
00128     static void unlock(lock_type &c)
00129     {
00130         lock_instance(c);
00131     }
00132 };
00133 
00134 // class lock_traits_inverter
00135 
00139 template<ss_typename_param_k T>
00140 struct lock_traits_inverter
00141 {
00142 public:
00144     typedef T                                           traits_type;
00146     typedef ss_typename_type_k traits_type::lock_type   lock_type;
00148     typedef lock_traits_inverter<T>                     class_type;
00149 
00150 // Operations
00151 public:
00153     static void lock(lock_type &c)
00154     {
00155         traits_type::unlock(c);
00156     }
00157 
00159     static void unlock(lock_type &c)
00160     {
00161         traits_type::lock(c);
00162     }
00163 };
00164 
00165 // class lock_scope
00166 
00171 template<   ss_typename_param_k L
00172 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00173         ,   ss_typename_param_k T = lock_traits<L>
00174 #else
00175         ,   ss_typename_param_k T
00176 #endif /* __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
00177         >
00178 class lock_scope
00179 {
00180 public:
00182     typedef L                       lock_type;
00184     typedef T                       traits_type;
00186     typedef lock_scope<L, T>        class_type;
00187 
00188 // Construction
00189 public:
00191     lock_scope(lock_type &l)
00192         : m_l(l)
00193     {
00194         traits_type::lock(m_l);
00195     }
00197     ~lock_scope()
00198     {
00199         traits_type::unlock(m_l);
00200     }
00201 
00202 // Members
00203 private:
00204     lock_type   &m_l;
00205 
00206 // Not to be implemented
00207 private:
00208     lock_scope(class_type const &rhs);
00209     lock_scope &operator =(class_type const &rhs);
00210 };
00211 
00212 /* 
00213 
00214 #ifndef _STLSOFT_NO_NAMESPACE
00215 } // namespace stlsoft
00216 #endif /* _STLSOFT_NO_NAMESPACE */
00217 
00218 /* 
00219 
00220 #endif /* !STLSOFT_INCL_H_STLSOFT_LOCK_SCOPE */
00221 
00222 /* 

STLSoft Libraries documentation © Synesis Software Pty Ltd, 2001-2004