Made sf::Resource thread-safe

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1404 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2010-02-12 08:09:54 +00:00
parent 0a7d28b687
commit 8a1a6bbfab
5 changed files with 6 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -28,6 +28,8 @@
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Lock.hpp>
#include <SFML/System/Mutex.hpp>
#include <set>
@ -111,7 +113,8 @@ private :
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
mutable std::set<ResourcePtr<T>*> myObservers;
mutable std::set<ResourcePtr<T>*> myObservers; ///< List of pointers to this resource
mutable Mutex myMutex; ///< Mutex for preventing concurrent access to the pointer list
};

View File

@ -64,6 +64,7 @@ Resource<T>& Resource<T>::operator =(const Resource<T>&)
template <typename T>
void Resource<T>::Connect(ResourcePtr<T>& observer) const
{
sf::Lock lock(myMutex);
myObservers.insert(&observer);
}
@ -72,5 +73,6 @@ void Resource<T>::Connect(ResourcePtr<T>& observer) const
template <typename T>
void Resource<T>::Disconnect(ResourcePtr<T>& observer) const
{
sf::Lock lock(myMutex);
myObservers.erase(&observer);
}