OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/base/message_loop_factory.h" | 5 #include "media/base/message_loop_factory.h" |
6 | 6 |
7 #include "base/threading/thread.h" | |
8 | |
7 namespace media { | 9 namespace media { |
8 | 10 |
9 MessageLoopFactory::~MessageLoopFactory() {} | 11 MessageLoopFactory::MessageLoopFactory() {} |
12 | |
13 MessageLoopFactory::~MessageLoopFactory() { | |
14 base::AutoLock auto_lock(lock_); | |
Ami GONE FROM CHROMIUM
2012/03/05 23:20:15
Locking in the dtor is a pretty good indicator tha
scherkus (not reviewing)
2012/03/05 23:29:35
I don't think things are borked rather coded defen
acolwell GONE FROM CHROMIUM
2012/03/05 23:53:20
This was an attempt at defensive coding. Nothing s
| |
15 | |
16 for (ThreadMap::iterator iter = thread_map_.begin(); | |
17 iter != thread_map_.end(); | |
18 ++iter) { | |
19 base::Thread* thread = (*iter).second; | |
20 | |
21 if (thread) { | |
22 thread->Stop(); | |
23 delete thread; | |
24 } | |
25 } | |
26 thread_map_.clear(); | |
27 } | |
28 | |
29 MessageLoop* MessageLoopFactory::GetMessageLoop(const std::string& name) { | |
30 base::Thread* thread = GetThread(name); | |
31 return thread ? thread->message_loop() : NULL; | |
32 } | |
33 | |
34 scoped_refptr<base::MessageLoopProxy> | |
35 MessageLoopFactory::GetMessageLoopProxy(const std::string& name) { | |
36 base::Thread* thread = GetThread(name); | |
37 return thread ? thread->message_loop_proxy() : NULL; | |
38 } | |
39 | |
40 base::Thread* MessageLoopFactory::GetThread(const std::string& name) { | |
41 if (name.empty()) | |
42 return NULL; | |
Ami GONE FROM CHROMIUM
2012/03/05 23:20:15
This isn't part of the doco'd interface of the cla
scherkus (not reviewing)
2012/03/05 23:29:35
"NULL is returned if |name| is an empty string" ??
acolwell GONE FROM CHROMIUM
2012/03/05 23:53:20
DCHECK_NE() seems good to me. I think this was one
| |
43 | |
44 base::AutoLock auto_lock(lock_); | |
45 | |
46 ThreadMap::iterator it = thread_map_.find(name); | |
Ami GONE FROM CHROMIUM
2012/03/05 23:20:15
We don't actually make use of this functionality a
scherkus (not reviewing)
2012/03/05 23:29:35
yup but ideally going further by not creating addi
acolwell GONE FROM CHROMIUM
2012/03/05 23:53:20
So the original intent was to share threads across
| |
47 if (it != thread_map_.end()) | |
48 return (*it).second; | |
49 | |
50 base::Thread* thread = new base::Thread(name.c_str()); | |
51 CHECK(thread->Start()) << "Failed to start thread: " << name; | |
52 thread_map_[name] = thread; | |
53 return thread; | |
54 } | |
10 | 55 |
11 } // namespace media | 56 } // namespace media |
OLD | NEW |