view src/parallel_execution/dependency.c @ 169:ea7b11f3e717

Using Queue Interface
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Tue, 22 Nov 2016 09:48:37 +0900
parents 473b7d990a1f
children 747067fe46bd
line wrap: on
line source

#include <stdio.h>
#include "context.h"
#include "origin_cs.h"

__code meta_waitFor(struct Context* context, struct Queue* queue, enum Code next) {
    context->data[D_Queue] = (union Data *)queue;
    goto (context->code[next])(context);
}

__code waitFor1(struct Context* context, struct Task* master, struct Task* slave, struct Element* element) {
    element->data = (union Data *)slave;
    // enqueue waitMe
    goto meta_waitFor(context, master->waitMe, PutQueue1);
}

__code waitFor1_stub(struct Context* context) {
    // next think
}

//__code waitFor2(struct Context* context, struct Task* master, struct Task* slave, struct Element* element) {
//    element->task = master;
//    task->next = context->next;
//    // enqueue waitI
//    goto meta_waitFor(context, task->waitI, PutQueue1);
//}
//
//__code waitFor2_stub(struct Context* context) {
//    // next think
//}

__code meta_spawnTask(struct Context* context, struct Queue* queue, enum Code next) {
    context->data[D_Queue] = (union Data *)queue;
    goto meta(context, context->next);
}

__code spawnTask(struct Context* context, struct Element* element, struct Queue* activeQueue, struct Queue* waitQueue) {
    struct Queue *queue;
    if (task->idsCount == 0) {
        // enqueue activeQueue
        queue = activeQueue;
    } else {
        // enqueue waitQueue
        queue = waitQueue;
    }
    queue->data = element->data;
    queue->next = context->next;
    goto meta_spawnTask(context, queue, queue->put);
}

__code spawnTask_stub(struct Context* context) {
    goto spawnTask(context,
            &context->data[D_Element]->element,
            &context->data[D_ActiveQueue]->queue,
            &context->data[D_WaitQueue]->queue);
}

__code taskA(struct Context* context) {
    printf("TaskA\n");
    goto meta(context, context->next);
}

__code taskB(struct Context* context) {
    printf("TaskB\n");
    goto meta(context, context->next);
}

__code taskC(struct Context* context) {
    printf("TaskC\n");
    goto meta(context, context->next);
}