////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
+// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
////////////////////////////////////////////////////////////
-#ifndef SFML_MUTEXWIN32_HPP
-#define SFML_MUTEXWIN32_HPP
+#ifndef SFML_THREADLOCAL_HPP
+#define SFML_THREADLOCAL_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
+#include <SFML/System/Export.hpp>
#include <SFML/System/NonCopyable.hpp>
-#include <windows.h>
+#include <cstdlib>
namespace sf
{
+namespace priv
+{
+ class ThreadLocalImpl;
+}
+
////////////////////////////////////////////////////////////
-/// Mutex defines a mutex (MUTual EXclusion) object,
-/// that allows a thread to lock critical instructions
-/// to avoid simultaneous access with other threads.
-/// The Win32 version uses critical sections, as it is
-/// faster than mutexes.<br/>
-/// See Lock for an efficient way of using it.
+/// \brief Defines variables with thread-local storage
+///
////////////////////////////////////////////////////////////
-class SFML_API Mutex : NonCopyable
+class SFML_SYSTEM_API ThreadLocal : NonCopyable
{
-public :
+public:
////////////////////////////////////////////////////////////
- /// Default constructor
+ /// \brief Default constructor
+ ///
+ /// \param value Optional value to initialize the variable
///
////////////////////////////////////////////////////////////
- Mutex();
+ ThreadLocal(void* value = NULL);
////////////////////////////////////////////////////////////
- /// Destructor
+ /// \brief Destructor
///
////////////////////////////////////////////////////////////
- ~Mutex();
+ ~ThreadLocal();
////////////////////////////////////////////////////////////
- /// Lock the mutex
+ /// \brief Set the thread-specific value of the variable
+ ///
+ /// \param value Value of the variable for the current thread
///
////////////////////////////////////////////////////////////
- void Lock();
+ void setValue(void* value);
////////////////////////////////////////////////////////////
- /// Unlock the mutex
+ /// \brief Retrieve the thread-specific value of the variable
+ ///
+ /// \return Value of the variable for the current thread
///
////////////////////////////////////////////////////////////
- void Unlock();
+ void* getValue() const;
-private :
+private:
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
- CRITICAL_SECTION myHandle; ///< Win32 handle of the mutex
+ priv::ThreadLocalImpl* m_impl; ///< Pointer to the OS specific implementation
};
} // namespace sf
-#endif // SFML_MUTEXWIN32_HPP
+#endif // SFML_THREADLOCAL_HPP
+
+
+////////////////////////////////////////////////////////////
+/// \class sf::ThreadLocal
+/// \ingroup system
+///
+/// This class manipulates void* parameters and thus is not
+/// appropriate for strongly-typed variables. You should rather
+/// use the sf::ThreadLocalPtr template class.
+///
+////////////////////////////////////////////////////////////