Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_SemaphoreTimed.cpp

00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  *
00016  * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
00017  *
00018  */
00019 
00020 #include "SemaphoreImpl.h"
00021 #include "C_SemaphoreTimed.hpp"
00022 #include "GeneratorTrace.hpp"
00023 
00024 #include <sys/time.h>
00025 #include <unistd.h>
00026 #include <cerrno>
00027 
00028 C_SemaphoreTimed::C_SemaphoreTimed(long P_timeOut):C_Semaphore() {
00029 
00030   GEN_DEBUG(0, "C_SemaphoreTimed::C_SemaphoreTimed(" << P_timeOut << ") start");
00031   m_timeOut = P_timeOut ;
00032   GEN_DEBUG(0, "C_SemaphoreTimed::C_SemaphoreTimed() end");
00033 }
00034 
00035 C_SemaphoreTimed::~C_SemaphoreTimed() {
00036   GEN_DEBUG(0, "C_SemaphoreTimed::~C_SemaphoreTimed() start");
00037   m_timeOut = 0 ;
00038   GEN_DEBUG(0, "C_SemaphoreTimed::~C_SemaphoreTimed() end");
00039 }
00040 
00041 T_CounterValue C_SemaphoreTimed::P() {
00042 
00043   T_CounterValue L_value   ;
00044   struct timeval    L_now     ;
00045   struct timespec   L_timeOut ;
00046   struct timezone   L_tzp     ;
00047   int               L_return  = -1; // do not forget to initialize
00048                                     // for re-entry call
00049 
00050   gettimeofday (&L_now,&L_tzp);
00051   L_timeOut.tv_sec = L_now.tv_sec + (time_t) m_timeOut ;
00052   L_timeOut.tv_nsec = L_now.tv_usec * 1000 ;
00053 
00054   pthread_mutex_lock (SemMutex) ;
00055   while (   (SemCounter <= COUNTER_COMP_VALUE) 
00056          && (L_return != ETIMEDOUT)) {
00057 
00058     L_return = pthread_cond_timedwait (SemCond, SemMutex, &L_timeOut);
00059 
00060   }
00061   if (L_return != ETIMEDOUT) {
00062     SemCounter -- ;
00063   } 
00064   L_value = SemCounter ;
00065   pthread_mutex_unlock (SemMutex);
00066 
00067   return (L_value) ;
00068 
00069 } // P()
00070 
00071 
00072 void C_SemaphoreTimed::change_display_period(long P_period) {
00073   m_timeOut = P_period;
00074 }
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 
00083 
00084 
00085 
00086 
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094 

Generated on Wed Mar 7 14:44:58 2007 for Seagull by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002