Skip to content

Commit

Permalink
A new (private) interface is supplied that allows the object watcher …
Browse files Browse the repository at this point in the history
…(coding in

proress by Darin) to Post the task (when the object is signaled) into a message
loop.

I also cleaned up the time-of-birth for tasks that sleep for a while before
running (such as those held by the timer, or by passed to this new
PostSignaledTask() interface.

r=darin


M    base/tracked.cc
M    base/message_loop.h
M    base/message_loop.cc
M    base/tracked.h



git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jar@google.com committed Aug 1, 2008
1 parent 1f94315 commit ee73678
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
10 changes: 10 additions & 0 deletions base/message_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,15 @@ void MessageLoop::PostDelayedTask(const tracked_objects::Location& from_here,
PostTaskInternal(task);
}

void MessageLoop::PostSignaledTask(Task* task) {
DCHECK(!task->MissingBirthplace());
task->ResetBirthTime();
DCHECK(!task->is_owned_by_message_loop());
task->set_posted_task_delay(0); // Run ASAP, and we take ownership.
DCHECK(task->is_owned_by_message_loop());
PostTaskInternal(task);
}

void MessageLoop::PostTaskInternal(Task* task) {
// Warning: Don't try to short-circuit, and handle this thread's tasks more
// directly, as it could starve handling of foreign threads. Put every task
Expand Down Expand Up @@ -648,6 +657,7 @@ bool MessageLoop::RunTimerTask(Timer* timer) {
DCHECK(!timer->repeating());
timer->set_task(NULL);
delete timer;
task->ResetBirthTime();
return QueueOrRunTask(task);
} else {
// This is an unknown timer task, and we *can't* delay running it, as a
Expand Down
4 changes: 4 additions & 0 deletions base/message_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,10 @@ class MessageLoop {
// Do a PostMessage(), and crash if we can't eventually do the post.
void EnsureMessageGetsPosted(int message) const;

// Post a task that an object watcher has already initialized with the
// place of birth.
void PostSignaledTask(Task* task);

// Post a task to our incomming queue.
void MessageLoop::PostTaskInternal(Task* task);

Expand Down
4 changes: 4 additions & 0 deletions base/tracked.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ void Tracked::SetBirthPlace(const Location& from_here) {
tracked_births_->RecordBirth();
}

void Tracked::ResetBirthTime() {
tracked_birth_time_ = Time::Now();
}

bool Tracked::MissingBirthplace() const {
return -1 == tracked_births_->location().line_number();
}
Expand Down
20 changes: 17 additions & 3 deletions base/tracked.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@
#include "base/time.h"

#ifndef NDEBUG
#ifndef TRACK_ALL_TASK_OBJECTS
#define TRACK_ALL_TASK_OBJECTS
#endif
#endif // TRACK_ALL_TASK_OBJECTS
#endif // NDEBUG

namespace tracked_objects {

Expand Down Expand Up @@ -119,13 +121,25 @@ class Tracked {
public:
Tracked();
virtual ~Tracked();

// Used to record the FROM_HERE location of a caller.
void SetBirthPlace(const Location& from_here);

// When a task sits around a long time, such as in a timer, or object watcher,
// this method should be called when the task becomes active, and its
// significant lifetime begins (and its waiting to be woken up has passed).
void ResetBirthTime();

bool MissingBirthplace() const;

private:
Births* tracked_births_; // At same birthplace, and same thread.
const Time tracked_birth_time_;
// Pointer to instance were counts of objects with the same birth location
// (on the same thread) are stored.
Births* tracked_births_;
// The time this object was constructed. If its life consisted of a long
// waiting period, and then it became active, then this value is generally
// reset before the object begins it active life.
Time tracked_birth_time_;

DISALLOW_EVIL_CONSTRUCTORS(Tracked);
};
Expand Down

0 comments on commit ee73678

Please sign in to comment.