<commit_before>#include <memory.h>
#include <vfs.h>
#include <binary.h>
#include <mmu.h>
#include <runtime.h>
#include <syscall.h>
#include <multi/multi.h>

static struct runtime_task tasks[MULTI_TASK_SLOTS];

static struct runtime_task *get_task(unsigned int index)
{

    if (!index || index >= MULTI_TASK_SLOTS)
        return 0;

    return &tasks[index];

}

static unsigned int get_task_slot(unsigned int parent)
{

    unsigned int i;

    for (i = parent; i < MULTI_TASK_SLOTS; i++)
    {

        if (!tasks[i].status.used)
            return i;

    }

    return 0;

}

static void schedule()
{

    unsigned int i;

    for (i = MULTI_TASK_SLOTS - 1; i > 0; i--)
    {

        if (!tasks[i].status.used)
            continue;

        if (!tasks[i].status.idle)
        {

            runtime_set_task(&tasks[i]);

            mmu_load_memory(tasks[i].id);

            break;

        }

    }

}

static void notify_pre_event(struct runtime_task *task, unsigned int index)
{

    unsigned int i;

    for (i = 1; i < MULTI_TASK_SLOTS - 1; i++)
    {

        if (!tasks[i].status.used)
            continue;

        if (!tasks[i].status.idle)
            continue;

        if (tasks[i].events[index].callback)
        {

            tasks[i].status.idle = 0;
            runtime_init_registers(&tasks[i].registers, tasks[i].events[index].callback, RUNTIME_TASK_VADDRESS_BASE + RUNTIME_TASK_ADDRESS_SIZE, RUNTIME_TASK_VADDRESS_BASE + RUNTIME_TASK_ADDRESS_SIZE);

        }

    }

}

static void notify_post_event(struct runtime_task *task, unsigned int index)
{

    schedule();

}

void clone_task(struct runtime_task *task, struct runtime_task *from, unsigned int id, unsigned int ip)
{

    memory_copy(task, from, sizeof (struct runtime_task));

    runtime_init_registers(&task->registers, ip, RUNTIME_TASK_VADDRESS_BASE + RUNTIME_TASK_ADDRESS_SIZE, RUNTIME_TASK_VADDRESS_BASE + RUNTIME_TASK_ADDRESS_SIZE);

    task->id = id;
    task->notify_pre_event = notify_pre_event;
    task->notify_post_event = notify_post_event;

}

static unsigned int spawn(struct runtime_task *task, void *stack)
{

    struct syscall_spawn_args *args = stack;<commit_msg>more cleanups<commit_after>#include <memory.h>
#include <vfs.h>
#include <binary.h>
#include <mmu.h>
#include <runtime.h>
#include <syscall.h>
#include <multi/multi.h>

static struct runtime_task tasks[MULTI_TASK_SLOTS];

static struct runtime_task *get_task(unsigned int index)
{

    if (!index || index >= MULTI_TASK_SLOTS)
        return 0;

    return &tasks[index];

}

static unsigned int get_task_slot(unsigned int parent)
{

    unsigned int i;

    for (i = parent; i < MULTI_TASK_SLOTS; i++)
    {

        if (!tasks[i].status.used)
            return i;

    }

    return 0;

}

static void schedule()
{

    unsigned int i;

    for (i = MULTI_TASK_SLOTS - 1; i > 0; i--)
    {

        if (!tasks[i].status.used)
            continue;

        if (tasks[i].status.idle)
            continue;

        runtime_set_task(&tasks[i]);

        mmu_load_memory(tasks[i].id);

        break;

    }

}

static void notify_pre_event(struct runtime_task *task, unsigned int index)
{

    unsigned int i;

    for (i = 1; i < MULTI_TASK_SLOTS - 1; i++)
    {

        if (!tasks[i].status.used)
            continue;

        if (!tasks[i].status.idle)
            continue;

        if (!tasks[i].events[index].callback)
            continue;

        tasks[i].status.idle = 0;
        runtime_init_registers(&tasks[i].registers, tasks[i].events[index].callback, RUNTIME_TASK_VADDRESS_BASE + RUNTIME_TASK_ADDRESS_SIZE, RUNTIME_TASK_VADDRESS_BASE + RUNTIME_TASK_ADDRESS_SIZE);

    }

}

static void notify_post_event(struct runtime_task *task, unsigned int index)
{

    schedule();

}

void clone_task(struct runtime_task *task, struct runtime_task *from, unsigned int id, unsigned int ip)
{

    memory_copy(task, from, sizeof (struct runtime_task));

    runtime_init_registers(&task->registers, ip, RUNTIME_TASK_VADDRESS_BASE + RUNTIME_TASK_ADDRESS_SIZE, RUNTIME_TASK_VADDRESS_BASE + RUNTIME_TASK_ADDRESS_SIZE);

    task->id = id;
    task->notify_pre_event = notify_pre_event;
    task->notify_post_event = notify_post_event;

}

static unsigned int spawn(struct runtime_task *task, void *stack)
{

    struct syscall_spawn_args *args = stack;
{'fraction_non_alphanumeric': 0.11362586605080831, 'fraction_numerical': 0.003233256351039261, 'mean_word_length': 2.9661172161172162, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5797684', 'n_tokens_mistral': 1567, 'n_tokens_neox': 1479, 'n_words': 320}