1 : // Copyright 2015 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #ifndef SYZYGY_KASKO_DLL_LIFETIME_H_
16 : #define SYZYGY_KASKO_DLL_LIFETIME_H_
17 :
18 : #include "base/macros.h"
19 : #include "base/memory/ref_counted.h"
20 :
21 m : namespace kasko {
22 :
23 : // Sets up and tears down global Kasko DLL state. Multiple instances may safely
24 : // exist simultaneously. Global state is set up when the first instance is
25 : // constructed and torn down when the last instance is destroyed. Construction
26 : // and destruction is not thread-safe.
27 m : class DllLifetime {
28 m : public:
29 m : DllLifetime();
30 m : ~DllLifetime();
31 :
32 m : private:
33 : // Holds global Kasko DLL state. Only a single Core instance will exist at any
34 : // time.
35 m : class Core;
36 :
37 : // A refcount to prevent the global Core instance from being destroyed while
38 : // this DllLifetime is alive.
39 m : scoped_refptr<Core> core_;
40 :
41 m : DISALLOW_COPY_AND_ASSIGN(DllLifetime);
42 m : };
43 :
44 m : } // namespace kasko
45 :
46 : #endif // SYZYGY_KASKO_DLL_LIFETIME_H_
|