00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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;
00048
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 }
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