workers: Map the current thread-id to the WorkerRunLoop.

Instead of using an AtomicSequenceNumber to find an ID for a worker runloop,
use the ID of the current thread instead.

BUG=none
R=jochen@chromium.org

Review URL: https://codereview.chromium.org/886593002

Cr-Commit-Position: refs/heads/master@{#313786}
parent 97b62a99
...@@ -36,9 +36,6 @@ struct WorkerTaskRunner::ThreadLocalState { ...@@ -36,9 +36,6 @@ struct WorkerTaskRunner::ThreadLocalState {
}; };
WorkerTaskRunner::WorkerTaskRunner() { WorkerTaskRunner::WorkerTaskRunner() {
// Start worker ids at 1, 0 is reserved for the main thread.
int id = id_sequence_.GetNext();
DCHECK(!id);
} }
bool WorkerTaskRunner::PostTask( bool WorkerTaskRunner::PostTask(
...@@ -86,7 +83,8 @@ WorkerTaskRunner::~WorkerTaskRunner() { ...@@ -86,7 +83,8 @@ WorkerTaskRunner::~WorkerTaskRunner() {
void WorkerTaskRunner::OnWorkerRunLoopStarted(const WebWorkerRunLoop& loop) { void WorkerTaskRunner::OnWorkerRunLoopStarted(const WebWorkerRunLoop& loop) {
DCHECK(!current_tls_.Get()); DCHECK(!current_tls_.Get());
int id = id_sequence_.GetNext(); DCHECK(!base::PlatformThread::CurrentRef().is_null());
int id = base::PlatformThread::CurrentId();
current_tls_.Set(new ThreadLocalState(id)); current_tls_.Set(new ThreadLocalState(id));
base::AutoLock locker_(loop_map_lock_); base::AutoLock locker_(loop_map_lock_);
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
#include <map> #include <map>
#include "base/atomic_sequence_num.h"
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread_local.h" #include "base/threading/thread_local.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "third_party/WebKit/public/platform/WebWorkerRunLoop.h" #include "third_party/WebKit/public/platform/WebWorkerRunLoop.h"
...@@ -42,14 +42,13 @@ class CONTENT_EXPORT WorkerTaskRunner { ...@@ -42,14 +42,13 @@ class CONTENT_EXPORT WorkerTaskRunner {
private: private:
friend class WorkerTaskRunnerTest; friend class WorkerTaskRunnerTest;
typedef std::map<int, blink::WebWorkerRunLoop> IDToLoopMap; typedef std::map<base::PlatformThreadId, blink::WebWorkerRunLoop> IDToLoopMap;
~WorkerTaskRunner(); ~WorkerTaskRunner();
struct ThreadLocalState; struct ThreadLocalState;
base::ThreadLocalPointer<ThreadLocalState> current_tls_; base::ThreadLocalPointer<ThreadLocalState> current_tls_;
base::AtomicSequenceNumber id_sequence_;
IDToLoopMap loop_map_; IDToLoopMap loop_map_;
base::Lock loop_map_lock_; base::Lock loop_map_lock_;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment