Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Side by Side Diff: src/core/SkMessageBus.h

Issue 1949313003: Reland of SkOncePtr -> SkOnce (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkImageFilterCache.cpp ('k') | src/core/SkMiniRecorder.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkMessageBus_DEFINED 8 #ifndef SkMessageBus_DEFINED
9 #define SkMessageBus_DEFINED 9 #define SkMessageBus_DEFINED
10 10
11 #include "SkMutex.h" 11 #include "SkMutex.h"
12 #include "SkOncePtr.h" 12 #include "SkOnce.h"
13 #include "SkTArray.h" 13 #include "SkTArray.h"
14 #include "SkTDArray.h" 14 #include "SkTDArray.h"
15 #include "SkTypes.h" 15 #include "SkTypes.h"
16 16
17 template <typename Message> 17 template <typename Message>
18 class SkMessageBus : SkNoncopyable { 18 class SkMessageBus : SkNoncopyable {
19 public: 19 public:
20 // Post a message to be received by all Inboxes for this Message type. Thre adsafe. 20 // Post a message to be received by all Inboxes for this Message type. Thre adsafe.
21 static void Post(const Message& m); 21 static void Post(const Message& m);
22 22
(...skipping 17 matching lines...) Expand all
40 SkMessageBus(); 40 SkMessageBus();
41 static SkMessageBus* Get(); 41 static SkMessageBus* Get();
42 42
43 SkTDArray<Inbox*> fInboxes; 43 SkTDArray<Inbox*> fInboxes;
44 SkMutex fInboxesMutex; 44 SkMutex fInboxesMutex;
45 }; 45 };
46 46
47 // This must go in a single .cpp file, not some .h, or we risk creating more tha n one global 47 // This must go in a single .cpp file, not some .h, or we risk creating more tha n one global
48 // SkMessageBus per type when using shared libraries. NOTE: at most one per fil e will compile. 48 // SkMessageBus per type when using shared libraries. NOTE: at most one per fil e will compile.
49 #define DECLARE_SKMESSAGEBUS_MESSAGE(Message) \ 49 #define DECLARE_SKMESSAGEBUS_MESSAGE(Message) \
50 SK_DECLARE_STATIC_ONCE_PTR(SkMessageBus<Message>, bus); \
51 template <> \ 50 template <> \
52 SkMessageBus<Message>* SkMessageBus<Message>::Get() { \ 51 SkMessageBus<Message>* SkMessageBus<Message>::Get() { \
53 return bus.get([]{ return new SkMessageBus<Message>(); }); \ 52 static SkOnce once; \
53 static SkMessageBus<Message>* bus; \
54 once([] { bus = new SkMessageBus<Message>(); }); \
55 return bus; \
54 } 56 }
55 57
56 // ----------------------- Implementation of SkMessageBus::Inbox ------------- ---------- 58 // ----------------------- Implementation of SkMessageBus::Inbox ------------- ----------
57 59
58 template<typename Message> 60 template<typename Message>
59 SkMessageBus<Message>::Inbox::Inbox() { 61 SkMessageBus<Message>::Inbox::Inbox() {
60 // Register ourselves with the corresponding message bus. 62 // Register ourselves with the corresponding message bus.
61 SkMessageBus<Message>* bus = SkMessageBus<Message>::Get(); 63 SkMessageBus<Message>* bus = SkMessageBus<Message>::Get();
62 SkAutoMutexAcquire lock(bus->fInboxesMutex); 64 SkAutoMutexAcquire lock(bus->fInboxesMutex);
63 bus->fInboxes.push(this); 65 bus->fInboxes.push(this);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 template <typename Message> 101 template <typename Message>
100 /*static*/ void SkMessageBus<Message>::Post(const Message& m) { 102 /*static*/ void SkMessageBus<Message>::Post(const Message& m) {
101 SkMessageBus<Message>* bus = SkMessageBus<Message>::Get(); 103 SkMessageBus<Message>* bus = SkMessageBus<Message>::Get();
102 SkAutoMutexAcquire lock(bus->fInboxesMutex); 104 SkAutoMutexAcquire lock(bus->fInboxesMutex);
103 for (int i = 0; i < bus->fInboxes.count(); i++) { 105 for (int i = 0; i < bus->fInboxes.count(); i++) {
104 bus->fInboxes[i]->receive(m); 106 bus->fInboxes[i]->receive(m);
105 } 107 }
106 } 108 }
107 109
108 #endif // SkMessageBus_DEFINED 110 #endif // SkMessageBus_DEFINED
OLDNEW
« no previous file with comments | « src/core/SkImageFilterCache.cpp ('k') | src/core/SkMiniRecorder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698