OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "services/media/framework/util/incident.h" | |
6 | |
7 namespace mojo { | |
8 namespace media { | |
9 | |
10 Incident::Incident() {} | |
11 | |
12 Incident::~Incident() {} | |
13 | |
14 void Incident::Occur() { | |
15 if (occurred_) { | |
16 return; | |
17 } | |
18 | |
19 occurred_ = true; | |
20 | |
21 // Swap out consequences_ in case one of the callbacks deletes this. | |
22 std::vector<std::function<void()>> consequences; | |
23 consequences_.swap(consequences); | |
24 | |
25 for (const std::function<void()>& consequence : consequences) { | |
26 consequence(); | |
27 } | |
28 } | |
29 | |
30 ThreadsafeIncident::ThreadsafeIncident() {} | |
31 | |
32 ThreadsafeIncident::~ThreadsafeIncident() {} | |
33 | |
34 void ThreadsafeIncident::Occur() { | |
35 std::vector<std::function<void()>> consequences; | |
36 | |
37 { | |
38 base::AutoLock lock(consequences_lock_); | |
39 | |
40 if (occurred_) { | |
41 return; | |
42 } | |
43 | |
44 occurred_ = true; | |
45 consequences_.swap(consequences); | |
46 } | |
47 | |
48 for (const std::function<void()>& consequence : consequences) { | |
49 consequence(); | |
50 } | |
51 } | |
52 | |
53 } // namespace media | |
54 } // namespace mojo | |
OLD | NEW |