6 #include <cds/details/defs.h>
7 #include <cds/os/topology.h>
8 #include <cds/threading/model.h>
9 #include <cds/details/lib.h>
15 bool CDS_EXPORT_API init_first_call();
16 bool CDS_EXPORT_API fini_last_call();
17 } // namespace details
20 /// Initialize CDS library
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:
27 #include <cds/gc/hp.h>
31 // // Initialize CDS library
35 // // Initialize Hazard Pointer GC (if it is needed for you)
38 // // Now you can use CDS library containers with Hazard Pointer GC
42 // // Teminate CDS library
49 You may call \p Initialize several times, only first call is significant others will be ignored.
50 To terminate the \p CDS library correctly, each call to \p Initialize must be balanced by a corresponding call to \ref Terminate.
52 Note, that this function does not initialize garbage collectors. To use GC you need you should call
53 GC-specific constructor function to initialize internal structures of GC. See cds::gc and its subnamespace for details.
55 static inline void Initialize(
56 unsigned int nFeatureFlags = 0 ///< for future use, must be zero.
59 CDS_UNUSED( nFeatureFlags );
61 if ( cds::details::init_first_call() )
63 cds::OS::topology::init();
64 cds::threading::ThreadData::s_nProcCount = cds::OS::topology::processor_count();
65 if ( cds::threading::ThreadData::s_nProcCount == 0 )
66 cds::threading::ThreadData::s_nProcCount = 1;
68 cds::threading::Manager::init();
72 /// Terminate CDS library
74 This function terminates \p CDS library.
75 After \p Terminate calling many features of the library are unavailable.
76 This call should be the last call of \p CDS library in your application.
78 static inline void Terminate()
80 if ( cds::details::fini_last_call() ) {
81 cds::threading::Manager::fini();
83 cds::OS::topology::fini();
89 #endif // __CDS_INIT_H