#ifndef MANY_TO_MANY_SCHEDULER_HPP
#define MANY_TO_MANY_SCHEDULER_HPP

/*
    Task function used by the shared-memory benchmark.

    taskId      = frame index, from 0 to taskCount - 1
    workerId    = zero-based worker index
    workerCount = total number of workers
    ctx         = user context, in shm_benchmark this points to MatrixSortContext
*/
typedef void (*ManyToManyPipeTaskFunction)(int taskId,
                                           int workerId,
                                           int workerCount,
                                           void* ctx);

/*
    Many-to-Many pipe scheduler.

    Mechanism:
        - every worker has one private parent-to-child assignment pipe
        - every worker has one private child-to-parent request pipe
        - workers request work dynamically
        - parent uses select() to serve whichever worker requests next
*/
int run_many_to_many_pipe_scheduler(int taskCount,
                                    int workerCount,
                                    ManyToManyPipeTaskFunction taskFn,
                                    void* ctx,
                                    bool useAffinity);

#endif
