Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
xbmcutil::GlobalsSingleton< T > Class Template Reference

#include <GlobalsHandling.h>

Static Public Member Functions

static std::shared_ptr< T > getInstance ()
 
static T * getQuick ()
 

Detailed Description

template<class T>
class xbmcutil::GlobalsSingleton< T >

This class is an implementation detail of the macros defined below and is NOT meant to be used as a general purpose utility. IOW, DO NOT USE THIS CLASS to support a general singleton design pattern, it's specialized for solving the initialization/finalization order/dependency problem with global variables and should only be used via the macros below.

Currently THIS IS NOT THREAD SAFE! Why not just add a lock you ask? Because this singleton is used to initialize global variables and there is an issue with having the lock used prior to its initialization. No matter what, if this class is used as a replacement for global variables there's going to be a race condition if it's used anywhere else. So currently this is the only prescribed use.

Therefore this hack depends on the fact that compilation unit global/static initialization is done in a single thread.

Member Function Documentation

◆ getInstance()

template<class T >
static std::shared_ptr< T > xbmcutil::GlobalsSingleton< T >::getInstance ( )
inlinestatic

Retrieve an instance of the singleton using a shared pointer for reference counting.

◆ getQuick()

template<class T >
static T * xbmcutil::GlobalsSingleton< T >::getQuick ( )
inlinestatic

This is for quick access when using form (2) of the pattern. Before 'mdd' points it out, this might be a case of 'solving problems we don't have' but this access is used frequently within the event loop so any help here should benefit the overall performance and there is nothing complicated or tricky here and not a lot of code to maintain.


The documentation for this class was generated from the following file: