FDO API Reference Feature Data Objects

Semaphore.h

Go to the documentation of this file.
00001 #ifndef FDO_SEMAPHORE
00002 #define FDO_SEMAPHORE
00003 //
00004 
00005 //
00006 // Copyright (C) 2004-2006  Autodesk, Inc.
00007 // 
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of version 2.1 of the GNU Lesser
00010 // General Public License as published by the Free Software Foundation.
00011 // 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 // Lesser General Public License for more details.
00016 // 
00017 // You should have received a copy of the GNU Lesser General Public
00018 // License along with this library; if not, write to the Free Software
00019 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 //
00021 
00022 /// \cond DOXYGEN-IGNORE
00023 /// \brief 
00024 /// FdoSemaphore is a semaphore class. It is used to prevent operations
00025 /// from happening concurrently or re-entrantly. FdoSemaphore is not currently part
00026 /// of the FDO API but can be added if there is a demand. It is a wrapper class around
00027 /// a boolean semaphore.
00028 ///
00029 /// FdoSemaphore can be used to prevent a member function on another class from 
00030 /// being called re-entrantly for the same object (see FdoXmlReaderXrcs::Parse()) 
00031 /// for an example. This can be done by declaring a FdoSemaphoreP, at the start of the
00032 /// function, that takes a boolean member and an exception. The boolean member must initially
00033 /// be false. When the FdoSemaphoreP is created, the boolean member is set to true. When 
00034 /// the function exits, FdoSemaphoreP goes out of scope and sets the boolean member back
00035 /// to false. However, if the function is called a second time before the first 
00036 /// invokation finishes, the second FdoSemaphoreP created will detect that the boolean member
00037 /// is true, and it will throw the given exception, thus rejecting the re-entrant 
00038 /// function call.
00039 class FdoSemaphore : public FdoIDisposable
00040 {
00041 public:
00042     /// \brief
00043     /// Constructs a new semaphore.
00044     /// \param semaphore 
00045     /// Input the semaphore switch. If true, then the
00046     /// given exception is thrown. If false, then semaphore is set to true.
00047     /// semaphore is set back to false when this object is deleted.
00048     /// \param ex 
00049     /// Input the exception to throw when semaphore is true.
00050     /// 
00051     /// \return
00052     /// Returns FdoSemaphore
00053     /// 
00054     static FdoSemaphore* Create( FdoBoolean& semaphore, FdoException* ex )
00055     {
00056         return new FdoSemaphore( semaphore, ex );
00057     }
00058 
00059 protected:
00060     FdoSemaphore() {}
00061     FdoSemaphore( bool& semaphore, FdoException* ex );
00062     virtual ~FdoSemaphore();
00063 
00064     virtual void Dispose()
00065     {
00066         delete this;
00067     }
00068 
00069 private:
00070     /// Pointer to the bool semaphore, so that it can be reset on destruction
00071     /// of this object.
00072     FdoBoolean* mSemaphore;
00073 
00074 };
00075 
00076 /// \brief
00077 /// FdoSemaphoreP is a FdoPtr on FdoSemaphore, provided for convenience.
00078 typedef FdoPtr<FdoSemaphore> FdoSemaphoreP;
00079 
00080 /// \endcond
00081 
00082 #endif
00083 
00084 

Comments or suggestions? Send us feedback.