Line data Source code
1 : /*
2 : * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 : *
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
6 : * tree. An additional intellectual property rights grant can be found
7 : * in the file PATENTS. All contributing project authors may
8 : * be found in the AUTHORS file in the root of the source tree.
9 : */
10 :
11 : #ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STATIC_INSTANCE_H_
12 : #define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STATIC_INSTANCE_H_
13 :
14 : #include <assert.h>
15 :
16 : #if defined(WEBRTC_ANDROID) || defined(WEBRTC_GONK)
17 : #define OS_LINUX
18 : #endif
19 : #include "base/singleton.h"
20 :
21 : namespace webrtc {
22 :
23 : enum CountOperation {
24 : kRelease,
25 : kAddRef,
26 : kAddRefNoCreate
27 : };
28 : enum CreateOperation {
29 : kInstanceExists,
30 : kCreate,
31 : kDestroy
32 : };
33 :
34 : template <class T>
35 : // Construct On First Use idiom. Avoids
36 : // "static initialization order fiasco".
37 0 : static T* GetStaticInstance(CountOperation count_operation) {
38 : // Simple solution since we don't use this for large objects anymore
39 0 : return Singleton<T>::get();
40 : }
41 :
42 : } // namspace webrtc
43 :
44 : #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STATIC_INSTANCE_H_
|