Made use of atomic variables
In order to replace mutex-protected integer values (Performance improvement) Former-commit-id: d40ed2444111f00dab372f2371fe91cfd9cd2472
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#define NAZARA_RESOURCE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <atomic>
|
||||
#include <set>
|
||||
|
||||
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_RESOURCE
|
||||
@@ -52,7 +53,7 @@ class NAZARA_API NzResource
|
||||
bool RemoveResourceListener(NzResourceListener* listener) const;
|
||||
bool RemoveResourceReference() const;
|
||||
|
||||
void SetPersistent(bool persistent = true, bool checkReferenceCount = false);
|
||||
bool SetPersistent(bool persistent = true, bool checkReferenceCount = false);
|
||||
|
||||
protected:
|
||||
void NotifyCreated();
|
||||
@@ -67,8 +68,8 @@ class NAZARA_API NzResource
|
||||
mutable std::set<NzResourceEntry> m_resourceListeners;
|
||||
mutable std::set<NzResourceEntry> m_resourceListenersCache;
|
||||
mutable bool m_resourceListenerUpdated;
|
||||
bool m_resourcePersistent;
|
||||
mutable unsigned int m_resourceReferenceCount;
|
||||
std::atomic_bool m_resourcePersistent;
|
||||
mutable std::atomic_uint m_resourceReferenceCount;
|
||||
};
|
||||
|
||||
#endif // NAZARA_RESOURCE_HPP
|
||||
|
||||
@@ -9,16 +9,11 @@
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Hashable.hpp>
|
||||
#include <atomic>
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_STRING
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
#else
|
||||
#include <Nazara/Core/ThreadSafetyOff.hpp>
|
||||
#endif
|
||||
|
||||
class NzAbstractHash;
|
||||
class NzHashDigest;
|
||||
|
||||
@@ -282,7 +277,10 @@ class NAZARA_API NzString : public NzHashable
|
||||
|
||||
struct NAZARA_API SharedString
|
||||
{
|
||||
SharedString() = default;
|
||||
SharedString() :
|
||||
refCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
SharedString(unsigned short referenceCount, unsigned int bufferSize, unsigned int stringSize, char* str) :
|
||||
capacity(bufferSize),
|
||||
@@ -296,8 +294,7 @@ class NAZARA_API NzString : public NzHashable
|
||||
unsigned int size;
|
||||
char* string;
|
||||
|
||||
unsigned short refCount = 1;
|
||||
NazaraMutex(mutex)
|
||||
std::atomic_ushort refCount;
|
||||
};
|
||||
|
||||
static SharedString emptyString;
|
||||
|
||||
Reference in New Issue
Block a user