Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ libargot.so

# Build
Release/
build/
Debug/

# Test
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
cmake_minimum_required(VERSION 3.15)
project(kronkflow LANGUAGES C)

include(cmake/ProjectOptions.cmake)
include(cmake/CompilerOptions.cmake)
include(cmake/Utils.cmake)

if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
message(FATAL_ERROR "Les builds dans le dossier source sont interdits. Créez un dossier de build (ex: 'build/').")
endif()
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ int main(void)
- `kfScheduler_tick(kfScheduler *sch, void *context)`: Advance the scheduler by one tick and execute ready tasks.

### Task Management
- `kfTask_opt(prHandler handler, void *data, prClearer clearer)`: Build a task opt structure.
- `kfScheduler_addTask(kfScheduler *sch, kfTask task, prTick delay, prTick interval)`: Register a task in the scheduler.
- `kfTask_opt(kfHandler handler, void *data, kfClearer clearer)`: Build a task opt structure.
- `kfScheduler_addTask(kfScheduler *sch, kfTask task, kfTick delay, kfTick interval)`: Register a task in the scheduler.

## License

Expand Down
19 changes: 19 additions & 0 deletions cmake/CompilerOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
add_library(project_options INTERFACE)

target_compile_options(project_options INTERFACE
${PROJECT_WARNINGS}
$<$<CONFIG:Debug>:${PROJECT_DEBUG_FLAGS}>
$<$<CONFIG:Release>:${PROJECT_RELEASE_FLAGS}>
)

target_link_libraries(project_options INTERFACE
stdc++exp
)

target_link_options(project_options INTERFACE
-rdynamic
)

target_compile_definitions(project_options INTERFACE
$<$<CONFIG:Debug>:_DEBUG>
)
16 changes: 16 additions & 0 deletions cmake/ProjectOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Global settings
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Warnings
set(PROJECT_WARNINGS
-Wall -Wextra -Wpedantic
-Wshadow -Wnull-dereference
-Wcast-align -Wmissing-declarations
-Wundef -Wunreachable-code
)

# Build flags
set(PROJECT_DEBUG_FLAGS -g -O0)
set(PROJECT_RELEASE_FLAGS -O3)
3 changes: 3 additions & 0 deletions cmake/Utils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function(apply_project_settings target)
target_link_libraries(${target} PRIVATE project_options)
endfunction()
16 changes: 8 additions & 8 deletions include/kronkflow/macros/optimization.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@
#define PROPHECY_MACROS_OPTIMIZATION_H

#if defined(__GNUC__) && (__GNUC__ >= 4) || defined(__has_attribute) && __has_attribute(visibility)
#define PR_API __attribute__((visibility("default")))
#define KF_API __attribute__((visibility("default")))
#else
#define PR_API
#define KF_API
#endif

#if defined(__GNUC__) && (__GNUC__ >= 4) || defined(__has_attribute) && __has_attribute(unused)
#define PR_UNUSED __attribute__((unused))
#define KF_UNUSED __attribute__((unused))
#else
#define PR_UNUSED
#define KF_UNUSED
#endif

#if defined(__GNUC__) && (__GNUC__ >= 4) || defined(__has_attribute) && __has_attribute(hot)
#define PR_HOT __attribute__((hot))
#define KF_HOT __attribute__((hot))
#else
#define PR_HOT
#define KF_HOT
#endif

#if defined(__GNUC__) && (__GNUC__ >= 4) || defined(__has_attribute) && __has_attribute(cold)
#define PR_COLD __attribute__((cold))
#define KF_COLD __attribute__((cold))
#else
#define PR_COLD
#define KF_COLD
#endif

#endif /* PROPHECY_MACROS_OPTIMIZATION_H */
12 changes: 6 additions & 6 deletions include/kronkflow/macros/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
#include <stddef.h>
#include <stdint.h>

typedef int prBool;
#define knTrue 1
#define knFalse 0
typedef int kfBool;
#define kfTrue 1
#define kfFalse 0

typedef prBool (*prHandler)(void *, void *);
typedef void (*prClearer)(void *);
typedef uint64_t prTick;
typedef kfBool (*kfHandler)(void *, void *);
typedef void (*kfClearer)(void *);
typedef uint64_t kfTick;
typedef size_t kfTaskID;

#endif /* PROPHECY_MACROS_TYPES_H */
10 changes: 5 additions & 5 deletions include/kronkflow/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ typedef struct prophecy_scheduler_s kfScheduler;
* @return Returns newly allocated kfScheduler, or NULL on error
*/
///////////////////////////////////////////////////////////////////////////////
PR_API kfScheduler *kfScheduler_create(size_t size);
KF_API kfScheduler *kfScheduler_create(size_t size);
///////////////////////////////////////////////////////////////////////////////


Expand All @@ -46,7 +46,7 @@ PR_API kfScheduler *kfScheduler_create(size_t size);
* @param sch The scheduler to destroy
*/
///////////////////////////////////////////////////////////////////////////////
PR_API void kfScheduler_destroy(kfScheduler *sch);
KF_API void kfScheduler_destroy(kfScheduler *sch);
///////////////////////////////////////////////////////////////////////////////


Expand All @@ -61,7 +61,7 @@ PR_API void kfScheduler_destroy(kfScheduler *sch);
* @return The id of the task added (>1), 0 if failed
*/
///////////////////////////////////////////////////////////////////////////////
PR_API kfTaskID kfScheduler_addTask(kfScheduler *sch, kfTaskOpt opt, prTick delay, prTick interval);
KF_API kfTaskID kfScheduler_addTask(kfScheduler *sch, kfTaskOpt opt, kfTick delay, kfTick interval);
///////////////////////////////////////////////////////////////////////////////


Expand All @@ -74,7 +74,7 @@ PR_API kfTaskID kfScheduler_addTask(kfScheduler *sch, kfTaskOpt opt, prTick dela
* @return Returns the number of tasks executed this tick
*/
///////////////////////////////////////////////////////////////////////////////
PR_API size_t kfScheduler_tick(kfScheduler *sch, void *context);
KF_API size_t kfScheduler_tick(kfScheduler *sch, void *context);
///////////////////////////////////////////////////////////////////////////////


Expand All @@ -86,7 +86,7 @@ PR_API size_t kfScheduler_tick(kfScheduler *sch, void *context);
* @return The current tick
*/
///////////////////////////////////////////////////////////////////////////////
PR_API prTick kfScheduler_currentTick(const kfScheduler *sch);
KF_API kfTick kfScheduler_currentTick(const kfScheduler *sch);
///////////////////////////////////////////////////////////////////////////////

#endif /* PROPHECY_SCHEDULER_H */
10 changes: 5 additions & 5 deletions include/kronkflow/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ typedef struct prophecy_task_s kfTask;
///////////////////////////////////////////////////////////////////////////////
typedef struct prophecy_task_opt_s {

prHandler handler; //!< The task handler (function ptr)
kfHandler handler; //!< The task handler (function ptr)
void* data; //!< The data to give to the handler
prClearer clearer; //!< The clearer of the data if allocated
kfClearer clearer; //!< The clearer of the data if allocated

} kfTaskOpt;
///////////////////////////////////////////////////////////////////////////////
Expand All @@ -39,12 +39,12 @@ typedef struct prophecy_task_opt_s {
/**
* @brief Create task opts
*
* @param handler The function ptr handler prBool (*)(void *, void *)
* @param handler The function ptr handler kfBool (*)(void *, void *)
* @param data The data to give to the handler
* @param clearer The clearer to clear data if allocated
*/
///////////////////////////////////////////////////////////////////////////////
PR_API kfTaskOpt kfTask_opt(prHandler handler, void *data, prClearer clearer);
KF_API kfTaskOpt kfTask_opt(kfHandler handler, void *data, kfClearer clearer);
///////////////////////////////////////////////////////////////////////////////


Expand All @@ -58,7 +58,7 @@ PR_API kfTaskOpt kfTask_opt(prHandler handler, void *data, prClearer clearer);
* @return Returns the new task
*/
///////////////////////////////////////////////////////////////////////////////
PR_API kfTask kfTask_create(kfTaskOpt *data, prTick delay, prTick interval);
KF_API kfTask kfTask_create(kfTaskOpt *data, kfTick delay, kfTick interval);
///////////////////////////////////////////////////////////////////////////////

#endif /* PROPHECY_TASKS_H */
10 changes: 10 additions & 0 deletions include/kronkflow/utils/threadpool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Give access to only one function that test the threadpool

#ifndef KRONKFLOW_THREADPOOL_TEST
#define KRONKFLOW_THREADPOOL_TEST

#include "kronkflow/macros/optimization.h"

KF_API void kfThreadPool_test(void);

#endif /* KRONKFLOW_THREADPOOL_TEST */
2 changes: 1 addition & 1 deletion src/scheduler/clear/scheduler_destroy.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "kronkflow/macros/optimization.h"
#include <stdlib.h>

PR_API
KF_API
void kfScheduler_destroy(
kfScheduler *sch
)
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/init/scheduler_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <stdlib.h>
#include <stddef.h>

PR_API
KF_API
kfScheduler *kfScheduler_create(
size_t size
)
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef struct prophecy_scheduler_s {
kfTask *tasks; //!< The raw array of tasks
size_t size; //!< The size of tasks raw array
size_t count; //!< The number of tasks pushed
prTick tick; //!< The current tick (please tick scheduler at each loop)
kfTick tick; //!< The current tick (please tick scheduler at each loop)

} kfScheduler;
///////////////////////////////////////////////////////////////////////////////
Expand Down
6 changes: 3 additions & 3 deletions src/scheduler/scheduler_addTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ static int __kfScheduler_ensureCapacity(
return 0;
}

PR_API
KF_API
size_t kfScheduler_addTask(
kfScheduler *sch,
kfTaskOpt taskOptions,
prTick target,
prTick interval
kfTick target,
kfTick interval
)
{
static size_t _id = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/scheduler/scheduler_currentTick.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "kronkflow/scheduler.h"
#include "scheduler.h"

PR_API
prTick kfScheduler_currentTick(
KF_API
kfTick kfScheduler_currentTick(
const kfScheduler *sch
)
{
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/scheduler_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "../minheap/minheap.h"
#include "kronkflow/scheduler.h"

PR_API
KF_API
size_t kfScheduler_tick(
kfScheduler *sch,
void *context
Expand Down
8 changes: 4 additions & 4 deletions src/task/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
typedef struct prophecy_task_s {

size_t id; //!< The id of the tasks
prHandler handler; //!< The handler (callback)
kfHandler handler; //!< The handler (callback)
void* data; //!< The task data
prClearer clearer; //!< The data clearer
prTick interval; //!< The interval (0 if ponctual, > 0 else)
prTick target; //!< The tick remainings.
kfClearer clearer; //!< The data clearer
kfTick interval; //!< The interval (0 if ponctual, > 0 else)
kfTick target; //!< The tick remainings.

} kfTask;
///////////////////////////////////////////////////////////////////////////////
Expand Down
6 changes: 3 additions & 3 deletions src/task/task_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
#include "task.h"

// DEBUG: Make sure opt is not NULL
PR_API
KF_API
inline
kfTask kfTask_create(
kfTaskOpt *opt,
prTick delay,
prTick interval
kfTick delay,
kfTick interval
)
{
return (kfTask){
Expand Down
6 changes: 3 additions & 3 deletions src/task/task_opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#include "kronkflow/macros/types.h"
#include "kronkflow/task.h"

PR_API
KF_API
inline
kfTaskOpt kfTask_opt(
prHandler handler,
kfHandler handler,
void *data,
prClearer clearer
kfClearer clearer
)
{
return (kfTaskOpt){
Expand Down
Loading