Singleton.hpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
26 //----------------------------------------------------------------------
27 #ifndef ICL_CORE_SINGLETON_HPP_INCLUDED
28 #define ICL_CORE_SINGLETON_HPP_INCLUDED
29 
30 #include "Singleton.h"
31 
32 namespace icl_core {
33 
34 template
35 <class T, template <class> class TCreationPolicy,
36  template <class> class TLifetimePolicy, template <class> class TThreadingModel>
38 {
39  T *temp = m_instance;
40  TThreadingModel<T>::memoryBarrier();
41  if (temp == NULL)
42  {
43  typename TThreadingModel<T>::Guard guard(m_lock);
44  temp = m_instance;
45  if (temp == NULL)
46  {
47  if (m_destroyed)
48  {
49  TLifetimePolicy<T>::onDeadReference();
50  m_destroyed = false;
51  }
52  temp = TCreationPolicy<T>::create();
53  TThreadingModel<T>::memoryBarrier();
54  m_instance = temp;
55  TLifetimePolicy<T>::scheduleDestruction(&destroySingleton);
56  }
57  }
58  return *m_instance;
59 }
60 
61 template
62 <class T, template <class> class TCreationPolicy,
63  template <class> class TLifetimePolicy, template <class> class TThreadingModel>
65 {
66  TCreationPolicy<T>::destroy(m_instance);
67  m_instance = NULL;
68  m_destroyed = true;
69 }
70 
71 template
72 <class T, template <class> class TCreationPolicy,
73  template <class> class TLifetimePolicy, template <class> class TThreadingModel>
75 
76 template
77 <class T, template <class> class TCreationPolicy,
78  template <class> class TLifetimePolicy, template <class> class TThreadingModel>
80 
81 template
82 <class T, template <class> class TCreationPolicy,
83  template <class> class TLifetimePolicy, template <class> class TThreadingModel>
85 
86 }
87 
88 #endif
Contains icl_core::Singleton.
static void destroySingleton()
Helper for destroying the instance.
Definition: Singleton.hpp:64
static T & instance()
Provide access to the singleton instance.
Definition: Singleton.hpp:37


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58