view dpp3.cbc @ 10:35d0358b3fe6

update Modern CbC Compiler
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Mon, 01 Jul 2019 22:18:03 +0900
parents a15437a1e94c
children
line wrap: on
line source

/*
** Program: Dining Philosophors Problem
** Author : Atsuki Shimoji
*/

#include "dpp3.h"
#include "queue.h"

__code putdown_fork(PhilsPtr self, TaskPtr current_task)
{
    //printf("%d: putdown_lfork:%d\n", self->id, self->left_fork->id);
    self->right_fork->owner = NULL;
    self->left_fork->owner = NULL;
    self->next = PickUpLeftFork;
    goto scheduler(self, current_task);
}

/*
__code putdown_lfork(PhilsPtr self, TaskPtr current_task)
{
    //printf("%d: putdown_lfork:%d\n", self->id, self->left_fork->id);
    self->left_fork->owner = NULL;
    self->next = pickup_lfork;
    goto scheduler(self, current_task);
}

__code putdown_rfork(PhilsPtr self, TaskPtr current_task)
{
    //printf("%d: putdown_rfork:%d\n", self->id, self->right_fork->id);
    self->right_fork->owner = NULL;
    self->next = putdown_lfork;
    goto scheduler(self, current_task);
}
*/

__code pickup_rfork(PhilsPtr self, TaskPtr current_task)
{
    if (self->right_fork->owner == NULL) {
	//printf("%d: pickup_rfork:%d\n", self->id, self->right_fork->id);
      self->right_fork->owner = self;
      self->next = PutDownFork;
      goto scheduler(self, current_task);
    } else {
      self->next = PickUpRightFork;
      goto scheduler(self, current_task);
    }
}

__code pickup_lfork(PhilsPtr self, TaskPtr current_task)
{
    if (self->left_fork->owner == NULL) {
	//printf("%d: pickup_lfork:%d\n", self->id, self->left_fork->id);
      self->left_fork->owner = self;
      self->next = PickUpRightFork;
      goto scheduler(self, current_task);
    } else {
      self->next = PickUpLeftFork;
      goto scheduler(self, current_task);
    }
}

__code eating(PhilsPtr self, TaskPtr current_task)
{
	printf("%d: eating\n", self->id);
	self->next = PutDownRightFork;
	goto scheduler(self, current_task);
}

__code putdown_lfork(PhilsPtr self, TaskPtr current_task)
{
	printf("%d: putdown_lfork:%d\n", self->id, self->left_fork->id);
	self->left_fork->owner = NULL;
	self->next = Thinking;
	goto scheduler(self, current_task);
}

__code putdown_rfork(PhilsPtr self, TaskPtr current_task)
{
	printf("%d: putdown_rfork:%d\n", self->id, self->right_fork->id);
	self->right_fork->owner = NULL;
	self->next = PutDownLeftFork;
	goto scheduler(self, current_task);
}
__code thinking(PhilsPtr self, TaskPtr current_task)
{
	printf("%d: thinking\n", self->id);
	self->next = WaitLeftFork;
	goto scheduler(self, current_task);
}
/* end */