diff options
Diffstat (limited to 'src/time')
| -rw-r--r-- | src/time/timo.cpp | 15 | ||||
| -rw-r--r-- | src/time/timo.h | 4 | ||||
| -rw-r--r-- | src/time/timr.cpp | 18 | ||||
| -rw-r--r-- | src/time/timr.h | 14 |
4 files changed, 39 insertions, 12 deletions
diff --git a/src/time/timo.cpp b/src/time/timo.cpp index 276b517..0a923f1 100644 --- a/src/time/timo.cpp +++ b/src/time/timo.cpp @@ -1,12 +1,11 @@ /*:* *: File: ./src/time/timo.cpp *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-CURRENT *: *: Copyright (C) 2003 Paul C. Buetow, Volker Richter *: Copyright (C) 2004 Paul C. Buetow *: Copyright (C) 2005 EXA Digital Solutions GbR - *: Copyright (C) 2006, 2007 Paul C. Buetow *: *: This program is free software; you can redistribute it and/or *: modify it under the terms of the GNU General Public License @@ -31,17 +30,23 @@ using namespace std; timo::timo() -{} +{ + pthread_mutex_init( &mut_t_time, NULL ); +} timo::~timo() -{} +{ + pthread_mutex_destroy( &mut_t_time ); +} double timo::get_last_activity( ) { double d_ret; + pthread_mutex_lock ( &mut_t_time ); d_ret = wrap::TIMR->get_time_diff( t_time ); + pthread_mutex_unlock( &mut_t_time ); return d_ret; } @@ -49,7 +54,9 @@ timo::get_last_activity( ) void timo::renew_timeout( ) { + pthread_mutex_lock ( &mut_t_time ); time( &t_time ); + pthread_mutex_unlock( &mut_t_time ); } #endif diff --git a/src/time/timo.h b/src/time/timo.h index 5ded5ff..ad4012e 100644 --- a/src/time/timo.h +++ b/src/time/timo.h @@ -1,12 +1,11 @@ /*:* *: File: ./src/time/timo.h *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-CURRENT *: *: Copyright (C) 2003 Paul C. Buetow, Volker Richter *: Copyright (C) 2004 Paul C. Buetow *: Copyright (C) 2005 EXA Digital Solutions GbR - *: Copyright (C) 2006, 2007 Paul C. Buetow *: *: This program is free software; you can redistribute it and/or *: modify it under the terms of the GNU General Public License @@ -34,6 +33,7 @@ class timo // timeout class { protected: time_t t_time; // last activity time. + pthread_mutex_t mut_t_time; public: timo( ); diff --git a/src/time/timr.cpp b/src/time/timr.cpp index 0d049c3..65ba780 100644 --- a/src/time/timr.cpp +++ b/src/time/timr.cpp @@ -1,12 +1,11 @@ /*:* *: File: ./src/time/timr.cpp *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-CURRENT *: *: Copyright (C) 2003 Paul C. Buetow, Volker Richter *: Copyright (C) 2004 Paul C. Buetow *: Copyright (C) 2005 EXA Digital Solutions GbR - *: Copyright (C) 2006, 2007 Paul C. Buetow *: *: This program is free software; you can redistribute it and/or *: modify it under the terms of the GNU General Public License @@ -36,6 +35,9 @@ timr::timr() wrap::system_message( TIMERIN ); b_timer_active = true; + pthread_mutex_init( &mut_s_time, NULL); + pthread_mutex_init( &mut_s_uptime, NULL); + pthread_mutex_init( &mut_i_offset, NULL); i_time_offset = tool::string2int( wrap::CONF->get_elem("chat.timeoffset") ); wrap::system_message( TIMEROF + tool::int2string( i_time_offset ) ); @@ -45,7 +47,11 @@ timr::timr() } timr::~timr() -{} +{ + pthread_mutex_destroy( &mut_s_time ); + pthread_mutex_destroy( &mut_s_uptime ); + pthread_mutex_destroy( &mut_i_offset ); +} bool timr::get_timer_active() const @@ -56,7 +62,9 @@ timr::get_timer_active() const int timr::get_offset() { + pthread_mutex_lock ( &mut_i_offset ); int i_ret_val = i_time_offset; + pthread_mutex_unlock( &mut_i_offset ); return i_ret_val; } @@ -150,13 +158,17 @@ timr::set_time( double d_uptime, int i_cur_seconds, int i_cur_minutes, int i_cur if (i_cur_hours == 24) i_cur_hours = 0; + pthread_mutex_lock ( &mut_s_time ); s_time = add_zero_to_front( tool::int2string( i_cur_hours ) ) + ":" + add_zero_to_front( tool::int2string( i_cur_minutes ) ) + ":" + add_zero_to_front( tool::int2string( i_cur_seconds ) ); + pthread_mutex_unlock( &mut_s_time ); + pthread_mutex_lock ( &mut_s_uptime ); s_uptime = add_zero_to_front( tool::int2string( i_hours ) ) + ":" + add_zero_to_front( tool::int2string( i_minutes ) ) + ":" + add_zero_to_front( tool::int2string( (int) d_uptime ) ); + pthread_mutex_unlock( &mut_s_uptime ); } string diff --git a/src/time/timr.h b/src/time/timr.h index 69d411c..0460cba 100644 --- a/src/time/timr.h +++ b/src/time/timr.h @@ -1,12 +1,11 @@ /*:* *: File: ./src/time/timr.h *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-CURRENT *: *: Copyright (C) 2003 Paul C. Buetow, Volker Richter *: Copyright (C) 2004 Paul C. Buetow *: Copyright (C) 2005 EXA Digital Solutions GbR - *: Copyright (C) 2006, 2007 Paul C. Buetow *: *: This program is free software; you can redistribute it and/or *: modify it under the terms of the GNU General Public License @@ -28,11 +27,13 @@ #ifndef TIMR_H #define TIMR_H +#include "../thrd/thro.h" + #include <unistd.h> using namespace std; -class timr +class timr : public thro { private: bool b_timer_active; @@ -40,6 +41,9 @@ private: string s_uptime; string s_time; + pthread_mutex_t mut_s_time; + pthread_mutex_t mut_s_uptime; + pthread_mutex_t mut_i_offset; public: timr(); @@ -56,7 +60,9 @@ public: get_time( ) { string s_ret; + pthread_mutex_lock ( &mut_s_time ); s_ret = this->s_time; + pthread_mutex_unlock( &mut_s_time ); return s_ret; } @@ -64,7 +70,9 @@ public: get_uptime( ) { string s_ret; + pthread_mutex_lock ( &mut_s_uptime ); s_ret = this->s_uptime; + pthread_mutex_unlock( &mut_s_uptime ); return s_ret; } |
