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

condition.hh

00001 /*
00002 *  Name:      condition.hh
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Condition class for POSIX 1003.1c compliant conditions
00005 *  Date:      $Date: 2003/08/08 23:30:34 $
00006 *  Revision:  $Revision: 1.2 $
00007 *
00008 *  Copyright (C) 1999-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #ifndef _MPCL_SYSTEM_POSIX_1_CONDITION__
00027 #define _MPCL_SYSTEM_POSIX_1_CONDITION__
00028 
00029 #include <pthread.h>
00030 #include "../condition.hh"
00031 #include "../exceptions.hh"
00032 #include "mutex.hh"
00033 
00034 
00036 namespace mpcl
00037 {
00038 
00040   namespace system
00041   {
00042 
00047     class TCondition : public ICondition
00048     {
00049 
00050       private:
00051 
00053         pthread_cond_t   tPosixId;
00054 
00056         TMutex&          rtMutex;
00057 
00058 
00059       public:
00060 
00061         //
00062         //  C O N S T R U C T O R S
00063         //
00064 
00070         TCondition (TMutex& rtSOURCE_MUTEX)
00071           throw (TErrorException)         :
00072           ICondition ()                   ,
00073           tPosixId   ()                   ,
00074           rtMutex    (rtSOURCE_MUTEX)
00075         {
00076           if ( pthread_cond_init (&tPosixId, NULL) )
00077           {
00078             throw TErrorException (GetErrorMessage(), __FILE__, __LINE__);
00079           }
00080         }
00081 
00086         ~TCondition()
00087           throw (TErrorException)
00088         {
00089           if ( pthread_cond_destroy (&tPosixId) )
00090           {
00091             throw TErrorException (GetErrorMessage(), __FILE__, __LINE__);
00092           }
00093         }
00094 
00100         void wait (void)
00101           throw (TErrorException)
00102         {
00103           if ( pthread_cond_wait (&tPosixId, &rtMutex.tPosixId) )
00104           {
00105             throw TErrorException (GetErrorMessage(), __FILE__, __LINE__);
00106           }
00107         }
00108 
00117         bool timedWait (size_t zSECONDS, size_t zNANOSECONDS = 0)
00118           throw (TErrorException);
00119 
00124         void signal (void)
00125           throw (TErrorException)
00126         {
00127           if ( pthread_cond_signal (&tPosixId) )
00128           {
00129             throw TErrorException (GetErrorMessage(), __FILE__, __LINE__);
00130           }
00131         }
00132 
00137         void broadcast (void)
00138           throw (TErrorException)
00139         {
00140           if ( pthread_cond_broadcast (&tPosixId) )
00141           {
00142             throw TErrorException (GetErrorMessage(), __FILE__, __LINE__);
00143           }
00144         }
00145 
00146     };  // class TCondition
00147 
00148   }  // namespace system
00149 
00150 }  // namespace mpcl
00151 
00152 
00153 #endif  // not _MPCL_SYSTEM_POSIX_1_CONDITION__

Generated on Mon Oct 13 02:35:22 2003 for MPCL by doxygen1.2.18