Skip to content

Commit

Permalink
Remove old Sleep and PostDelayedTask interfaces that use int ms inste…
Browse files Browse the repository at this point in the history
…ad of TimeDelta.

The previous version of this patch was reverted due to crashing cros_x86 and cros_tegra2 builds.  See: http://codereview.chromium.org/9703053/

BUG=108171

Review URL: https://chromiumcodereview.appspot.com/10572030

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143401 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tedvessenes@gmail.com committed Jun 21, 2012
1 parent 131816e commit beea992
Show file tree
Hide file tree
Showing 25 changed files with 156 additions and 288 deletions.
51 changes: 20 additions & 31 deletions base/message_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,48 +258,38 @@ void MessageLoop::RemoveDestructionObserver(
void MessageLoop::PostTask(
const tracked_objects::Location& from_here, const base::Closure& task) {
DCHECK(!task.is_null()) << from_here.ToString();
PendingTask pending_task(from_here, task, CalculateDelayedRuntime(0), true);
PendingTask pending_task(
from_here, task, CalculateDelayedRuntime(TimeDelta()), true);
AddToIncomingQueue(&pending_task);
}

void MessageLoop::PostDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
int64 delay_ms) {
TimeDelta delay) {
DCHECK(!task.is_null()) << from_here.ToString();
PendingTask pending_task(from_here, task,
CalculateDelayedRuntime(delay_ms), true);
PendingTask pending_task(
from_here, task, CalculateDelayedRuntime(delay), true);
AddToIncomingQueue(&pending_task);
}

void MessageLoop::PostDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
base::TimeDelta delay) {
PostDelayedTask(from_here, task, delay.InMillisecondsRoundedUp());
}

void MessageLoop::PostNonNestableTask(
const tracked_objects::Location& from_here, const base::Closure& task) {
DCHECK(!task.is_null()) << from_here.ToString();
PendingTask pending_task(from_here, task, CalculateDelayedRuntime(0), false);
AddToIncomingQueue(&pending_task);
}

void MessageLoop::PostNonNestableDelayedTask(
const tracked_objects::Location& from_here, const base::Closure& task,
int64 delay_ms) {
const tracked_objects::Location& from_here,
const base::Closure& task) {
DCHECK(!task.is_null()) << from_here.ToString();
PendingTask pending_task(from_here, task,
CalculateDelayedRuntime(delay_ms), false);
PendingTask pending_task(
from_here, task, CalculateDelayedRuntime(TimeDelta()), false);
AddToIncomingQueue(&pending_task);
}

void MessageLoop::PostNonNestableDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
base::TimeDelta delay) {
PostNonNestableDelayedTask(from_here, task, delay.InMillisecondsRoundedUp());
TimeDelta delay) {
DCHECK(!task.is_null()) << from_here.ToString();
PendingTask pending_task(
from_here, task, CalculateDelayedRuntime(delay), false);
AddToIncomingQueue(&pending_task);
}

void MessageLoop::Run() {
Expand Down Expand Up @@ -543,11 +533,10 @@ bool MessageLoop::DeletePendingTasks() {
return did_work;
}

TimeTicks MessageLoop::CalculateDelayedRuntime(int64 delay_ms) {
TimeTicks MessageLoop::CalculateDelayedRuntime(TimeDelta delay) {
TimeTicks delayed_run_time;
if (delay_ms > 0) {
delayed_run_time =
TimeTicks::Now() + TimeDelta::FromMilliseconds(delay_ms);
if (delay > TimeDelta()) {
delayed_run_time = TimeTicks::Now() + delay;

#if defined(OS_WIN)
if (high_resolution_timer_expiration_.is_null()) {
Expand All @@ -556,8 +545,8 @@ TimeTicks MessageLoop::CalculateDelayedRuntime(int64 delay_ms) {
// which as a percentage is pretty inaccurate. So enable high
// res timers for any timer which is within 2x of the granularity.
// This is a tradeoff between accuracy and power management.
bool needs_high_res_timers =
delay_ms < (2 * base::Time::kMinLowResolutionThresholdMs);
bool needs_high_res_timers = delay.InMilliseconds() <
(2 * base::Time::kMinLowResolutionThresholdMs);
if (needs_high_res_timers) {
if (base::Time::ActivateHighResolutionTimer(true)) {
high_resolution_timer_expiration_ = TimeTicks::Now() +
Expand All @@ -567,7 +556,7 @@ TimeTicks MessageLoop::CalculateDelayedRuntime(int64 delay_ms) {
}
#endif
} else {
DCHECK_EQ(delay_ms, 0) << "delay should not be negative";
DCHECK_EQ(delay.InMilliseconds(), 0) << "delay should not be negative";
}

#if defined(OS_WIN)
Expand Down
10 changes: 1 addition & 9 deletions base/message_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
const tracked_objects::Location& from_here,
const base::Closure& task);

void PostDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task, int64 delay_ms);

void PostDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
Expand All @@ -176,10 +172,6 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
const tracked_objects::Location& from_here,
const base::Closure& task);

void PostNonNestableDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task, int64 delay_ms);

void PostNonNestableDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
Expand Down Expand Up @@ -449,7 +441,7 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
bool DeletePendingTasks();

// Calculates the time at which a PendingTask should run.
base::TimeTicks CalculateDelayedRuntime(int64 delay_ms);
base::TimeTicks CalculateDelayedRuntime(base::TimeDelta delay);

// Start recording histogram info about events and action IF it was enabled
// and IF the statistics recorder can accept a registration of our histogram.
Expand Down
18 changes: 0 additions & 18 deletions base/message_loop_proxy_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,6 @@ namespace base {
MessageLoopProxyImpl::~MessageLoopProxyImpl() {
}

// This function will be removed later in the fixing of CR Bug #108171.
bool MessageLoopProxyImpl::PostDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
int64 delay_ms) {
return PostDelayedTask(
from_here, task, base::TimeDelta::FromMilliseconds(delay_ms));
}

// This function will be removed later in the fixing of CR Bug #108171.
bool MessageLoopProxyImpl::PostNonNestableDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
int64 delay_ms) {
return PostNonNestableDelayedTask(
from_here, task, base::TimeDelta::FromMilliseconds(delay_ms));
}

bool MessageLoopProxyImpl::PostDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
Expand Down
7 changes: 0 additions & 7 deletions base/message_loop_proxy_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,9 @@ namespace base {
class BASE_EXPORT MessageLoopProxyImpl : public MessageLoopProxy {
public:
// MessageLoopProxy implementation
virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
const base::Closure& task,
int64 delay_ms) OVERRIDE;
virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
const base::Closure& task,
base::TimeDelta delay) OVERRIDE;
virtual bool PostNonNestableDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
int64 delay_ms) OVERRIDE;
virtual bool PostNonNestableDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
Expand Down
2 changes: 1 addition & 1 deletion base/sequenced_task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace base {
bool SequencedTaskRunner::PostNonNestableTask(
const tracked_objects::Location& from_here,
const Closure& task) {
return PostNonNestableDelayedTask(from_here, task, 0);
return PostNonNestableDelayedTask(from_here, task, base::TimeDelta());
}

bool SequencedTaskRunner::DeleteSoonInternal(
Expand Down
5 changes: 0 additions & 5 deletions base/sequenced_task_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ class BASE_EXPORT SequencedTaskRunner : public TaskRunner {
bool PostNonNestableTask(const tracked_objects::Location& from_here,
const Closure& task);

virtual bool PostNonNestableDelayedTask(
const tracked_objects::Location& from_here,
const Closure& task,
int64 delay_ms) = 0;

virtual bool PostNonNestableDelayedTask(
const tracked_objects::Location& from_here,
const Closure& task,
Expand Down
2 changes: 1 addition & 1 deletion base/task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool PostTaskAndReplyTaskRunner::PostTask(

bool TaskRunner::PostTask(const tracked_objects::Location& from_here,
const Closure& task) {
return PostDelayedTask(from_here, task, 0);
return PostDelayedTask(from_here, task, base::TimeDelta());
}

bool TaskRunner::PostTaskAndReply(
Expand Down
5 changes: 0 additions & 5 deletions base/task_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ class BASE_EXPORT TaskRunner
//
// It is valid for an implementation to ignore |delay_ms|; that is,
// to have PostDelayedTask behave the same as PostTask.
//
// TODO(tedv): Make PostDelayedTask use TimeDelta instead.
virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
const Closure& task,
int64 delay_ms) = 0;
virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
const Closure& task,
base::TimeDelta delay) = 0;
Expand Down
3 changes: 0 additions & 3 deletions base/threading/platform_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ class BASE_EXPORT PlatformThread {
// Yield the current thread so another thread can be scheduled.
static void YieldCurrentThread();

// Sleeps for the specified duration (units are milliseconds).
static void Sleep(int duration_ms);

// Sleeps for the specified duration.
static void Sleep(base::TimeDelta duration);

Expand Down
7 changes: 0 additions & 7 deletions base/threading/platform_thread_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,6 @@ void PlatformThread::YieldCurrentThread() {
sched_yield();
}

// static
void PlatformThread::Sleep(int duration_ms) {
// NOTE: This function will be supplanted by the other version of Sleep
// in the future. See issue 108171 for more information.
Sleep(TimeDelta::FromMilliseconds(duration_ms));
}

// static
void PlatformThread::Sleep(TimeDelta duration) {
struct timespec sleep_time, remaining;
Expand Down
5 changes: 0 additions & 5 deletions base/threading/platform_thread_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ void PlatformThread::YieldCurrentThread() {
::Sleep(0);
}

// static
void PlatformThread::Sleep(int duration_ms) {
::Sleep(duration_ms);
}

// static
void PlatformThread::Sleep(TimeDelta duration) {
::Sleep(duration.InMillisecondsRoundedUp());
Expand Down
Loading

0 comments on commit beea992

Please sign in to comment.