view src/synchronizedQueue/synchronizedQueueForSemContext.h @ 143:34a7a21edc36

recude stack get using traverse field
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 09 Nov 2016 22:33:16 +0900
parents 2e7e66ccb3db
children
line wrap: on
line source

/* Context definition for synchronized queue for sem example */

#include <pthread.h>
#define ALLOCATE_SIZE 1000

enum Code {
    Code1,
    Code2,
    Code3,
    Code4,
    Code5,
    Code6,
    Code7,
    Allocator,
    Sender,
    Put,
    Receiver,
    Get,
    Exit,
    ThreadExit,
};

enum UniqueData {
    Allocate,
    Queue,
    Counter,
};

struct Context {
    int codeNum;
    __code (**code) (struct Context *);
    void* heap_start;
    void* heap;
    long dataSize;
    int dataNum;
    union Data* head;
    union Data** data;
};


union Data {
    long count;
    struct Queue {
        union Data* first;
        union Data* last;
        struct Sem {
            volatile int value;
            pthread_mutex_t mutex;
            pthread_cond_t cond;

        } *queue_remain, *queue_count;
    } queue;
    struct Element {
        int value;
        union Data* next;
    } element;
    struct Allocate {
        long size;
        enum Code next;
        enum Code after_put;
        enum Code after_get;
    } allocate;
};