| 823 | } |
| 824 | |
| 825 | void Assets::workerMain() { |
| 826 | while (true) { |
| 827 | if (m_stopThreads) |
| 828 | break; |
| 829 | |
| 830 | { |
| 831 | RecursiveMutexLocker luaLocker(m_luaMutex); |
| 832 | as<LuaEngine>(m_luaEngine.get())->collectGarbage(); |
| 833 | } |
| 834 | |
| 835 | MutexLocker assetsLocker(m_assetsMutex); |
| 836 | |
| 837 | AssetId assetId; |
| 838 | QueuePriority queuePriority = QueuePriority::None; |
| 839 | |
| 840 | // Find the highest priority queue entry |
| 841 | for (auto const& pair : m_queue) { |
| 842 | if (pair.second == QueuePriority::Load || pair.second == QueuePriority::PostProcess) { |
| 843 | assetId = pair.first; |
| 844 | queuePriority = pair.second; |
| 845 | if (pair.second == QueuePriority::Load) |
| 846 | break; |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | if (queuePriority != QueuePriority::Load && queuePriority != QueuePriority::PostProcess) { |
| 851 | // Nothing in the queue that needs work |
| 852 | m_assetsQueued.wait(m_assetsMutex); |
| 853 | continue; |
| 854 | } |
| 855 | |
| 856 | bool workIsBlocking; |
| 857 | if (queuePriority == QueuePriority::PostProcess) |
| 858 | workIsBlocking = !doPost(assetId); |
| 859 | else |
| 860 | workIsBlocking = !doLoad(assetId); |
| 861 | |
| 862 | if (workIsBlocking) { |
| 863 | // We are blocking on some sort of busy asset, so need to wait on |
| 864 | // something to complete here, rather than spinning and burning cpu. |
| 865 | m_assetsDone.wait(m_assetsMutex); |
| 866 | continue; |
| 867 | } |
| 868 | |
| 869 | // After processing an asset, unlock the main asset mutex and yield so we |
| 870 | // don't starve other threads. |
| 871 | assetsLocker.unlock(); |
| 872 | Thread::yield(); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | template <typename Function> |
| 877 | decltype(auto) Assets::unlockDuring(Function f) const { |
nothing calls this directly
no test coverage detected