mirror of https://github.com/OpenMW/openmw.git
removes UnrefQueue (#3181)
Currently, we use an `UnrefQueue` which supposedly aims to transfer destruction costs to another thread. The implications of this unusual pattern can not be well understood because some allocators might free resources more efficiently if they are freed by the same thread that allocated them. In addition, `UnrefQueue` complicates the validation of thread safety in our engine. Lastly, our current usage of `UnrefQueue` triggers `ref()`, `unref()` atomic operations as objects are passed into the queue. These operations could be more expensive than the actual destruction. With this PR we thus remove `UnrefQueue`. We can expect these changes to have a minor impact at most because we free most resources elsewhere in `ResourceSystem::updateCache`.pull/3185/head
parent
fc32793cc6
commit
a854a6e04a
@ -1,39 +0,0 @@
|
||||
#include "unrefqueue.hpp"
|
||||
|
||||
//#include <osg/Timer>
|
||||
|
||||
//#include <components/debug/debuglog.hpp>
|
||||
|
||||
namespace SceneUtil
|
||||
{
|
||||
void UnrefWorkItem::doWork()
|
||||
{
|
||||
mObjects.clear();
|
||||
}
|
||||
|
||||
UnrefQueue::UnrefQueue()
|
||||
{
|
||||
mWorkItem = new UnrefWorkItem;
|
||||
}
|
||||
|
||||
void UnrefQueue::push(const osg::Referenced *obj)
|
||||
{
|
||||
mWorkItem->mObjects.emplace_back(obj);
|
||||
}
|
||||
|
||||
void UnrefQueue::flush(SceneUtil::WorkQueue *workQueue)
|
||||
{
|
||||
if (mWorkItem->mObjects.empty())
|
||||
return;
|
||||
|
||||
workQueue->addWorkItem(mWorkItem, true);
|
||||
|
||||
mWorkItem = new UnrefWorkItem;
|
||||
}
|
||||
|
||||
unsigned int UnrefQueue::getNumItems() const
|
||||
{
|
||||
return mWorkItem->mObjects.size();
|
||||
}
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
#ifndef OPENMW_COMPONENTS_UNREFQUEUE_H
|
||||
#define OPENMW_COMPONENTS_UNREFQUEUE_H
|
||||
|
||||
#include <deque>
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Referenced>
|
||||
|
||||
#include <components/sceneutil/workqueue.hpp>
|
||||
|
||||
namespace SceneUtil
|
||||
{
|
||||
class WorkQueue;
|
||||
|
||||
class UnrefWorkItem : public SceneUtil::WorkItem
|
||||
{
|
||||
public:
|
||||
std::deque<osg::ref_ptr<const osg::Referenced> > mObjects;
|
||||
void doWork() override;
|
||||
};
|
||||
|
||||
/// @brief Handles unreferencing of objects through the WorkQueue. Typical use scenario
|
||||
/// would be the main thread pushing objects that are no longer needed, and the background thread deleting them.
|
||||
class UnrefQueue : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
UnrefQueue();
|
||||
|
||||
/// Adds an object to the list of objects to be unreferenced. Call from the main thread.
|
||||
void push(const osg::Referenced* obj);
|
||||
|
||||
/// Adds a WorkItem to the given WorkQueue that will clear the list of objects in a worker thread, thus unreferencing them.
|
||||
/// Call from the main thread.
|
||||
void flush(SceneUtil::WorkQueue* workQueue);
|
||||
|
||||
unsigned int getNumItems() const;
|
||||
|
||||
private:
|
||||
osg::ref_ptr<UnrefWorkItem> mWorkItem;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue