Skip to content

Commit

Permalink
Merge pull request #93 from pr0g/whitespace
Browse files Browse the repository at this point in the history
Whitespace updates
  • Loading branch information
dougbinks committed Jun 11, 2023
2 parents d7d4e5b + 722beb6 commit 4001680
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 73 deletions.
26 changes: 13 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ option( ENKITS_BUILD_EXAMPLES "Build example applications" ON )
option( ENKITS_BUILD_SHARED "Build shared library" OFF )
option( ENKITS_INSTALL "Generate installation target" OFF )

set( ENKITS_TASK_PRIORITIES_NUM "3" CACHE STRING "Number of task priorities, 1-5, 0 for defined by defaults in source" )
set( ENKITS_TASK_PRIORITIES_NUM "3" CACHE STRING "Number of task priorities, 1-5, 0 for defined by defaults in source" )

set( ENKITS_HEADERS
src/LockLessMultiReadPipe.h
Expand All @@ -22,7 +22,7 @@ if( ENKITS_BUILD_C_INTERFACE )
list( APPEND ENKITS_HEADERS
src/TaskScheduler_c.h
)

list( APPEND ENKITS_SRC
src/TaskScheduler_c.cpp
)
Expand All @@ -35,18 +35,18 @@ if( ENKITS_BUILD_SHARED )
target_compile_definitions( enkiTS PRIVATE ENKITS_BUILD_DLL=1 )
target_compile_definitions( enkiTS INTERFACE ENKITS_DLL=1 )
if( UNIX )
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
endif()
endif ()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
endif()
endif ()
else()
add_library( enkiTS STATIC ${ENKITS_SRC} )
endif()

target_include_directories( enkiTS PUBLIC "${PROJECT_SOURCE_DIR}/src")

if( ENKITS_TASK_PRIORITIES_NUM GREATER "0" )
target_compile_definitions( enkiTS PUBLIC "ENKITS_TASK_PRIORITIES_NUM=${ENKITS_TASK_PRIORITIES_NUM}" )
target_compile_definitions( enkiTS PUBLIC "ENKITS_TASK_PRIORITIES_NUM=${ENKITS_TASK_PRIORITIES_NUM}" )
endif()

if( UNIX )
Expand Down Expand Up @@ -84,7 +84,7 @@ if( ENKITS_BUILD_EXAMPLES )
add_executable( Priorities example/Priorities.cpp )
target_link_libraries(Priorities enkiTS )
endif()

add_executable( TaskThroughput example/TaskThroughput.cpp example/Timer.h )
target_link_libraries(TaskThroughput enkiTS )

Expand All @@ -111,11 +111,11 @@ if( ENKITS_BUILD_EXAMPLES )

add_executable( WaitForNewPinnedTasks example/WaitForNewPinnedTasks.cpp )
target_link_libraries(WaitForNewPinnedTasks enkiTS )

if( ENKITS_BUILD_C_INTERFACE )
add_executable( ParallelSum_c example/ParallelSum_c.c )
target_link_libraries(ParallelSum_c enkiTS )

add_executable( PinnedTask_c example/PinnedTask_c.c )
target_link_libraries(PinnedTask_c enkiTS )

Expand All @@ -135,10 +135,10 @@ if( ENKITS_BUILD_C_INTERFACE )

add_executable( CompletionAction_c example/CompletionAction_c.c )
target_link_libraries(CompletionAction_c enkiTS )
add_executable( WaitForNewPinnedTasks_c example/WaitForNewPinnedTasks_c.c )

add_executable( WaitForNewPinnedTasks_c example/WaitForNewPinnedTasks_c.c )
target_link_libraries(WaitForNewPinnedTasks_c enkiTS )

endif()
endif()

endif()
70 changes: 35 additions & 35 deletions src/TaskScheduler.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) 2013 Doug Binks
//
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgement in the product documentation would be
Expand Down Expand Up @@ -89,7 +89,7 @@ namespace enki
// each software thread gets its own copy of gtl_threadNum, so this is safe to use as a static variable
static thread_local uint32_t gtl_threadNum = enki::NO_THREAD_NUM;

namespace enki
namespace enki
{
struct SubTaskSet
{
Expand All @@ -98,7 +98,7 @@ namespace enki
};

// we derive class TaskPipe rather than typedef to get forward declaration working easily
class TaskPipe : public LockLessMultiReadPipe<gc_PipeSizeLog2,enki::SubTaskSet> {};
class TaskPipe : public LockLessMultiReadPipe<gc_PipeSizeLog2, enki::SubTaskSet> {};

enum ThreadState : int32_t
{
Expand All @@ -120,7 +120,7 @@ namespace enki
TaskScheduler* pTaskScheduler;
};

struct alignas(enki::gc_CacheLineSize) ThreadDataStore
struct alignas(enki::gc_CacheLineSize) ThreadDataStore
{
semaphoreid_t* pWaitNewPinnedTaskSemaphore = nullptr;
std::atomic<ThreadState> threadState = { ENKI_THREAD_STATE_NONE };
Expand Down Expand Up @@ -158,7 +158,7 @@ namespace
while( __rdtsc() < end )
{
_mm_pause();
}
}
}
#else
static void SpinWait( uint32_t spinCount_ )
Expand All @@ -167,7 +167,7 @@ namespace
{
// TODO: may have NOP or yield equiv
--spinCount_;
}
}
}
#endif
}
Expand All @@ -180,9 +180,9 @@ static void SafeCallback( ProfilerCallbackFunc func_, uint32_t threadnum_ )
}
}


ENKITS_API void* enki::DefaultAllocFunc( size_t align_, size_t size_, void* userData_, const char* file_, int line_ )
{
{
(void)userData_; (void)file_; (void)line_;
void* pRet;
#ifdef _WIN32
Expand All @@ -197,7 +197,7 @@ ENKITS_API void* enki::DefaultAllocFunc( size_t align_, size_t size_, void* user
else
{
int retval = posix_memalign( &pRet, align_, size_ );
(void)retval; //unused
(void)retval; // unused
}
#endif
return pRet;
Expand Down Expand Up @@ -279,7 +279,7 @@ void TaskScheduler::TaskingThreadFunction( const ThreadArgs& args_ )
SafeCallback( pTS->m_Config.profilerCallbacks.threadStart, threadNum );

uint32_t spinCount = 0;
uint32_t hintPipeToCheck_io = threadNum + 1; // does not need to be clamped.
uint32_t hintPipeToCheck_io = threadNum + 1; // does not need to be clamped.
while( pTS->GetIsRunning() )
{
if( !pTS->TryRunTask( threadNum, hintPipeToCheck_io ) )
Expand Down Expand Up @@ -416,7 +416,7 @@ void TaskScheduler::StartThreads()

// From https://learn.microsoft.com/en-us/windows/win32/procthread/processor-groups
// If a thread is assigned to a different group than the process, the process's affinity is updated to include the thread's affinity
// and the process becomes a multi-group process.
// and the process becomes a multi-group process.
GROUP_AFFINITY threadAffinity;
success = GetThreadGroupAffinity( thread_handle, &threadAffinity );
assert(success); (void)success;
Expand All @@ -442,7 +442,7 @@ void TaskScheduler::StopThreads( bool bWait_ )
// we set m_bWaitforAllCalled to true to ensure any task which loop using this status exit
m_bWaitforAllCalled.store( true, std::memory_order_release );

// set status
// set status
m_bShutdownRequested.store( true, std::memory_order_release );
m_bRunning.store( false, std::memory_order_release );

Expand Down Expand Up @@ -514,9 +514,9 @@ bool TaskScheduler::TryRunTask( uint32_t threadNum_, uint32_t& hintPipeToCheck_i
return false;
}

static inline uint32_t RotateLeft( uint32_t value, int32_t count )
static inline uint32_t RotateLeft( uint32_t value, int32_t count )
{
return ( value << count ) | ( value >> ( 32 - count ));
return ( value << count ) | ( value >> ( 32 - count ));
}
/* xxHash variant based on documentation on
https://github.com/Cyan4973/xxHash/blob/eec5700f4d62113b47ee548edbc4746f61ffb098/doc/xxhash_spec.md
Expand Down Expand Up @@ -568,7 +568,7 @@ bool TaskScheduler::TryRunTask( uint32_t threadNum_, uint32_t priority_, uint32_
// the starting thread which we start checking for tasks to run
uint32_t& rndSeed = m_pThreadDataStore[threadNum_].rndSeed;
++rndSeed;
uint32_t threadToCheckOffset = Hash32( rndSeed * threadNum_ );
uint32_t threadToCheckOffset = Hash32( rndSeed * threadNum_ );
while( !bHaveTask && checkCount < m_NumThreads )
{
threadToCheck = ( threadToCheckOffset + checkCount ) % m_NumThreads;
Expand All @@ -580,7 +580,7 @@ bool TaskScheduler::TryRunTask( uint32_t threadNum_, uint32_t priority_, uint32_
}
}
}

if( bHaveTask )
{
// update hint, will preserve value unless actually got task from another thread.
Expand Down Expand Up @@ -788,7 +788,7 @@ bool TaskScheduler::WakeSuspendedThreadsWithPinnedTasks( uint32_t threadNum_ )
uint32_t thread = ( threadNum_ + t ) % m_NumThreads;

ThreadState state = m_pThreadDataStore[ thread ].threadState.load( std::memory_order_acquire );

ENKI_ASSERT( state != ENKI_THREAD_STATE_NONE );

if( state == ENKI_THREAD_STATE_WAIT_NEW_TASKS || state == ENKI_THREAD_STATE_WAIT_TASK_COMPLETION )
Expand Down Expand Up @@ -1206,12 +1206,12 @@ T* TaskScheduler::NewArray( size_t num_, const char* file_, int line_ )
T* pRet = (T*)m_Config.customAllocator.alloc( alignof(T), num_*sizeof(T), m_Config.customAllocator.userData, file_, line_ );
if( !std::is_trivial<T>::value )
{
T* pCurr = pRet;
T* pCurr = pRet;
for( size_t i = 0; i < num_; ++i )
{
void* pBuffer = pCurr;
void* pBuffer = pCurr;
pCurr = new(pBuffer) T;
++pCurr;
++pCurr;
}
}
return pRet;
Expand Down Expand Up @@ -1241,7 +1241,7 @@ T* TaskScheduler::New( const char* file_, int line_, Args&&... args_ )
template< typename T >
void TaskScheduler::Delete( T* p_, const char* file_, int line_ )
{
p_->~T();
p_->~T();
this->Free(p_, file_, line_ );
}

Expand Down Expand Up @@ -1319,7 +1319,7 @@ namespace enki
{
HANDLE sem;
};

inline void SemaphoreCreate( semaphoreid_t& semaphoreid )
{
#ifdef _XBOX_ONE
Expand Down Expand Up @@ -1364,27 +1364,27 @@ namespace enki

namespace enki
{

struct semaphoreid_t
{
dispatch_semaphore_t sem;
};

inline void SemaphoreCreate( semaphoreid_t& semaphoreid )
{
semaphoreid.sem = dispatch_semaphore_create(0);
}

inline void SemaphoreClose( semaphoreid_t& semaphoreid )
{
dispatch_release( semaphoreid.sem );
}

inline void SemaphoreWait( semaphoreid_t& semaphoreid )
{
dispatch_semaphore_wait( semaphoreid.sem, DISPATCH_TIME_FOREVER );
}

inline void SemaphoreSignal( semaphoreid_t& semaphoreid, int32_t countWaiting )
{
while( countWaiting-- > 0 )
Expand All @@ -1401,29 +1401,29 @@ namespace enki

namespace enki
{

struct semaphoreid_t
{
sem_t sem;
};

inline void SemaphoreCreate( semaphoreid_t& semaphoreid )
{
int err = sem_init( &semaphoreid.sem, 0, 0 );
ENKI_ASSERT( err == 0 );
(void)err;
}

inline void SemaphoreClose( semaphoreid_t& semaphoreid )
{
sem_destroy( &semaphoreid.sem );
}

inline void SemaphoreWait( semaphoreid_t& semaphoreid )
{
while( sem_wait( &semaphoreid.sem ) == -1 && errno == EINTR ) {}
}

inline void SemaphoreSignal( semaphoreid_t& semaphoreid, int32_t countWaiting )
{
while( countWaiting-- > 0 )
Expand Down Expand Up @@ -1452,7 +1452,7 @@ void TaskScheduler::SetCustomAllocator( CustomAllocator customAllocator_ )
m_Config.customAllocator = customAllocator_;
}

Dependency::Dependency( const ICompletable* pDependencyTask_, ICompletable* pTaskToRunOnCompletion_ )
Dependency::Dependency( const ICompletable* pDependencyTask_, ICompletable* pTaskToRunOnCompletion_ )
: pTaskToRunOnCompletion( pTaskToRunOnCompletion_ )
, pDependencyTask( pDependencyTask_ )
, pNext( pDependencyTask->m_pDependents )
Expand Down
5 changes: 2 additions & 3 deletions src/TaskScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define ENKITS_TASK_PRIORITIES_NUM 3
#endif

#ifndef ENKITS_API
#ifndef ENKITS_API
#if defined(_WIN32) && defined(ENKITS_BUILD_DLL)
// Building enkiTS as a DLL
#define ENKITS_API __declspec(dllexport)
Expand Down Expand Up @@ -60,7 +60,6 @@

namespace enki
{

struct TaskSetPartition
{
uint32_t start;
Expand Down Expand Up @@ -387,7 +386,7 @@ namespace enki
// It is guaranteed that GetThreadNum() < GetNumTaskThreads() unless it is NO_THREAD_NUM
ENKITS_API uint32_t GetThreadNum() const;

// Call on a thread to register the thread to use the TaskScheduling API.
// Call on a thread to register the thread to use the TaskScheduling API.
// This is implicitly done for the thread which initializes the TaskScheduler
// Intended for developers who have threads who need to call the TaskScheduler API
// Returns true if successful, false if not.
Expand Down
Loading

0 comments on commit 4001680

Please sign in to comment.