Remove unused ConditionVariableWrapper on POSIX platforms

BUG=

Review URL: https://codereview.webrtc.org/1602203003

Cr-Commit-Position: refs/heads/master@{#11308}
This commit is contained in:
tommi
2016-01-19 13:13:14 -08:00
committed by Commit bot
parent 7b971e728b
commit cd255cc07b
8 changed files with 21 additions and 188 deletions

View File

@ -50,8 +50,6 @@ static_library("system_wrappers") {
"source/condition_variable_event_win.h",
"source/condition_variable_native_win.cc",
"source/condition_variable_native_win.h",
"source/condition_variable_posix.cc",
"source/condition_variable_posix.h",
"source/cpu_features.cc",
"source/cpu_info.cc",
"source/critical_section.cc",

View File

@ -11,6 +11,11 @@
#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CONDITION_VARIABLE_WRAPPER_H_
#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CONDITION_VARIABLE_WRAPPER_H_
// TODO(tommi): Remove completely. As is there is still some code for Windows
// that relies on ConditionVariableWrapper, but code has been removed on other
// platforms.
#if defined(WEBRTC_WIN)
namespace webrtc {
class CriticalSectionWrapper;
@ -39,4 +44,6 @@ class ConditionVariableWrapper {
} // namespace webrtc
#endif // defined(WEBRTC_WIN)
#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CONDITION_VARIABLE_WRAPPER_H_

View File

@ -51,9 +51,7 @@ private:
friend class ConditionVariableEventWin;
friend class ConditionVariableNativeWin;
#else
// TODO(tommi): Remove friendness.
pthread_mutex_t mutex_;
friend class ConditionVariablePosix;
#endif
};

View File

@ -10,19 +10,17 @@
#include "webrtc/system_wrappers/include/condition_variable_wrapper.h"
#if defined(_WIN32)
// TODO(tommi): Remove completely. As is there is still some code for Windows
// that relies on ConditionVariableWrapper, but code has been removed on other
// platforms.
#if defined(WEBRTC_WIN)
#include <windows.h>
#include "webrtc/system_wrappers/source/condition_variable_event_win.h"
#include "webrtc/system_wrappers/source/condition_variable_native_win.h"
#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
#include <pthread.h>
#include "webrtc/system_wrappers/source/condition_variable_posix.h"
#endif
namespace webrtc {
ConditionVariableWrapper* ConditionVariableWrapper::CreateConditionVariable() {
#if defined(_WIN32)
// Try to create native condition variable implementation.
ConditionVariableWrapper* ret_val = ConditionVariableNativeWin::Create();
if (!ret_val) {
@ -31,11 +29,7 @@ ConditionVariableWrapper* ConditionVariableWrapper::CreateConditionVariable() {
ret_val = new ConditionVariableEventWin();
}
return ret_val;
#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
return ConditionVariablePosix::Create();
#else
return NULL;
#endif
}
} // namespace webrtc
#endif // defined(WEBRTC_WIN)

View File

@ -1,127 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/system_wrappers/source/condition_variable_posix.h"
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
#include <errno.h>
#if defined(WEBRTC_LINUX)
#include <time.h>
#else
#include <sys/time.h>
#endif
namespace webrtc {
ConditionVariableWrapper* ConditionVariablePosix::Create() {
ConditionVariablePosix* ptr = new ConditionVariablePosix;
if (!ptr) {
return NULL;
}
const int error = ptr->Construct();
if (error) {
delete ptr;
return NULL;
}
return ptr;
}
ConditionVariablePosix::ConditionVariablePosix() {
}
int ConditionVariablePosix::Construct() {
#ifdef WEBRTC_CLOCK_TYPE_REALTIME
pthread_cond_init(&cond_, NULL);
#else
int result = 0;
pthread_condattr_t cond_attr;
result = pthread_condattr_init(&cond_attr);
if (result != 0) {
return -1;
}
result = pthread_condattr_setclock(&cond_attr, CLOCK_MONOTONIC);
if (result != 0) {
return -1;
}
result = pthread_cond_init(&cond_, &cond_attr);
if (result != 0) {
return -1;
}
result = pthread_condattr_destroy(&cond_attr);
if (result != 0) {
return -1;
}
#endif
return 0;
}
ConditionVariablePosix::~ConditionVariablePosix() {
pthread_cond_destroy(&cond_);
}
void ConditionVariablePosix::SleepCS(CriticalSectionWrapper& crit_sect) {
pthread_cond_wait(&cond_, &crit_sect.mutex_);
}
bool ConditionVariablePosix::SleepCS(CriticalSectionWrapper& crit_sect,
unsigned long max_time_inMS) {
const unsigned long INFINITE = 0xFFFFFFFF;
const int MILLISECONDS_PER_SECOND = 1000;
#ifndef WEBRTC_LINUX
const int MICROSECONDS_PER_MILLISECOND = 1000;
#endif
const int NANOSECONDS_PER_SECOND = 1000000000;
const int NANOSECONDS_PER_MILLISECOND = 1000000;
if (max_time_inMS != INFINITE) {
timespec ts;
#ifndef WEBRTC_MAC
#ifdef WEBRTC_CLOCK_TYPE_REALTIME
clock_gettime(CLOCK_REALTIME, &ts);
#else
clock_gettime(CLOCK_MONOTONIC, &ts);
#endif
#else // WEBRTC_MAC
struct timeval tv;
gettimeofday(&tv, 0);
ts.tv_sec = tv.tv_sec;
ts.tv_nsec = tv.tv_usec * MICROSECONDS_PER_MILLISECOND;
#endif
ts.tv_sec += max_time_inMS / MILLISECONDS_PER_SECOND;
ts.tv_nsec +=
(max_time_inMS
- ((max_time_inMS / MILLISECONDS_PER_SECOND) * MILLISECONDS_PER_SECOND))
* NANOSECONDS_PER_MILLISECOND;
if (ts.tv_nsec >= NANOSECONDS_PER_SECOND) {
ts.tv_sec += ts.tv_nsec / NANOSECONDS_PER_SECOND;
ts.tv_nsec %= NANOSECONDS_PER_SECOND;
}
const int res = pthread_cond_timedwait(&cond_, &crit_sect.mutex_, &ts);
return (res == ETIMEDOUT) ? false : true;
} else {
pthread_cond_wait(&cond_, &crit_sect.mutex_);
return true;
}
}
void ConditionVariablePosix::Wake() {
pthread_cond_signal(&cond_);
}
void ConditionVariablePosix::WakeAll() {
pthread_cond_broadcast(&cond_);
}
} // namespace webrtc

View File

@ -1,42 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_CONDITION_VARIABLE_POSIX_H_
#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_CONDITION_VARIABLE_POSIX_H_
#include <pthread.h>
#include "webrtc/system_wrappers/include/condition_variable_wrapper.h"
#include "webrtc/typedefs.h"
namespace webrtc {
class ConditionVariablePosix : public ConditionVariableWrapper {
public:
static ConditionVariableWrapper* Create();
~ConditionVariablePosix() override;
void SleepCS(CriticalSectionWrapper& crit_sect) override;
bool SleepCS(CriticalSectionWrapper& crit_sect,
unsigned long max_time_in_ms) override;
void Wake() override;
void WakeAll() override;
private:
ConditionVariablePosix();
int Construct();
private:
pthread_cond_t cond_;
};
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_CONDITION_VARIABLE_POSIX_H_

View File

@ -10,6 +10,11 @@
#include "webrtc/system_wrappers/include/condition_variable_wrapper.h"
// TODO(tommi): Remove completely. As is there is still some code for Windows
// that relies on ConditionVariableWrapper, but code has been removed on other
// platforms.
#if defined(WEBRTC_WIN)
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/base/platform_thread.h"
#include "webrtc/base/scoped_ptr.h"
@ -201,3 +206,5 @@ TEST(CondVarWaitTest, WaitingWaits) {
} // anonymous namespace
} // namespace webrtc
#endif // defined(WEBRTC_WIN)

View File

@ -55,8 +55,6 @@
'source/atomic32_win.cc',
'source/clock.cc',
'source/condition_variable.cc',
'source/condition_variable_posix.cc',
'source/condition_variable_posix.h',
'source/condition_variable_event_win.cc',
'source/condition_variable_event_win.h',
'source/condition_variable_native_win.cc',