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

# deSynchObject.hpp

Go to the documentation of this file.

    00001 ///////////////////////////////////////////////////////////////////////////////
    00002 /// @file deSynchObject.hpp
    00003 ///
    00004 /// @brief
    00005 ///
    00006 /// @author trajar
    00007 ///
    00008 /// This file is the intellectual property of Novus Delta, LLC.. Usage of the
    00009 /// contents of this file is subject to the Destiny3D Member License which
    00010 /// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
    00011 ///
    00012 /// This file is distributed "AS IS" without warranty of any kind.  Novus
    00013 /// Delta, LLC. does not guarantee the fitness of the contents of this file
    00014 /// for any particular purpose.
    00015 ///
    00016 /// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
    00017 ///
    00018 /// <hr>
    00019 ///                                 Change History
    00020 /// <hr>
    00021 ///
    00022 /// @date Jun 2002
    00023 /// @author trajar
    00024 /// @remarks Creation
    00025 ///
    00026 ///////////////////////////////////////////////////////////////////////////////
    00027
    00028 #ifndef     _DESYNCHOBJECT_HPP
    00029 #define     _DESYNCHOBJECT_HPP
    00030
    00031 #ifndef     _DENET_HPP
    00032  #include   "deNet.hpp"
    00033 #endif
    00034
    00035 #include    <WINDOWS.H>
    00036
    00037 // used to ensure local lock inside a function
    00038 #define     ENSURE_LOCK( a, b ) { if( !(b)->IsLocked() ) { deSynchLocalObject myLocalSynchObject = deSynchLocalObject( (a), (b) ); } }
    00039
    00040 //-------------------------------------------------------------
    00041 // deSynchObject
    00042 //
    00043 // - used to ensure thread safe operations
    00044 //-------------------------------------------------------------
    00045 class DENET_API deSynchObject
    00046 {
    00047 public:
    00048     deSynchObject(void);
    00049     ~deSynchObject(void);
    00050
    00051     void    Lock(void*);
    00052     void    Unlock(void);
    00053
    00054     void *  GetOwner(void)      const { return m_Owner; }
    00055     bool    IsLocked(void)      const { return m_bLocked || m_Owner; }
    00056
    00057 private:
    00058
    00059     bool                m_bLocked;
    00060     void *              m_Owner;
    00061     CRITICAL_SECTION    m_csLock;
    00062 };
    00063
    00064 //-------------------------------------------------------------
    00065 // deSynchLocalObject
    00066 //
    00067 // - used to ensure thread-safe operations for local function
    00068 //-------------------------------------------------------------
    00069 class DENET_API deSynchLocalObject
    00070 {
    00071 public:
    00072     // don't use this
    00073     deSynchLocalObject( void );
    00074
    00075     // use these
    00076     deSynchLocalObject( void * pOwner, deSynchObject * pObj );
    00077     ~deSynchLocalObject( void );
    00078
    00079     deSynchObject *     GetParent( void );
    00080
    00081 private:
    00082     void *              m_Owner;
    00083     deSynchObject *     m_Object;
    00084 };
    00085
    00086 #endif