view DPP/dpp2.cbc @ 4:afa536eef659

remove some files
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Thu, 19 Apr 2012 13:41:35 +0900
parents 6695c97470f3
children
line wrap: on
line source

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

#include "dpp2.h"

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 = putdown_lfork;
	goto scheduler(self, current_task);
}

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

/* waiting for right fork */
code hungry2(PhilsPtr self, TaskPtr current_task)
{
	//printf("%d: hungry2\n", self->id);
	self->next = pickup_rfork;
	goto scheduler(self, current_task);
}

/* waiting for left fork */
code hungry1(PhilsPtr self, TaskPtr current_task)
{
	//printf("%d: hungry1\n", self->id);
	self->next = pickup_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 = eating;
		goto scheduler(self, current_task);
	} else {
		self->next = hungry2;
		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 = pickup_rfork;
		goto scheduler(self, current_task);
	} else {
		self->next = hungry1;
		goto scheduler(self, current_task);
	}
}

code thinking(PhilsPtr self, TaskPtr current_task)
{
	//printf("%d: thinking\n", self->id);
	self->next = hungry1;
	goto scheduler(self, current_task);
}

/* end */