blob: 6cf12da3f0b406cec0165783b27811a93980cda7 (
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
|
// Copyright (c) 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 "media/base/message_loop_factory_impl.h"
namespace media {
MessageLoopFactoryImpl::MessageLoopFactoryImpl() {}
MessageLoopFactoryImpl::~MessageLoopFactoryImpl() {
base::AutoLock auto_lock(lock_);
for (ThreadMap::iterator iter = thread_map_.begin();
iter != thread_map_.end();
++iter) {
base::Thread* thread = (*iter).second;
if (thread) {
thread->Stop();
delete thread;
}
}
thread_map_.clear();
}
// MessageLoopFactory methods.
MessageLoop* MessageLoopFactoryImpl::GetMessageLoop(const std::string& name) {
if (name.empty()) {
return NULL;
}
base::AutoLock auto_lock(lock_);
ThreadMap::iterator it = thread_map_.find(name);
if (it != thread_map_.end())
return (*it).second->message_loop();
scoped_ptr<base::Thread> thread(new base::Thread(name.c_str()));
if (thread->Start()) {
MessageLoop* message_loop = thread->message_loop();
thread_map_[name] = thread.release();
return message_loop;
}
LOG(ERROR) << "Failed to start '" << name << "' thread!";
return NULL;
}
scoped_refptr<base::MessageLoopProxy>
MessageLoopFactoryImpl::GetMessageLoopProxy(const std::string& name) {
if (name.empty()) {
return NULL;
}
base::AutoLock auto_lock(lock_);
ThreadMap::iterator it = thread_map_.find(name);
if (it != thread_map_.end())
return (*it).second->message_loop_proxy();
scoped_ptr<base::Thread> thread(new base::Thread(name.c_str()));
if (thread->Start()) {
scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
thread->message_loop_proxy();
thread_map_[name] = thread.release();
return message_loop_proxy;
}
LOG(ERROR) << "Failed to start '" << name << "' thread!";
return NULL;
}
} // namespace media
|