summaryrefslogtreecommitdiffstats
path: root/cc/proxy.cc
blob: 9a07254c24aa6765f9d09ae60695f91672c17667 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// 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/proxy.h"

#include "cc/thread.h"
#include "cc/thread_impl.h"

namespace cc {

Thread* Proxy::mainThread() const
{
    return m_mainThread.get();
}

bool Proxy::hasImplThread() const
{
    return m_implThread;
}

Thread* Proxy::implThread() const
{
    return m_implThread.get();
}

Thread* Proxy::currentThread() const
{
    if (mainThread() && mainThread()->belongsToCurrentThread())
        return mainThread();
    if (implThread() && implThread()->belongsToCurrentThread())
        return implThread();
    return 0;
}

bool Proxy::isMainThread() const
{
#ifndef NDEBUG
    DCHECK(mainThread());
    if (m_implThreadIsOverridden)
        return false;
    return mainThread()->belongsToCurrentThread();
#else
    return true;
#endif
}

bool Proxy::isImplThread() const
{
#ifndef NDEBUG
    if (m_implThreadIsOverridden)
        return true;
    return implThread() && implThread()->belongsToCurrentThread();
#else
    return true;
#endif
}

#ifndef NDEBUG
void Proxy::setCurrentThreadIsImplThread(bool isImplThread)
{
    m_implThreadIsOverridden = isImplThread;
}
#endif

bool Proxy::isMainThreadBlocked() const
{
#ifndef NDEBUG
    return m_isMainThreadBlocked;
#else
    return true;
#endif
}

#ifndef NDEBUG
void Proxy::setMainThreadBlocked(bool isMainThreadBlocked)
{
    m_isMainThreadBlocked = isMainThreadBlocked;
}
#endif

Proxy::Proxy(scoped_ptr<Thread> implThread)
    : m_mainThread(ThreadImpl::createForCurrentThread())
    , m_implThread(implThread.Pass())
#ifndef NDEBUG
    , m_implThreadIsOverridden(false)
    , m_isMainThreadBlocked(false)
#endif
{
}

Proxy::~Proxy()
{
    DCHECK(isMainThread());
}

}  // namespace cc