Skip to content

Commit

Permalink
Refactor and update sync primitives.
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrocaster committed Oct 20, 2015
1 parent f0109a3 commit a1461ce
Show file tree
Hide file tree
Showing 58 changed files with 231 additions and 218 deletions.
2 changes: 1 addition & 1 deletion src/Layers/xrRender/DetailManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class ECORE_API CDetailManager
void Render ();

/// MT stuff
xrCriticalSection MT;
Lock MT;
volatile u32 m_frame_calc;
volatile u32 m_frame_rendered;

Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRender/HOM.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CHOM
Fmatrix m_xform;
Fmatrix m_xform_01;

xrCriticalSection MT;
Lock MT;
volatile u32 MT_frame_rendered;
HOMStatistics stats;

Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRender/SkeletonCustom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "xrEngine/Render.h"
#endif
int psSkeletonUpdate = 32;
xrCriticalSection UCalc_Mutex
Lock UCalc_Mutex
#ifdef PROFILE_CRITICAL_SECTIONS
(MUTEX_PROFILE_ID(UCalc_Mutex))
#endif // PROFILE_CRITICAL_SECTIONS
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRender/SkeletonCustom.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "Include/xrRender/Kinematics.h"

// consts
extern xrCriticalSection UCalc_Mutex ;
extern Lock UCalc_Mutex ;

// refs
class CKinematics;
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRender/WallmarksEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CWallmarksEngine
CDB::Collector sml_collector;
xr_vector<u32> sml_adjacency;

xrCriticalSection lock;
Lock lock;
private:
wm_slot* FindSlot (ref_shader shader);
wm_slot* AppendSlot (ref_shader shader);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xrAI/game_spawn_constructor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CGameSpawnConstructor {
};

private:
xrCriticalSection m_critical_section;
Lock m_critical_section;
ALife::_SPAWN_ID m_spawn_id;
CThreadManager m_thread_manager;
CSpawnHeader m_spawn_header;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xrAI/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class CProfiler {
PORTIONS m_portions;
TIMERS m_timers;
bool m_actual;
xrCriticalSection m_section;
Lock m_section;
u32 m_call_count;

protected:
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xrLC/OGF_Face.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void OGF::Optimize ()


// Make Progressive
xrCriticalSection progressive_cs
Lock progressive_cs
#ifdef PROFILE_CRITICAL_SECTIONS
(MUTEX_PROFILE_ID(progressive_cs))
#endif // PROFILE_CRITICAL_SECTIONS
Expand Down
4 changes: 2 additions & 2 deletions src/utils/xrLC/xrLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include "utils/xrLC_Light/xrLC_GlobalData.h"
#include "utils/xrLC_Light/xrLightVertex.h"

#include "xrCore/Threading/xrSyncronize.h"
#include "xrCore/Threading/Lock.hpp"
#include "net.h"

#include "utils/xrLC_Light/lcnet_task_manager.h"
#include "utils/xrLC_Light/mu_model_light.h"
xrCriticalSection task_CS
Lock task_CS
#ifdef PROFILE_CRITICAL_SECTIONS
(MUTEX_PROFILE_ID(task_C_S))
#endif // PROFILE_CRITICAL_SECTIONS
Expand Down
4 changes: 2 additions & 2 deletions src/utils/xrLC/xrPhase_GI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "utils/xrLC_Light/xrLC_GlobalData.h"
#include "utils/xrLC_Light/xrface.h"

#include "xrCore/Threading/xrSyncronize.h"
#include "xrCore/Threading/Lock.hpp"
#include "xrCDB/xrCDB.h"


Expand All @@ -17,7 +17,7 @@ const float gi_clip = 0.05f;
const u32 gi_maxlevel = 4;
//////////////////////////////////////////////////////////////////////////
static xr_vector<R_Light>* task;
xrCriticalSection task_cs
Lock task_cs
#ifdef PROFILE_CRITICAL_SECTIONS
(MUTEX_PROFILE_ID(task_cs))
#endif // PROFILE_CRITICAL_SECTIONS
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xrLCUtil/LevelCompilerLoggerWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class XRLCUTIL_API LevelCompilerLoggerWindow : public ILevelCompilerLogger
HWND hwTime = 0;
HWND hwPText = 0;
HWND hwPhaseTime = 0;
xrCriticalSection csLog
Lock csLog
#ifdef PROFILE_CRITICAL_SECTIONS
(MUTEX_PROFILE_ID(csLog))
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/utils/xrLC_Light/lcnet_task_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ namespace lc_net
DWORD session_id;
u32 tasks_completed;
bool _release;
xrCriticalSection pool_lock;
xrCriticalSection log_lock;
xrCriticalSection init_lock;
Lock pool_lock;
Lock log_lock;
Lock init_lock;
private:
void send_task ( IGridUser& user, u32 id );
void receive_result ( IGenericStream* inStream );
Expand Down
4 changes: 2 additions & 2 deletions src/utils/xrLC_Light/mu_model_light_threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


#include "utils/xrLCUtil/xrThread.hpp"
#include "xrCore/Threading/xrSyncronize.h"
#include "xrCore/Threading/Lock.hpp"



Expand All @@ -23,7 +23,7 @@ CThreadManager mu_secondary(ProxyStatus, ProxyProgress);
#define MU_THREADS 4
// mu-light
bool mu_models_local_calc_lightening = false;
xrCriticalSection mu_models_local_calc_lightening_wait_lock;
Lock mu_models_local_calc_lightening_wait_lock;
void WaitMuModelsLocalCalcLightening()
{
for(;;)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/xrLC_Light/net_cl_data_prepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#include "xrlc_globaldata.h"
#include "mu_light_net.h"
#include "utils/xrLCUtil/xrThread.hpp"
#include "xrCore/Threading/xrSyncronize.h"
#include "xrCore/Threading/Lock.hpp"

bool global_compile_data_initialized = false;
bool base_global_compile_data_initialized = false;
CThreadManager cl_data_prepare(ProxyStatus, ProxyProgress);
xrCriticalSection wait_lock;
Lock wait_lock;
void SetBaseGlobalCompileDataInitialized( );
class NetCompileDetaPrepare : public CThread
{
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xrLC_Light/net_exec_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ namespace lc_net
return *this;
}
void __cdecl Finalize(IGenericStream* outStream);
xrCriticalSection run_task_lock;
Lock run_task_lock;
void exec_pool::send_task( IGridUser& user, IGenericStream* Stream, u8 pool_id, u32 id )
{

Expand Down
4 changes: 2 additions & 2 deletions src/utils/xrLC_Light/net_exec_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace lc_net
u32 _start;
u32 _end;
u32 tasks_completed;
xrCriticalSection send_receive_lock;
xrCriticalSection run_lock;
Lock send_receive_lock;
Lock run_lock;
xr_vector<net_execution*> pool;
CTimer start_time;
task_manager &_task_manager;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/xrLC_Light/net_global_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ bool global_data_file_path(LPCSTR name, IAgent* agent, DWORD sessionId, string_p
//net_global_data_impl<gl_type> impl;


xrCriticalSection create_data_lock;
xrCriticalSection ref_lock;
Lock create_data_lock;
Lock ref_lock;
u32 _id;
u32 _use_count;
bool _clear;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xrLC_Light/net_global_data_cleanup.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace lc_net

u32 id_state ;
xr_vector<u32> vec_cleanup ;
xrCriticalSection lock;
Lock lock;
friend void data_cleanup_callback( const char* dataDesc, IGenericStream** stream );
public:
global_data_cleanup ( );
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xrLC_Light/net_light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//==============================================================================


static xrCriticalSection block;
static Lock block;
LPCSTR dataDesc = "global_data";

xr_vector<u32> net_pool;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xrLC_Light/net_task_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ get_net_task_manager()->receive( r );

}

static xrCriticalSection send_receive_data_lock;
static Lock send_receive_data_lock;
class INetFileBuffWriter;
static INetFileBuffWriter *gl_data_write = 0;
static CVirtualFileRW *g_net_data = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/xrLC_Light/xrLightVertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
typedef xr_multimap<float,vecVertex> mapVert;
typedef mapVert::iterator mapVertIt;
mapVert* g_trans;
xrCriticalSection g_trans_CS
Lock g_trans_CS
#ifdef PROFILE_CRITICAL_SECTIONS
(MUTEX_PROFILE_ID(g_trans_CS))
#endif // PROFILE_CRITICAL_SECTIONS
Expand Down Expand Up @@ -63,7 +63,7 @@ void g_trans_register (Vertex* V)
const u32 VLT_END = u32(-1);
class CVertexLightTasker
{
xrCriticalSection cs;
Lock cs;
volatile u32 index;
public:
CVertexLightTasker () : index(0)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xrLC_Light/xrLight_Implicit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void ImplicitLighting(BOOL b_net)
thread_spawn (ImplicitLightingTreadNetExec,"worker-thread",1024*1024,0);

}
xrCriticalSection implicit_net_lock;
Lock implicit_net_lock;
void XRLC_LIGHT_API ImplicitNetWait()
{
implicit_net_lock.Enter();
Expand Down
2 changes: 1 addition & 1 deletion src/xrCDB/ISpatial.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class XRCDB_API ISpatial_DB
}
};
private:
xrCriticalSection cs;
Lock cs;

poolSS< ISpatial_NODE, 128 > allocator;

Expand Down
4 changes: 2 additions & 2 deletions src/xrCDB/xrCDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace CDB
S_forcedword = u32(-1)
};
private:
xrCriticalSection cs;
Lock cs;
Opcode::OPCODE_Model* tree;
u32 status; // 0=ready, 1=init, 2=building

Expand All @@ -86,7 +86,7 @@ namespace CDB
if (S_READY!=status)
{
Log ("! WARNING: syncronized CDB::query");
xrCriticalSection* C = (xrCriticalSection*) &cs;
Lock* C = (Lock*) &cs;
C->Enter ();
C->Leave ();
}
Expand Down
2 changes: 1 addition & 1 deletion src/xrCDB/xr_area.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class XRCDB_API CObjectSpace
{
private:
// Debug
xrCriticalSection Lock;
Lock Lock;
CDB::MODEL Static;
Fbox m_BoundingVolume;
xrXRC xrc; // MT: dangerous
Expand Down
4 changes: 2 additions & 2 deletions src/xrCore/LocatorAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void setup_reader(IReader* _r, _open_file& _of)
template <typename T>
void _register_open_file(T* _r, LPCSTR _fname)
{
xrCriticalSection _lock;
Lock _lock;
_lock.Enter();

shared_str f = _fname;
Expand All @@ -138,7 +138,7 @@ void _register_open_file(T* _r, LPCSTR _fname)
template <typename T>
void _unregister_open_file(T* _r)
{
xrCriticalSection _lock;
Lock _lock;
_lock.Enter();

xr_vector<_open_file>::iterator it = std::find_if(g_open_files.begin(), g_open_files.end(), eq_pointer<T>(_r));
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/LocatorAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class XRCORE_API CLocatorAPI
files_set m_files;
BOOL bNoRecurse;

xrCriticalSection m_auth_lock;
Lock m_auth_lock;
u64 m_auth_code;

const file* RegisterExternal(const char* name);
Expand Down
16 changes: 16 additions & 0 deletions src/xrCore/Threading/Event.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "stdafx.h"
#include "Event.hpp"
#include <windows.h>

Event::Event() { handle = (void*)CreateEvent(NULL, FALSE, FALSE, NULL); }

Event::~Event() { CloseHandle(handle); }

void Event::Reset() { ResetEvent(handle); }

void Event::Set() { SetEvent(handle); }

void Event::Wait() const { WaitForSingleObject(handle, INFINITE); }

bool Event::Wait(u32 millisecondsTimeout) const
{ return WaitForSingleObject(handle, millisecondsTimeout)!=WAIT_TIMEOUT; }
23 changes: 23 additions & 0 deletions src/xrCore/Threading/Event.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include "xrCore/xrCore.h"

class XRCORE_API Event
{
private:
void *handle;

public:
Event();
~Event();

// Reset the event to the unsignalled state.
void Reset();
// Set the event to the signalled state.
void Set();
// Wait indefinitely for the object to become signalled.
void Wait() const;
// Wait, with a time limit, for the object to become signalled.
bool Wait(u32 millisecondsTimeout) const;

void *GetHandle() const { return handle; }
};
Loading

0 comments on commit a1461ce

Please sign in to comment.