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 
00024 /// \brief 
00025 /// FdoSemaphore is a semaphore class. It is used to prevent operations
00026 /// from happening concurrently or re-entrantly. FdoSemaphore is not currently part
00027 /// of the FDO API but can be added if there is a demand. It is a wrapper class around
00028 /// a boolean semaphore.
00029 ///
00030 /// FdoSemaphore can be used to prevent a member function on another class from 
00031 /// being called re-entrantly for the same object (see FdoXmlReaderXrcs::Parse()) 
00032 /// for an example. This can be done by declaring a FdoSemaphoreP, at the start of the
00033 /// function, that takes a boolean member and an exception. The boolean member must initially
00034 /// be false. When the FdoSemaphoreP is created, the boolean member is set to true. When 
00035 /// the function exits, FdoSemaphoreP goes out of scope and sets the boolean member back
00036 /// to false. However, if the function is called a second time before the first 
00037 /// invokation finishes, the second FdoSemaphoreP created will detect that the boolean member
00038 /// is true, and it will throw the given exception, thus rejecting the re-entrant 
00039 /// function call.
00040 class FdoSemaphore : public FdoIDisposable
00041 {
00042 public:
00043     /// \brief
00044     /// Constructs a new semaphore.
00045     /// \param semaphore 
00046     /// Input the semaphore switch. If true, then the
00047     /// given exception is thrown. If false, then semaphore is set to true.
00048     /// semaphore is set back to false when this object is deleted.
00049     /// \param ex 
00050     /// Input the exception to throw when semaphore is true.
00051     /// 
00052     /// \return
00053     /// Returns FdoSemaphore
00054     /// 
00055     static FdoSemaphore* Create( FdoBoolean& semaphore, FdoException* ex )
00056     {
00057         return new FdoSemaphore( semaphore, ex );
00058     }
00059 
00060 protected:
00061     FdoSemaphore() {}
00062     FdoSemaphore( bool& semaphore, FdoException* ex );
00063     virtual ~FdoSemaphore();
00064 
00065     virtual void Dispose()
00066     {
00067         delete this;
00068     }
00069 
00070 private:
00071     /// Pointer to the bool semaphore, so that it can be reset on destruction
00072     /// of this object.
00073     FdoBoolean* mSemaphore;
00074 
00075 };
00076 
00077 /// \brief
00078 /// FdoSemaphoreP is a FdoPtr on FdoSemaphore, provided for convenience.
00079 typedef FdoPtr<FdoSemaphore> FdoSemaphoreP;
00080 
00081 /// \endcond
00082 
00083 #endif
00084 
00085 

Comments or suggestions? Send us feedback.