Removed trailing whitespaces
[libcds.git] / cds / init.h
1 //$$CDS-header$$
2
3 #ifndef CDSLIB_INIT_H
4 #define CDSLIB_INIT_H
5
6 #include <cds/details/defs.h>
7 #include <cds/os/topology.h>
8 #include <cds/threading/model.h>
9 #include <cds/details/lib.h>
10
11 namespace cds {
12
13     //@cond
14     namespace details {
15         bool CDS_EXPORT_API init_first_call();
16         bool CDS_EXPORT_API fini_last_call();
17     }   // namespace details
18     //@endcond
19
20     /// Initialize CDS library
21     /**
22         The function initializes \p CDS library framework.
23         Before usage of \p CDS library features your application must initialize it
24         by calling \p %Initialize() function, see \ref cds_how_to_use "how to use the library".
25
26         You can call \p Initialize several times, only first call is significant others will be ignored.
27         To terminate the \p CDS library correctly, each call to \p %Initialize() must be balanced
28         by a corresponding \p Terminate() call.
29
30         Note, that this function does not initialize garbage collectors. To use GC you need you should call
31         GC-specific constructor function to initialize internal structures of GC.
32         See \p cds::gc for details.
33     */
34     static inline void Initialize(
35         unsigned int nFeatureFlags = 0  ///< for future use, must be zero.
36     )
37     {
38         CDS_UNUSED( nFeatureFlags );
39
40         if ( cds::details::init_first_call() )
41         {
42             cds::OS::topology::init();
43             cds::threading::ThreadData::s_nProcCount = cds::OS::topology::processor_count();
44             if ( cds::threading::ThreadData::s_nProcCount == 0 )
45                 cds::threading::ThreadData::s_nProcCount = 1;
46
47             cds::threading::Manager::init();
48         }
49     }
50
51     /// Terminate CDS library
52     /**
53         This function terminates \p CDS library.
54         After \p %Terminate() calling many features of the library are unavailable.
55         This call should be the last call of \p CDS library in your application,
56         see \ref cds_how_to_use "how to use the library".
57     */
58     static inline void Terminate()
59     {
60         if ( cds::details::fini_last_call() ) {
61             cds::threading::Manager::fini();
62
63             cds::OS::topology::fini();
64         }
65     }
66
67 }   // namespace cds
68
69 #endif // CDSLIB_INIT_H