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
36 changes: 18 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
cmake_minimum_required(VERSION 3.15)
project(prophecy LANGUAGES C)
project(kronkflow LANGUAGES C)

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()

file(GLOB_RECURSE prophecy_SOURCES
file(GLOB_RECURSE kronkflow_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.c"
)

set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)

add_library(prophecy-obj OBJECT ${prophecy_SOURCES})
add_library(kronkflow-obj OBJECT ${kronkflow_SOURCES})

target_include_directories(prophecy-obj
target_include_directories(kronkflow-obj
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_compile_options(prophecy-obj PRIVATE
target_compile_options(kronkflow-obj PRIVATE
-Wall
-Wextra
-O3
)

set_target_properties(prophecy-obj PROPERTIES
set_target_properties(kronkflow-obj PROPERTIES
POSITION_INDEPENDENT_CODE ON
)

add_library(prophecy-static STATIC $<TARGET_OBJECTS:prophecy-obj>)
target_link_libraries(prophecy-static PUBLIC prophecy-obj)
add_library(kronkflow-static STATIC $<TARGET_OBJECTS:kronkflow-obj>)
target_link_libraries(kronkflow-static PUBLIC kronkflow-obj)

add_library(prophecy-shared SHARED $<TARGET_OBJECTS:prophecy-obj>)
target_link_libraries(prophecy-shared PUBLIC prophecy-obj)
add_library(kronkflow-shared SHARED $<TARGET_OBJECTS:kronkflow-obj>)
target_link_libraries(kronkflow-shared PUBLIC kronkflow-obj)

target_compile_definitions(prophecy-shared PRIVATE prophecy_BUILD_DLL)
target_compile_definitions(kronkflow-shared PRIVATE kronkflow_BUILD_DLL)

add_library(prophecy ALIAS prophecy-static)
add_library(kronkflow ALIAS kronkflow-static)

set_target_properties(prophecy-static PROPERTIES
OUTPUT_NAME prophecy
set_target_properties(kronkflow-static PROPERTIES
OUTPUT_NAME kronkflow
)

set_target_properties(prophecy-shared PROPERTIES
OUTPUT_NAME prophecy
set_target_properties(kronkflow-shared PROPERTIES
OUTPUT_NAME kronkflow
)

# NOTE: Installation

include(GNUInstallDirs)

install(TARGETS prophecy-static prophecy-shared
install(TARGETS kronkflow-static kronkflow-shared
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/prophecy
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/kronkflow
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Prophecy
# Kronkflow

Prophecy is a lightweight, efficient task scheduler library for C applications. It implements a **min-heap binary tree** to manage task priorities, ensuring optimal resource usage and fast task lookups.
Kronkflow is a lightweight, efficient task scheduler library for C applications. It implements a **min-heap binary tree** to manage task priorities, ensuring optimal resource usage and fast task lookups.

## Features

Expand All @@ -19,18 +19,18 @@ cmake ..
make
```

This will generate `libprophecy.a` and `libprophecy.so`. You can now install with
This will generate `libkronkflow.a` and `libkronkflow.so`. You can now install with

```bash
sudo make install
```

## Quick Start

Here is a simple example of how to use Prophecy:
Here is a simple example of how to use Kronkflow:

```c
#include "prophecy.h"
#include <kronkflow.h>
#include <stdio.h>
#include <unistd.h>

Expand All @@ -43,35 +43,35 @@ static bool my_handler(void *context, void *data)
int main(void)
{
// Create a scheduler with a capacity of 512 tasks
prScheduler *sch = prScheduler_create(512);
kfScheduler *sch = kfScheduler_create(512);

// Add a periodic task (runs in 2 ticks, then every 5 ticks)
prScheduler_addTask(sch, prTask_opt(&my_handler, (void *)1, NULL) 2, 5);
kfScheduler_addTask(sch, kfTask_opt(&my_handler, (void *)1, NULL) 2, 5);

// Add a punctual task (runs once in 10 ticks)
prScheduler_addTask(sch, prTask_opt(&my_handler, (void *)3, NULL), 10, 0);
kfScheduler_addTask(sch, kfTask_opt(&my_handler, (void *)3, NULL), 10, 0);

// Main loop
while (1) {
sleep(1); // Simulate time passing
prScheduler_tick(sch, NULL);
kfScheduler_tick(sch, NULL);
}

prScheduler_destroy(sch);
kfScheduler_destroy(sch);
return true;
}
```

## API Overview

### Scheduler Management
- `prScheduler_create(size_t size)`: Allocate and initialize a new scheduler.
- `prScheduler_destroy(prScheduler *sch)`: Free the scheduler and its resources.
- `prScheduler_tick(prScheduler *sch, void *context)`: Advance the scheduler by one tick and execute ready tasks.
- `kfScheduler_create(size_t size)`: Allocate and initialize a new scheduler.
- `kfScheduler_destroy(kfScheduler *sch)`: Free the scheduler and its resources.
- `kfScheduler_tick(kfScheduler *sch, void *context)`: Advance the scheduler by one tick and execute ready tasks.

### Task Management
- `prTask_opt(prHandler handler, void *data, prClearer clearer)`: Build a task opt structure.
- `prScheduler_addTask(prScheduler *sch, prTask task, prTick delay, prTick interval)`: Register a task in the scheduler.
- `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.

## License

Expand Down
5 changes: 5 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# KRONKFLOW - TODO

[ ] Add multithreading options to the scheduler
[ ] Add Read / Write mask when adding a task so we can do clean multi threading
[ ] Add custom thread pool in C
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
typedef prBool (*prHandler)(void *, void *);
typedef void (*prClearer)(void *);
typedef uint64_t prTick;
typedef size_t prTaskID;
typedef size_t kfTaskID;

#endif /* PROPHECY_MACROS_TYPES_H */
22 changes: 11 additions & 11 deletions include/prophecy/scheduler.h → include/kronkflow/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/
#ifndef PROPHECY_SCHEDULER_H
#define PROPHECY_SCHEDULER_H
#include "prophecy/macros/types.h"
#include "prophecy/macros/optimization.h"
#include "prophecy/task.h"
#include "kronkflow/macros/types.h"
#include "kronkflow/macros/optimization.h"
#include "kronkflow/task.h"
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
Expand All @@ -20,10 +20,10 @@

///////////////////////////////////////////////////////////////////////////////
/**
* @brief Forward declaration of prScheduler type
* @brief Forward declaration of kfScheduler type
*/
///////////////////////////////////////////////////////////////////////////////
typedef struct prophecy_scheduler_s prScheduler;
typedef struct prophecy_scheduler_s kfScheduler;
///////////////////////////////////////////////////////////////////////////////


Expand All @@ -32,10 +32,10 @@ typedef struct prophecy_scheduler_s prScheduler;
* @brief Create a task scheduler
*
* @param size Starting size of tasks scheduler
* @return Returns newly allocated prScheduler, or NULL on error
* @return Returns newly allocated kfScheduler, or NULL on error
*/
///////////////////////////////////////////////////////////////////////////////
PR_API prScheduler *prScheduler_create(size_t size);
PR_API kfScheduler *kfScheduler_create(size_t size);
///////////////////////////////////////////////////////////////////////////////


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


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


Expand All @@ -74,7 +74,7 @@ PR_API prTaskID prScheduler_addTask(prScheduler *sch, prTaskOpt opt, prTick dela
* @return Returns the number of tasks executed this tick
*/
///////////////////////////////////////////////////////////////////////////////
PR_API size_t prScheduler_tick(prScheduler *sch, void *context);
PR_API size_t kfScheduler_tick(kfScheduler *sch, void *context);
///////////////////////////////////////////////////////////////////////////////


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

#endif /* PROPHECY_SCHEDULER_H */
14 changes: 7 additions & 7 deletions include/prophecy/task.h → include/kronkflow/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
*/
#ifndef PROPHECY_TASKS_H
#define PROPHECY_TASKS_H
#include "prophecy/macros/optimization.h"
#include "prophecy/macros/types.h"
#include "kronkflow/macros/optimization.h"
#include "kronkflow/macros/types.h"

///////////////////////////////////////////////////////////////////////////////
/**
* @brief Forward declaration of prTask
* @brief Forward declaration of kfTask
*/
///////////////////////////////////////////////////////////////////////////////
typedef struct prophecy_task_s prTask;
typedef struct prophecy_task_s kfTask;
///////////////////////////////////////////////////////////////////////////////


Expand All @@ -31,7 +31,7 @@ typedef struct prophecy_task_opt_s {
void* data; //!< The data to give to the handler
prClearer clearer; //!< The clearer of the data if allocated

} prTaskOpt;
} kfTaskOpt;
///////////////////////////////////////////////////////////////////////////////


Expand All @@ -44,7 +44,7 @@ typedef struct prophecy_task_opt_s {
* @param clearer The clearer to clear data if allocated
*/
///////////////////////////////////////////////////////////////////////////////
PR_API prTaskOpt prTask_opt(prHandler handler, void *data, prClearer clearer);
PR_API kfTaskOpt kfTask_opt(prHandler handler, void *data, prClearer clearer);
///////////////////////////////////////////////////////////////////////////////


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

#endif /* PROPHECY_TASKS_H */
14 changes: 7 additions & 7 deletions src/minheap/minheap.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

///////////////////////////////////////////////////////////////////////////////
/**
* @brief Forward declaration of prScheduler
* @brief Forward declaration of kfScheduler
*/
///////////////////////////////////////////////////////////////////////////////
typedef struct prophecy_scheduler_s prScheduler;
typedef struct prophecy_scheduler_s kfScheduler;
///////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////
/**
* @brief Forward declaration of prTask
* @brief Forward declaration of kfTask
*/
///////////////////////////////////////////////////////////////////////////////
typedef struct prophecy_task_s prTask;
typedef struct prophecy_task_s kfTask;
///////////////////////////////////////////////////////////////////////////////


Expand All @@ -34,7 +34,7 @@ typedef struct prophecy_task_s prTask;
* @param idx The index of the task
*/
///////////////////////////////////////////////////////////////////////////////
void prMinHeap_add(prScheduler *sch, size_t idx);
void prMinHeap_add(kfScheduler *sch, size_t idx);
///////////////////////////////////////////////////////////////////////////////


Expand All @@ -46,7 +46,7 @@ void prMinHeap_add(prScheduler *sch, size_t idx);
* @param idx The index of the task to remove
*/
///////////////////////////////////////////////////////////////////////////////
void prMinHeap_remove(prScheduler *sch, size_t idx);
void prMinHeap_remove(kfScheduler *sch, size_t idx);
///////////////////////////////////////////////////////////////////////////////


Expand All @@ -58,7 +58,7 @@ void prMinHeap_remove(prScheduler *sch, size_t idx);
* @param task2 The task2 to swap
*/
///////////////////////////////////////////////////////////////////////////////
void prMinHeap_swap(prTask *task1, prTask *task2);
void prMinHeap_swap(kfTask *task1, kfTask *task2);
///////////////////////////////////////////////////////////////////////////////

#endif /* PROPHECY_MINHEAP_H */
2 changes: 1 addition & 1 deletion src/minheap/minheap_add.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
// DEBUG: Bubble up
void prMinHeap_add(
prScheduler *sch,
kfScheduler *sch,
size_t idx
)
{
Expand Down
2 changes: 1 addition & 1 deletion src/minheap/minheap_remove.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <stddef.h>

void prMinHeap_remove(
prScheduler *sch,
kfScheduler *sch,
size_t idx
)
{
Expand Down
6 changes: 3 additions & 3 deletions src/minheap/minheap_swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#include "../scheduler/scheduler.h"

void prMinHeap_swap(
prTask *task1,
prTask *task2
kfTask *task1,
kfTask *task2
)
{
prTask tmp = *task1;
kfTask tmp = *task1;

*task1 = *task2;
*task2 = tmp;
Expand Down
4 changes: 2 additions & 2 deletions src/scheduler/clear/scheduler_clear.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <stddef.h>
#include <stdlib.h>

void prScheduler_clear(
prScheduler *sch
void kfScheduler_clear(
kfScheduler *sch
)
{
if (!sch) {
Expand Down
Loading
Loading