This repository has been archived on 2024-05-05. You can view files and clone it, but cannot push or open issues or pull requests.
work-stealing-scheduler/includes/sched.h
Mylloon e97e332c3f
modifications
* move some .h code in .c
* remove unnecessary typedef
* use number of sleeping threads instead of global exit variable
* add some error verification
* use qlen variable

it currently works but probably janky as hell
2024-04-19 16:06:56 +02:00

35 lines
954 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <pthread.h>
#include <unistd.h>
struct scheduler;
typedef void (*taskfunc)(void *, struct scheduler *);
static inline int
sched_default_threads(void)
{
return sysconf(_SC_NPROCESSORS_ONLN);
}
/* Lance l'ordonnanceur
* - nthreads : nombre de threads créer par l'ordonnanceur.
* Si 0, le nombre de threads sera égal au nombre de coeurs de votre machine
*
* - qlen : nombre minimum de tâches simultanées que lordonnanceur devra
* supporter.
* Retourne une erreur si l'utilisateur dépasse qlen
*
* - f, closure : tâche initiale
*
* Renvoie 1 quand elle a terminé, -1 en cas d'échec d'initialisation
*/
int sched_init(int nthreads, int qlen, taskfunc f, void *closure);
/* Enfile une nouvelle tâche (f, closure) à l'ordonanceur (s)
*
* Peut renvoyer -1 avec errno = EAGAIN quand on dépasse la capacité de
* l'ordonanceur
* */
int sched_spawn(taskfunc f, void *closure, struct scheduler *s);