diff options
Diffstat (limited to 'system_wrappers/source')
-rw-r--r-- | system_wrappers/source/trace_posix.cc | 20 | ||||
-rw-r--r-- | system_wrappers/source/trace_posix.h | 4 |
2 files changed, 17 insertions, 7 deletions
diff --git a/system_wrappers/source/trace_posix.cc b/system_wrappers/source/trace_posix.cc index 49659690..d0ab45b7 100644 --- a/system_wrappers/source/trace_posix.cc +++ b/system_wrappers/source/trace_posix.cc @@ -38,13 +38,15 @@ namespace webrtc { -TracePosix::TracePosix() { +TracePosix::TracePosix() + : crit_sect_(*CriticalSectionWrapper::CreateCriticalSection()) { struct timeval system_time_high_res; gettimeofday(&system_time_high_res, 0); prev_api_tick_count_ = prev_tick_count_ = system_time_high_res.tv_sec; } TracePosix::~TracePosix() { + delete &crit_sect_; StopThread(); } @@ -60,13 +62,17 @@ WebRtc_Word32 TracePosix::AddTime(char* trace_message, const WebRtc_UWord32 ms_time = system_time_high_res.tv_usec / 1000; WebRtc_UWord32 prev_tickCount = 0; - if (level == kTraceApiCall) { - prev_tickCount = prev_tick_count_; - prev_tick_count_ = ms_time; - } else { - prev_tickCount = prev_api_tick_count_; - prev_api_tick_count_ = ms_time; + { + CriticalSectionScoped lock(&crit_sect_); + if (level == kTraceApiCall) { + prev_tickCount = prev_tick_count_; + prev_tick_count_ = ms_time; + } else { + prev_tickCount = prev_api_tick_count_; + prev_api_tick_count_ = ms_time; + } } + WebRtc_UWord32 dw_delta_time = ms_time - prev_tickCount; if (prev_tickCount == 0) { dw_delta_time = 0; diff --git a/system_wrappers/source/trace_posix.h b/system_wrappers/source/trace_posix.h index 76df1b16..1c446b1f 100644 --- a/system_wrappers/source/trace_posix.h +++ b/system_wrappers/source/trace_posix.h @@ -21,6 +21,8 @@ class TracePosix : public TraceImpl { TracePosix(); virtual ~TracePosix(); + // This method can be called on several different threads different from + // the creating thread. virtual WebRtc_Word32 AddTime(char* trace_message, const TraceLevel level) const; @@ -30,6 +32,8 @@ class TracePosix : public TraceImpl { private: volatile mutable WebRtc_UWord32 prev_api_tick_count_; volatile mutable WebRtc_UWord32 prev_tick_count_; + + CriticalSectionWrapper& crit_sect_; }; } // namespace webrtc |