mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
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:
parent
0a7d28b687
commit
8a1a6bbfab
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -28,6 +28,8 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
#include <SFML/System/Lock.hpp>
|
||||||
|
#include <SFML/System/Mutex.hpp>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
|
||||||
@ -111,7 +113,8 @@ private :
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// 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
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@ Resource<T>& Resource<T>::operator =(const Resource<T>&)
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void Resource<T>::Connect(ResourcePtr<T>& observer) const
|
void Resource<T>::Connect(ResourcePtr<T>& observer) const
|
||||||
{
|
{
|
||||||
|
sf::Lock lock(myMutex);
|
||||||
myObservers.insert(&observer);
|
myObservers.insert(&observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,5 +73,6 @@ void Resource<T>::Connect(ResourcePtr<T>& observer) const
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void Resource<T>::Disconnect(ResourcePtr<T>& observer) const
|
void Resource<T>::Disconnect(ResourcePtr<T>& observer) const
|
||||||
{
|
{
|
||||||
|
sf::Lock lock(myMutex);
|
||||||
myObservers.erase(&observer);
|
myObservers.erase(&observer);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user