summaryrefslogtreecommitdiffstats
path: root/cc/scoped_thread_proxy.cc
blob: 03aa6de7e9ea6733c11732879815adfe562ecbda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/scoped_thread_proxy.h"

#include "base/bind.h"

namespace cc {

ScopedThreadProxy::ScopedThreadProxy(cc::Thread* targetThread)
    : m_targetThread(targetThread)
    , m_shutdown(false)
{
}

ScopedThreadProxy::~ScopedThreadProxy()
{
}

void ScopedThreadProxy::postTask(const tracked_objects::Location& location, base::Closure cb)
{
    m_targetThread->postTask(base::Bind(&ScopedThreadProxy::runTaskIfNotShutdown, this, cb));
}

void ScopedThreadProxy::shutdown()
{
    DCHECK(m_targetThread->belongsToCurrentThread());
    DCHECK(!m_shutdown);
    m_shutdown = true;
}

void ScopedThreadProxy::runTaskIfNotShutdown(base::Closure cb)
{
    // If our shutdown flag is set, it's possible that m_targetThread has already been destroyed so don't
    // touch it.
    if (m_shutdown) {
        return;
    }
    DCHECK(m_targetThread->belongsToCurrentThread());
    cb.Run();
}

}  // namespace cc