16 Commits
Author SHA1 Message Date
Bret Curtis 2c66d3dd9a Let UnrefQueue defer destruction of any shared object
The queue only needs to hand the last reference to a worker thread, so
it holds std::shared_ptr<void> instead of osg::ref_ptr<osg::Referenced>.
That keeps the right deleter for whatever type is pushed.
2026-10-10 11:54:25 +02:00
Bret Curtis 28b8274aee Own work queue items with std::shared_ptr instead of osg::Referenced
SceneUtil::WorkQueue is a thread pool with no scene graph in it, so neither it
nor WorkItem needs an OSG base class to be reference counted; both now use
std::shared_ptr and workqueue.hpp, workqueue.cpp and generatenavmeshtile.hpp
end up with no reference to osg at all. Because osg::ref_ptr can re-adopt a raw
pointer and std::shared_ptr cannot without minting a second control block, the
places that passed the queue around as WorkQueue* now pass const
std::shared_ptr<WorkQueue>& instead, which is RenderingManager::getWorkQueue
and the World, WindowManager, MapWindow and GlobalMap constructors. The
non-owning WorkQueue& parameters in UnrefQueue, WorkThread and navmeshtool are
unchanged, and WorkItem gains the virtual destructor it used to inherit.
2026-09-20 12:33:25 +02:00
jvoisinandelsid 3cbf1dc042 First pass with include-what-you-use 2022-10-09 10:39:43 +00:00
clang-format-botandζeh Matt ddb0522bbf Apply clang-format to code base 2022-09-22 21:35:26 +03:00
elsid 0614b82452 Restore UnrefQueue to destruct animation asynchronously 2022-07-24 21:08:43 +02:00
Bo SvenssonandGitHub a854a6e04a 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`.
2021-10-20 23:02:15 +02:00
Andrei Kortunov 065ed5138e Use emplace_back instead of push_back 2020-10-18 10:27:35 +04:00
Sophie Kirschner c412f99963 Remove commented lines in UnrefWorkItem::doWork 2018-08-26 11:08:06 +03:00
Sophie Kirschner 4dd9386c4f Fix error: member access into incomplete type 'SceneUtil::UnrefWorkItem'
Fixes compile error encountered on OSX 10.9 with g++

sophie:build pineapple$ g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

The compilation error:

[ 24%] Building CXX object apps/openmw/CMakeFiles/openmw.dir/mwrender/renderingmanager.cpp.o
In file included from /Users/pineapple/git/openmw/apps/openmw/mwrender/renderingmanager.cpp:1:
In file included from /Users/pineapple/git/openmw/apps/openmw/mwrender/renderingmanager.hpp:4:
/Users/pineapple/git/openmw/openmw-deps/include/osg/ref_ptr:35:36: error: member access into incomplete type 'SceneUtil::UnrefWorkItem'
        ~ref_ptr() { if (_ptr) _ptr->unref();  _ptr = 0; }
                                   ^
/Users/pineapple/git/openmw/./components/sceneutil/unrefqueue.hpp:14:11: note: in instantiation of member function
      'osg::ref_ptr<SceneUtil::UnrefWorkItem>::~ref_ptr' requested here
    class UnrefQueue : public osg::Referenced
          ^
/Users/pineapple/git/openmw/./components/sceneutil/unrefqueue.hpp:10:11: note: forward declaration of 'SceneUtil::UnrefWorkItem'
    class UnrefWorkItem;
2018-08-24 16:41:52 +03:00
Andrei Kortunov 1452684d9e Use new logging system for components 2018-08-14 19:42:41 +04:00
scrawl 8f79fa3d72 Add resource statistics panel opened with F4 2017-02-22 14:28:45 +01:00
scrawl a1069dce3c Change UnrefQueue to accept osg::Referenced instead of osg::Object 2017-02-04 02:24:42 +01:00
scrawl 2f8be401cc Add the unref work items to the front of the workqueue (Bug #3273)
Ensures that memory still gets freed even if the workqueue is overloaded.
2016-03-29 00:27:56 +02:00
scrawl afe533e670 Accept a const Object in UnrefQueue 2016-02-09 19:00:30 +01:00
scrawl 40a6e05e17 Use a deque instead of vector in UnrefQueue 2016-02-09 16:09:55 +01:00
scrawl d11c2864df Introduce UnrefQueue to handle the deleting of no longer needed objects in the background thread 2016-02-09 15:45:35 +01:00