[vlc-devel] commit: Adding a generic singleton pattern implementation ( Hugo Beauzee-Luyssen )

Ruud Althuizen ruud at il.fontys.nl
Fri Dec 25 18:39:25 CET 2009


On Fri 25 Dec 2009 06:19 PM, git version control wrote:
> +    static T*      getInstance( intf_thread_t *p_intf = NULL )
> +    {
> +        if ( m_instance == NULL )
> +            m_instance = new T( p_intf );
> +        return m_instance;
> +    }
Please note that this is not threading safe. It probably doesn't matter in
the VLC cases that it's used, but has caused a lot of problems in a school
project of mine.

> +    static void    killInstance()
> +    {
> +        if ( m_instance != NULL )
> +        {
> +            delete m_instance;
> +            m_instance = NULL;
> +        }
> +    }
A while ago there were a lot of patches that changed this construction to:

  static void    killInstance()
  {
	  delete m_instance;
	  m_instance = NULL;
  }
That is because delete (and free()) will check for NULL pointers anyway.

-- 
Greetings,
Ruud Althuizen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20091225/b3c325e9/attachment.sig>


More information about the vlc-devel mailing list