view src/synchronizedQueue/synchronizedQueueContext.c @ 56:4283b87ddbf4

Add stub to synchronizedQueues
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Tue, 16 Jun 2015 15:59:48 +0900
parents 83ee9c75115a
children 2a40d697bf4e
line wrap: on
line source

#include <stdlib.h>

#include "synchronizedQueueContext.h"

extern __code code1_stub(struct Context*);
extern __code code2_stub(struct Context*);
extern __code code3_stub(struct Context*);
extern __code code4_stub(struct Context*);
extern __code code5_stub(struct Context*);
extern __code code6_stub(struct Context*);
extern __code code7_stub(struct Context*);
extern __code meta(struct Context*);
extern __code allocate(struct Context*);
extern __code sender_stub(struct Context*);
extern __code put_stub(struct Context*);
extern __code receiver_stub(struct Context*);
extern __code get_stub(struct Context*);
extern __code exit_code(struct Context*);
extern __code thread_exit_stub(struct Context*);

__code initSynchronizedQueueContext(struct Context* context) {
    context->dataSize   = sizeof(union Data)*ALLOCATE_SIZE;
    context->code       = malloc(sizeof(__code*)*ALLOCATE_SIZE);
    context->data       = malloc(sizeof(union Data*)*ALLOCATE_SIZE);
    context->heap_start = malloc(context->dataSize);

    context->codeNum          = Exit;
    context->code[Allocator]  = allocate;
    context->code[Code1]      = code1_stub;
    context->code[Code2]      = code2_stub;
    context->code[Code3]      = code3_stub;
    context->code[Code4]      = code4_stub;
    context->code[Code5]      = code5_stub;
    context->code[Code6]      = code6_stub;
    context->code[Code7]      = code7_stub;
    context->code[Sender]     = sender_stub;
    context->code[Put]        = put_stub;
    context->code[Receiver]   = receiver_stub;
    context->code[Get]        = get_stub;
    context->code[Exit]       = exit_code;
    context->code[ThreadExit] = thread_exit_stub;

    context->heap = context->heap_start;

    context->data[Allocate] = context->heap;
    context->heap          += sizeof(struct Allocate);

    context->data[Queue]    = context->heap;
    context->heap          += sizeof(struct Queue);
    context->data[Queue]->queue.first = 0;
    pthread_mutex_init(&context->data[Queue]->queue.mutex, NULL);
    pthread_cond_init(&context->data[Queue]->queue.cond, NULL);

    context->dataNum = Queue;
}