Files
NazaraEngine/include/Nazara/Core/Resource.hpp
Lynix 42c10268d2 Fixed thread-safety
Fixed huge mistake in Clock code (Allocating a mutex everytime instead
of locking it)
HashDigest and StringStream class are no longer thread-safe (That was
stupid anyway)


Former-commit-id: d07a6859df27eac2c5171e75720b3963b6a5fbbb
2014-03-06 09:49:39 +01:00

59 lines
1.6 KiB
C++

// Copyright (C) 2014 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_RESOURCE_HPP
#define NAZARA_RESOURCE_HPP
#include <Nazara/Prerequesites.hpp>
#include <atomic>
#include <unordered_map>
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_RESOURCE
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
#endif
class NzResourceListener;
class NAZARA_API NzResource
{
public:
NzResource(bool persistent = true);
virtual ~NzResource();
void AddResourceListener(NzResourceListener* listener, int index = 0) const;
void AddResourceReference() const;
unsigned int GetResourceReferenceCount() const;
bool IsPersistent() const;
void RemoveResourceListener(NzResourceListener* listener) const;
bool RemoveResourceReference() const;
bool SetPersistent(bool persistent = true, bool checkReferenceCount = false);
protected:
void NotifyCreated();
void NotifyDestroy();
private:
typedef std::unordered_map<NzResourceListener*, std::pair<int, unsigned int>> ResourceListenerMap;
void RemoveResourceListenerIterator(ResourceListenerMap::iterator iterator) const;
NazaraMutexAttrib(m_mutex, mutable)
// Je fais précéder le nom par 'resource' pour éviter les éventuels conflits de noms
mutable ResourceListenerMap m_resourceListeners;
std::atomic_bool m_resourcePersistent;
mutable std::atomic_uint m_resourceReferenceCount;
bool m_resourceListenersLocked;
};
#endif // NAZARA_RESOURCE_HPP