Skip to content
kronkorpPublic

About

A tiny task scheduler in C - built for the zappy project.

Topics

Resources

Stars

5 stars

Watchers

0 watching

Forks

Latest commit

 

History

54 Commits

Folders and files

Repository files navigation

Contributors Forks Stargazers Issues License LinkedIn


Kronk Corp logo     Kronkflow logo

Kronkflow

A lightweight and efficient task scheduler library for C
Explore the usage »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. License
  6. Contact

About The Project

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.

Key Features:

  • Efficient Scheduling: Uses a min-heap to keep the next upcoming task at the top.

  • One-time & Periodic Tasks: Support for both punctual and recurring tasks.

  • Staged Execution: Each tick, ready tasks are executed stage by stage, whatever the insertion order.

  • Lightweight: Zero-dependency library, easy to integrate.

(back to top)

Built With

  • C

(back to top)

Getting Started

To get a local copy up and running, follow these steps.

Prerequisites

CMake and a C compiler:

sudo apt install cmake build-essential

Installation

  1. Clone the repo
    git clone https://github.com/kronkorp/kronkflow.git
    cd kronkflow/
  2. Build
    mkdir build
    cd build/
    cmake ..
    make
    This generates libkronkflow.a and libkronkflow.so.
  3. Install the library
    sudo make install

(back to top)

Usage

Here is a simple example of how to use Kronkflow:

#include <kronkflow/scheduler.h>
#include <kronkflow/task.h>
#include <stdio.h>
#include <unistd.h>

// Your task handler
static kfBool my_handler(void *context, void *data)
{
    printf("Task executed with data: %ld\n", (long int)data);
    return kfTrue;
}

int main(void)
{
    // Create a scheduler with a capacity of 512 tasks
    kfScheduler *sch = kfScheduler_create(512);

    // Add a periodic task on stage 0 (runs in 2 ticks, then every 5 ticks)
    kfScheduler_addTask(sch,
        kfTask_opt(&my_handler, (void *)1, NULL, 0, (kfRWMasks){ 0, 0 }), 2, 5);

    // Add a punctual task on stage 1 (runs once in 10 ticks).
    // Each tick, tasks are sorted and executed stage by stage, so this
    // always runs after every stage 0 task, no matter the insertion order.
    kfScheduler_addTask(sch,
        kfTask_opt(&my_handler, (void *)3, NULL, 1, (kfRWMasks){ 0, 0 }), 10, 0);

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

    kfScheduler_destroy(sch);
    return 0;
}

API Overview

Scheduler Management

  • 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, stage by stage.

Task Management

  • kfTask_opt(kfHandler handler, void *data, kfClearer clearer, kfStageId stage, kfRWMasks masks): Build a task opt structure.
  • kfScheduler_addTask(kfScheduler *sch, kfTaskOpt opt, kfTick delay, kfTick interval): Register a task in the scheduler.

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feat/amazing-feature dev)
  3. Commit your Changes (git commit -m '[ADD] Add some amazing feature')
  4. Push to the Branch (git push origin feat/amazing-feature)
  5. Open a Pull Request against dev

(back to top)

Top contributors:

contrib.rocks image

License

Distributed under the MIT license. See LICENSE for more information.

(back to top)

Contact

Gauthier Malfilatre - @GauthierMalfilatre - gauthier.malfilatre@epitech.eu

Project Link: https://github.com/kronkorp/kronkflow

(back to top)

About

A tiny task scheduler in C - built for the zappy project.

Topics

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages