improved spinlock
This commit is contained in:
parent
9143756339
commit
405c946618
14 changed files with 27 additions and 77 deletions
|
@ -2,7 +2,6 @@
|
|||
Pos=347,43
|
||||
Size=1149,500
|
||||
Collapsed=0
|
||||
DockId=0x00000008,3
|
||||
|
||||
[Window][Debug##Default]
|
||||
Pos=887,889
|
||||
|
@ -13,82 +12,67 @@ Collapsed=0
|
|||
Pos=347,547
|
||||
Size=1503,503
|
||||
Collapsed=0
|
||||
DockId=0x00000003,0
|
||||
|
||||
[Window][Asset properties]
|
||||
Pos=1500,43
|
||||
Size=350,500
|
||||
Collapsed=0
|
||||
DockId=0x00000009,0
|
||||
|
||||
[Window][Log]
|
||||
Pos=1,547
|
||||
Size=342,503
|
||||
Collapsed=0
|
||||
DockId=0x00000005,0
|
||||
|
||||
[Window][Properties]
|
||||
Pos=1,43
|
||||
Size=342,500
|
||||
Collapsed=0
|
||||
DockId=0x00000004,0
|
||||
|
||||
[Window][Entity List]
|
||||
Pos=1,547
|
||||
Size=342,503
|
||||
Collapsed=0
|
||||
DockId=0x00000005,1
|
||||
|
||||
[Window][###Scene View]
|
||||
Pos=347,43
|
||||
Size=1149,500
|
||||
Collapsed=0
|
||||
DockId=0x00000008,1
|
||||
|
||||
[Window][###game_view]
|
||||
Pos=347,43
|
||||
Size=1149,500
|
||||
Collapsed=0
|
||||
DockId=0x00000008,2
|
||||
|
||||
[Window][Maps]
|
||||
Pos=347,43
|
||||
Size=1149,739
|
||||
Collapsed=0
|
||||
DockId=0x00000008,2
|
||||
DockId=0x00000001,2
|
||||
|
||||
[Window][Profiler]
|
||||
Pos=347,875
|
||||
Size=1503,175
|
||||
Collapsed=0
|
||||
DockId=0x00000003,2
|
||||
DockId=0x00000001,2
|
||||
|
||||
[Window][Clip Manager]
|
||||
Pos=347,547
|
||||
Size=1503,503
|
||||
Collapsed=0
|
||||
DockId=0x00000003,1
|
||||
|
||||
[Window][GUIEditor]
|
||||
Pos=347,43
|
||||
Size=1149,500
|
||||
Collapsed=0
|
||||
DockId=0x00000008,0
|
||||
|
||||
[Window][Renderer Stats]
|
||||
Pos=347,919
|
||||
Size=1503,131
|
||||
Collapsed=0
|
||||
DockId=0x00000003,3
|
||||
DockId=0x00000001,3
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0x00000001 Pos=1,43 Size=1849,1007 Split=X SelectedTab=0x1C33C293
|
||||
DockNode ID=0x00000006 Parent=0x00000001 SizeRef=342,1007 Split=Y SelectedTab=0xB7722E25
|
||||
DockNode ID=0x00000004 Parent=0x00000006 SizeRef=342,500 SelectedTab=0xC89E3217
|
||||
DockNode ID=0x00000005 Parent=0x00000006 SizeRef=342,503 SelectedTab=0xB7722E25
|
||||
DockNode ID=0x00000007 Parent=0x00000001 SizeRef=1503,1007 Split=Y
|
||||
DockNode ID=0x00000002 Parent=0x00000007 SizeRef=1849,500 Split=X SelectedTab=0xE32DF26B
|
||||
DockNode ID=0x00000008 Parent=0x00000002 SizeRef=1149,739 DocRoot=1 SelectedTab=0xE32DF26B
|
||||
DockNode ID=0x00000009 Parent=0x00000002 SizeRef=350,739 SelectedTab=0x3BC70FD5
|
||||
DockNode ID=0x00000003 Parent=0x00000007 SizeRef=1849,503 SelectedTab=0x7E7D78B8
|
||||
DockSpace ID=0x00000001 Pos=1,43 Size=1849,1007 CentralNode=1 SelectedTab=0x1C33C293
|
||||
DockSpace ID=0x39930E19 Pos=0,0 Size=0,0 CentralNode=1
|
||||
DockSpace ID=0xAFF71519 Pos=1,43 Size=1599,976 CentralNode=1
|
||||
|
||||
|
|
|
@ -48,7 +48,6 @@ AssetBrowser::AssetBrowser(StudioApp& app)
|
|||
, m_autoreload_changed_resource(true)
|
||||
, m_changed_files(app.getWorldEditor().getAllocator())
|
||||
, m_is_focus_requested(false)
|
||||
, m_changed_files_mutex(false)
|
||||
, m_history(app.getWorldEditor().getAllocator())
|
||||
, m_plugins(app.getWorldEditor().getAllocator())
|
||||
, m_app(app)
|
||||
|
|
|
@ -68,9 +68,6 @@ struct AssetCompilerImpl : AssetCompiler
|
|||
, m_to_compile(app.getWorldEditor().getAllocator())
|
||||
, m_compiled(app.getWorldEditor().getAllocator())
|
||||
, m_on_resource_changed(app.getWorldEditor().getAllocator())
|
||||
, m_to_compile_mutex(false)
|
||||
, m_compiled_mutex(false)
|
||||
, m_plugin_mutex(false)
|
||||
, m_semaphore(0, 0x7fFFffFF)
|
||||
{
|
||||
m_watcher = FileSystemWatcher::create(".", app.getWorldEditor().getAllocator());
|
||||
|
|
|
@ -14,7 +14,6 @@ LogUI::LogUI(IAllocator& allocator)
|
|||
, m_level_filter(2 | 4)
|
||||
, m_notifications(allocator)
|
||||
, m_last_uid(1)
|
||||
, m_guard(false)
|
||||
, m_is_open(false)
|
||||
, m_are_notifications_hovered(false)
|
||||
, m_move_notifications_to_front(false)
|
||||
|
|
|
@ -251,7 +251,6 @@ static const u32 ALLOCATION_GUARD = 0xFDFDFDFD;
|
|||
Allocator::Allocator(IAllocator& source)
|
||||
: m_source(source)
|
||||
, m_root(nullptr)
|
||||
, m_mutex(false)
|
||||
, m_total_size(0)
|
||||
, m_is_fill_enabled(true)
|
||||
, m_are_guards_enabled(true)
|
||||
|
|
|
@ -58,7 +58,6 @@ struct System
|
|||
, m_job_queue(allocator)
|
||||
, m_ready_fibers(allocator)
|
||||
, m_counter_pool(allocator)
|
||||
, m_sync(false)
|
||||
, m_work_signal(true)
|
||||
, m_event_outside_job(true)
|
||||
, m_free_queue(allocator)
|
||||
|
@ -228,6 +227,7 @@ CounterHandle allocateCounter()
|
|||
|
||||
void decCounter(CounterHandle handle)
|
||||
{
|
||||
ASSERT((handle & HANDLE_ID_MASK) < 4096);
|
||||
Job next_job = {nullptr, nullptr};
|
||||
|
||||
MT::SpinLock lock(g_system->m_sync);
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace MT
|
|||
typedef void* SemaphoreHandle;
|
||||
typedef void* MutexHandle;
|
||||
typedef void* EventHandle;
|
||||
typedef volatile i32 SpinMutexHandle;
|
||||
typedef volatile long SpinMutexHandle;
|
||||
#elif defined __linux__
|
||||
struct SemaphoreHandle
|
||||
{
|
||||
|
@ -72,7 +72,7 @@ private:
|
|||
class LUMIX_ENGINE_API SpinMutex
|
||||
{
|
||||
public:
|
||||
explicit SpinMutex(bool locked);
|
||||
explicit SpinMutex();
|
||||
~SpinMutex();
|
||||
|
||||
void lock();
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
#include "engine/mt/atomic.h"
|
||||
#include "engine/mt/thread.h"
|
||||
#include "engine/win/simple_win.h"
|
||||
|
||||
|
||||
#include <intrin.h>
|
||||
|
||||
namespace Lumix
|
||||
{
|
||||
|
@ -73,49 +72,26 @@ bool Event::poll()
|
|||
}
|
||||
|
||||
|
||||
SpinMutex::SpinMutex(bool locked)
|
||||
: m_id(0)
|
||||
{
|
||||
if (locked)
|
||||
{
|
||||
lock();
|
||||
}
|
||||
}
|
||||
SpinMutex::SpinMutex() : m_id(0) {}
|
||||
|
||||
SpinMutex::~SpinMutex() = default;
|
||||
|
||||
|
||||
void SpinMutex::lock()
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
if (compareAndExchange(&m_id, 1, 0))
|
||||
{
|
||||
memoryBarrier();
|
||||
return;
|
||||
}
|
||||
|
||||
while (m_id)
|
||||
{
|
||||
yield();
|
||||
}
|
||||
for (;;) {
|
||||
if(m_id == 0 && _interlockedbittestandset(&m_id, 0) == 0) break;
|
||||
_mm_pause();
|
||||
}
|
||||
}
|
||||
|
||||
bool SpinMutex::poll()
|
||||
{
|
||||
if (compareAndExchange(&m_id, 1, 0))
|
||||
{
|
||||
memoryBarrier();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return m_id == 0 && _interlockedbittestandset(&m_id, 0) == 0;
|
||||
}
|
||||
|
||||
void SpinMutex::unlock()
|
||||
{
|
||||
memoryBarrier();
|
||||
m_id = 0;
|
||||
_interlockedbittestandreset(&m_id, 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ namespace Lumix
|
|||
|
||||
PathManager::PathManager(IAllocator& allocator)
|
||||
: m_paths(allocator)
|
||||
, m_mutex(false)
|
||||
, m_allocator(allocator)
|
||||
{
|
||||
g_path_manager = this;
|
||||
|
|
|
@ -19,7 +19,6 @@ static struct Instance
|
|||
{
|
||||
Instance()
|
||||
: contexts(allocator)
|
||||
, mutex(false)
|
||||
, timer(Timer::create(allocator))
|
||||
{}
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ struct ThreadContext
|
|||
{
|
||||
ThreadContext(IAllocator& allocator)
|
||||
: buffer(allocator)
|
||||
, mutex(false)
|
||||
{
|
||||
buffer.resize(1024 * 512);
|
||||
}
|
||||
|
|
|
@ -550,9 +550,7 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
|
|||
|
||||
void showPreview(Model& model)
|
||||
{
|
||||
// TODO
|
||||
ASSERT(false);
|
||||
/*auto* render_scene = static_cast<RenderScene*>(m_universe->getScene(MODEL_INSTANCE_TYPE));
|
||||
auto* render_scene = static_cast<RenderScene*>(m_universe->getScene(MODEL_INSTANCE_TYPE));
|
||||
if (!render_scene) return;
|
||||
if (!model.isReady()) return;
|
||||
if (!m_mesh.isValid()) return;
|
||||
|
@ -563,7 +561,7 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
|
|||
AABB aabb = model.getAABB();
|
||||
|
||||
const Vec3 center = (aabb.max + aabb.min) * 0.5f;
|
||||
m_viewport.pos = center + Vec3(1, 1, 1) * (aabb.max - aabb.min).length();
|
||||
m_viewport.pos = DVec3(0) + center + Vec3(1, 1, 1) * (aabb.max - aabb.min).length();
|
||||
m_viewport.rot = Quat::vec3ToVec3({0, 0, 1}, {1, 1, 1});
|
||||
}
|
||||
ImVec2 image_size(ImGui::GetContentRegionAvailWidth(), ImGui::GetContentRegionAvailWidth());
|
||||
|
@ -589,9 +587,11 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
|
|||
{
|
||||
if (ImGui::Selectable("Save preview"))
|
||||
{
|
||||
const Matrix mtx(m_viewport.pos, m_viewport.rot);
|
||||
// TODO
|
||||
ASSERT(false);
|
||||
/*const Matrix mtx(m_viewport.pos, m_viewport.rot);
|
||||
model.getResourceManager().load(model);
|
||||
renderTile(&model, &mtx);
|
||||
renderTile(&model, &mtx);*/
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
@ -611,7 +611,7 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
|
|||
if (delta.x != 0 || delta.y != 0)
|
||||
{
|
||||
const Vec2 MOUSE_SENSITIVITY(50, 50);
|
||||
Vec3 pos = m_viewport.pos;
|
||||
DVec3 pos = m_viewport.pos;
|
||||
Quat rot = m_viewport.rot;
|
||||
|
||||
float yaw = -Math::signum(delta.x) * (Math::pow(Math::abs((float)delta.x / MOUSE_SENSITIVITY.x), 1.2f));
|
||||
|
@ -629,13 +629,13 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
|
|||
Vec3 dir = rot.rotate(Vec3(0, 0, 1));
|
||||
Vec3 origin = (model.getAABB().max + model.getAABB().min) * 0.5f;
|
||||
|
||||
float dist = (origin - pos).length();
|
||||
pos = origin + dir * dist;
|
||||
float dist = (origin - pos.toFloat()).length();
|
||||
pos = DVec3(0) + origin + dir * dist;
|
||||
|
||||
m_viewport.rot = rot;
|
||||
m_viewport.pos = pos;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -117,7 +117,7 @@ static struct {
|
|||
Pool<Uniform, Uniform::MAX_COUNT> uniforms;
|
||||
Pool<Program, Program::MAX_COUNT> programs;
|
||||
HashMap<u32, uint>* uniforms_hash_map;
|
||||
MT::SpinMutex handle_mutex {false};
|
||||
MT::SpinMutex handle_mutex;
|
||||
DWORD thread;
|
||||
int vertex_attributes = 0;
|
||||
int instance_attributes = 0;
|
||||
|
|
|
@ -68,7 +68,6 @@ struct MTBucketArray
|
|||
|
||||
MTBucketArray(IAllocator& allocator)
|
||||
: m_counts(allocator)
|
||||
, m_mutex(false)
|
||||
{
|
||||
m_mem = (u8*)VirtualAlloc(nullptr, 1024 * 1024 * 8, MEM_RESERVE, PAGE_READWRITE);
|
||||
m_end = m_mem;
|
||||
|
|
Loading…
Reference in a new issue