diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3f72d5a..5f5603e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,7 +22,7 @@ jobs: - uses: actions/checkout@v3 - name: Configure static library - run: cmake -S . -B build-static + run: cmake -S . -B build-static -D ENKITS_SANITIZE=ON - name: Build static library run: cmake --build build-static --parallel - name: Test static library @@ -48,7 +48,7 @@ jobs: - uses: actions/checkout@v3 - name: Configure static library - run: cmake -S . -B build-static + run: cmake -S . -B build-static -D ENKITS_SANITIZE=ON - name: Build static library run: cmake --build build-static --parallel - name: Test static library @@ -71,7 +71,7 @@ jobs: - uses: actions/checkout@v3 - name: Configure static library - run: cmake -S . -B build-static + run: cmake -S . -B build-static -D ENKITS_SANITIZE=ON - name: Build static library run: cmake --build build-static --parallel - name: Test static library @@ -93,8 +93,13 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Setup MSVC dev command prompt + uses: TheMrMilchmann/setup-msvc-dev@v3 + with: + arch: x64 + - name: Configure static library - run: cmake -S . -B build-static -G "Visual Studio 17 2022" + run: cmake -S . -B build-static -G "Visual Studio 17 2022" -D ENKITS_SANITIZE=ON - name: Build static library run: cmake --build build-static --parallel - name: Test static library diff --git a/CMakeLists.txt b/CMakeLists.txt index b18051c..0c12562 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ option( ENKITS_BUILD_C_INTERFACE "Build C interface" ON ) option( ENKITS_BUILD_EXAMPLES "Build example applications" ON ) option( ENKITS_BUILD_SHARED "Build shared library" OFF ) option( ENKITS_INSTALL "Generate installation target" OFF ) +option( ENKITS_SANITIZE "Build with sanitizers" OFF) set( ENKITS_TASK_PRIORITIES_NUM "3" CACHE STRING "Number of task priorities, 1-5, 0 for defined by defaults in source" ) @@ -36,6 +37,17 @@ endif() list( APPEND ENKITS_SRC ${ENKITS_HEADERS} ) +if(ENKITS_SANITIZE) + if(MSVC) + add_compile_options(/fsanitize=address) + add_link_options(/INCREMENTAL:NO) + else() + # add_compile_options(-fsanitize=thread -fno-omit-frame-pointer) + add_compile_options(-fsanitize=address -fsanitize-address-use-after-scope -fsanitize=undefined) + add_link_options(-fsanitize=address -fsanitize-address-use-after-scope -fsanitize=undefined) + endif() +endif() + if( ENKITS_BUILD_SHARED ) add_library( enkiTS SHARED ${ENKITS_SRC} ) target_compile_definitions( enkiTS PRIVATE ENKITS_BUILD_DLL=1 ) diff --git a/src/TaskScheduler_c.cpp b/src/TaskScheduler_c.cpp index 5c73d34..5f97fe6 100644 --- a/src/TaskScheduler_c.cpp +++ b/src/TaskScheduler_c.cpp @@ -206,7 +206,7 @@ ENKITS_API uint32_t enkiGetNumFirstExternalTaskThread() enkiTaskSet* enkiCreateTaskSet( enkiTaskScheduler* pETS_, enkiTaskExecuteRange taskFunc_ ) { - const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator; + CustomAllocator customAllocator = pETS_->GetConfig().customAllocator; enkiTaskSet* pTask = (enkiTaskSet*)customAllocator.alloc( alignof(enkiTaskSet), sizeof(enkiTaskSet), customAllocator.userData, ENKI_FILE_AND_LINE ); new(pTask) enkiTaskSet( taskFunc_ ); @@ -216,7 +216,7 @@ enkiTaskSet* enkiCreateTaskSet( enkiTaskScheduler* pETS_, enkiTaskExecuteRange t void enkiDeleteTaskSet( enkiTaskScheduler* pETS_, enkiTaskSet* pTaskSet_ ) { - const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator; + CustomAllocator customAllocator = pETS_->GetConfig().customAllocator; pTaskSet_->~enkiTaskSet(); customAllocator.free( pTaskSet_, sizeof(enkiTaskSet), customAllocator.userData, ENKI_FILE_AND_LINE ); @@ -300,7 +300,7 @@ int enkiIsTaskSetComplete( enkiTaskScheduler* pETS_, enkiTaskSet* pTaskSet_ ) enkiPinnedTask* enkiCreatePinnedTask(enkiTaskScheduler* pETS_, enkiPinnedTaskExecute taskFunc_, uint32_t threadNum_) { - const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator; + CustomAllocator customAllocator = pETS_->GetConfig().customAllocator; enkiPinnedTask* pTask = (enkiPinnedTask*)customAllocator.alloc( alignof(enkiPinnedTask), sizeof(enkiPinnedTask), customAllocator.userData, ENKI_FILE_AND_LINE ); new(pTask) enkiPinnedTask( taskFunc_, threadNum_ ); @@ -309,7 +309,7 @@ enkiPinnedTask* enkiCreatePinnedTask(enkiTaskScheduler* pETS_, enkiPinnedTaskExe void enkiDeletePinnedTask( enkiTaskScheduler* pETS_, enkiPinnedTask* pPinnedTask_ ) { - const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator; + CustomAllocator customAllocator = pETS_->GetConfig().customAllocator; pPinnedTask_->~enkiPinnedTask(); customAllocator.free( pPinnedTask_, sizeof(enkiPinnedTask), customAllocator.userData, ENKI_FILE_AND_LINE ); @@ -443,7 +443,7 @@ enkiCompletable* enkiGetCompletableFromCompletionAction( enkiCompletionAction* p enkiCompletable* enkiCreateCompletable( enkiTaskScheduler* pETS_ ) { - const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator; + CustomAllocator customAllocator = pETS_->GetConfig().customAllocator; enkiCompletable* pTask = (enkiCompletable*)customAllocator.alloc( alignof(enkiCompletable), sizeof(enkiCompletable), customAllocator.userData, ENKI_FILE_AND_LINE ); new(pTask) enkiCompletable(); @@ -452,7 +452,7 @@ enkiCompletable* enkiCreateCompletable( enkiTaskScheduler* pETS_ ) void enkiDeleteCompletable( enkiTaskScheduler* pETS_, enkiCompletable* pCompletable_ ) { - const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator; + CustomAllocator customAllocator = pETS_->GetConfig().customAllocator; pCompletable_->~enkiCompletable(); customAllocator.free( pCompletable_, sizeof(enkiCompletable), customAllocator.userData, ENKI_FILE_AND_LINE ); @@ -470,7 +470,7 @@ void enkiWaitForCompletablePriority( enkiTaskScheduler* pETS_, enkiCompletable* enkiDependency* enkiCreateDependency( enkiTaskScheduler* pETS_ ) { - const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator; + CustomAllocator customAllocator = pETS_->GetConfig().customAllocator; enkiDependency* pDep = (enkiDependency*)customAllocator.alloc( alignof(enkiDependency), sizeof(enkiDependency), customAllocator.userData, ENKI_FILE_AND_LINE ); new(pDep) enkiDependency(); @@ -479,7 +479,7 @@ enkiDependency* enkiCreateDependency( enkiTaskScheduler* pETS_ ) void enkiDeleteDependency( enkiTaskScheduler* pETS_, enkiDependency* pDependency_ ) { - const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator; + CustomAllocator customAllocator = pETS_->GetConfig().customAllocator; pDependency_->~enkiDependency(); customAllocator.free( pDependency_, sizeof(enkiDependency), customAllocator.userData, ENKI_FILE_AND_LINE ); @@ -492,7 +492,7 @@ void enkiSetDependency( enkiDependency* pDependency_, enkiCompletable* pDependen enkiCompletionAction* enkiCreateCompletionAction( enkiTaskScheduler* pETS_, enkiCompletionFunction completionFunctionPreComplete_, enkiCompletionFunction completionFunctionPostComplete_ ) { - const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator; + CustomAllocator customAllocator = pETS_->GetConfig().customAllocator; enkiCompletionAction* pCA = (enkiCompletionAction*)customAllocator.alloc( alignof(enkiCompletionAction), sizeof(enkiCompletionAction), customAllocator.userData, ENKI_FILE_AND_LINE ); new(pCA) enkiCompletionAction(); @@ -503,7 +503,7 @@ enkiCompletionAction* enkiCreateCompletionAction( enkiTaskScheduler* pETS_, enki void enkiDeleteCompletionAction( enkiTaskScheduler* pETS_, enkiCompletionAction* pCompletionAction_ ) { - const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator; + CustomAllocator customAllocator = pETS_->GetConfig().customAllocator; pCompletionAction_->~enkiCompletionAction(); customAllocator.free( pCompletionAction_, sizeof(enkiCompletionAction), customAllocator.userData, ENKI_FILE_AND_LINE );