OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 template <class T> | 34 template <class T> |
35 // Construct On First Use idiom. Avoids | 35 // Construct On First Use idiom. Avoids |
36 // "static initialization order fiasco". | 36 // "static initialization order fiasco". |
37 static T* GetStaticInstance(CountOperation count_operation) { | 37 static T* GetStaticInstance(CountOperation count_operation) { |
38 // TODO (hellner): use atomic wrapper instead. | 38 // TODO (hellner): use atomic wrapper instead. |
39 static volatile long instance_count = 0; | 39 static volatile long instance_count = 0; |
40 static T* volatile instance = NULL; | 40 static T* volatile instance = NULL; |
41 CreateOperation state = kInstanceExists; | 41 CreateOperation state = kInstanceExists; |
42 #ifndef _WIN32 | 42 #ifndef _WIN32 |
43 rtc::CriticalSection crit_sect; | 43 static rtc::CriticalSection crit_sect; |
44 rtc::CritScope lock(&crit_sect); | 44 rtc::CritScope lock(&crit_sect); |
45 | 45 |
46 if (count_operation == | 46 if (count_operation == |
47 kAddRefNoCreate && instance_count == 0) { | 47 kAddRefNoCreate && instance_count == 0) { |
48 return NULL; | 48 return NULL; |
49 } | 49 } |
50 if (count_operation == | 50 if (count_operation == |
51 kAddRef || | 51 kAddRef || |
52 count_operation == kAddRefNoCreate) { | 52 count_operation == kAddRefNoCreate) { |
53 instance_count++; | 53 instance_count++; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 } | 138 } |
139 return NULL; | 139 return NULL; |
140 } | 140 } |
141 #endif // #ifndef _WIN32 | 141 #endif // #ifndef _WIN32 |
142 return instance; | 142 return instance; |
143 } | 143 } |
144 | 144 |
145 } // namspace webrtc | 145 } // namspace webrtc |
146 | 146 |
147 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STATIC_INSTANCE_H_ | 147 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STATIC_INSTANCE_H_ |
OLD | NEW |