Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members

FXInterlock.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                   Interlocking object (a semaphore)                           *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2003 by Mathew Robertson.   All Rights Reserved.                *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************/
00022 #ifndef FXINTERLOCK_H
00023 #define FXINTERLOCK_H
00024 
00025 #ifndef FXWAITABLE_H
00026 #include "FXWaitable.h"
00027 #endif
00028 namespace FXEX{
00029 
00030 /**
00031  * A base class for controlling sequenced events
00032  */
00033 class FXAPI FXInterlock : public FXWaitable {
00034   FXDECLARE(FXInterlock)
00035 
00036 private:
00037   FXThreadSemaphore semaphore;  // interlockable object
00038   FXint             wait_;      // wait count
00039 
00040 private:
00041   // dummy copy constructor and operator= to prevent copying
00042   FXInterlock(const FXInterlock&);
00043   FXInterlock& operator=(const FXInterlock&);
00044 
00045 public:
00046   // ctor
00047   FXInterlock(FXObject *tgt=NULL,FXSelector sel=0);
00048 
00049   /// wait indefinately
00050   void wait();
00051 
00052   /// wait for some condition, or time out
00053   FXbool trywait(FXuint ms);
00054 
00055   /// activate object to stop waiting
00056   void activate();
00057 
00058   /// activate all objects to stop waiting
00059   void activateAll();
00060 
00061   /// get the current value of the wait counter
00062   FXint getWaitCount();
00063 
00064   /// dtor
00065   virtual ~FXInterlock();
00066   };
00067 
00068 } // namespace FXEX
00069 #endif // FXINTERLOCK_H