示例#1
0
void create_data(){
	struct semaphore* s=semaphore_create(M);
	set_bouncer(s);
	
	struct BB* bb=BB_create(A);
	set_ABB(bb);
	
	bb=BB_create(A);
	set_DrinkBB(bb);
	
	bb=BB_create(C);
	set_CBB(bb);
	// buy new cups
	int i;
	for(i=0; i<C; i++){
		struct Cup* c=malloc(sizeof(struct Cup));
		c->id=next_cupID;
		next_cupID++;
		printf(1, "buy new cup\n");
		BB_put(cbb, c);
	}
	
	bb=BB_create(C);
	set_DBB(bb);
}
示例#2
0
void return_cup(struct Cup* c)
{
	BB_put(dbb, c);
	dc_count++;
	
	if(get_dc_percent()>60){
		printf(1, "wakeup cupboy!\n");
		semaphore_up(cupboy_lk);
	}
}
示例#3
0
void *ping(void *s)
{
    thread_init *p = s;  /* p has the proper type instead of void */
    int i;
    int sleep_time;
    char sync[1] = {'S'};
    unsigned int rand_seed = p->my_seed;

    for (i = 0; i < p->count; i++)
    {
        sleep_time = 1 + (rand_r(&rand_seed) % p->max_sleep);
        printf("%s (Delay %d seconds before & after Pong thread)\n", p->my_call, sleep_time);
        st_sleep(sleep_time);
        BB_put(sync);
        st_sleep(sleep_time);   /* give pong a chance to run */
    }
    quit = true;
    printf("Ping exiting\n");
    BB_put(sync);
    fflush(stdout);
    st_thread_exit(NULL);
}
示例#4
0
文件: Bienstein.c 项目: yonatana/OS
// This function is called by a bartender whenever a student finished to drink his drink
// and wishes to return the cup used (i.e when the type of the action the bartender received from 
// ABB is 2 - returning a dirty cup). 
// If at least 60% of the cups are dirty, the cup boy will be notified.
void return_cup(Cup* cup){
  BB_put(DBB,cup);
}
示例#5
0
文件: Bienstein.c 项目: yonatana/OS
// This function is called by the cup boy when he wishes to add a clean cup he just washed.
void add_clean_cup(Cup* cup){
  BB_put(CBB,cup);
}
示例#6
0
文件: Bienstein.c 项目: yonatana/OS
// This function is called by the bartender whenever he finishes to make a drink (ordered by a student). 
// The cup the drink is made in is placed in the DrinkBB.
void serve_drink(Cup* cup){
  BB_put(DrinkBB,cup);
} 
示例#7
0
文件: Bienstein.c 项目: yonatana/OS
// This function is called by a student whenever he wants to perform an action:
// place an order for a drink from the bar or return a dirty cup. 
// The action is placed at the end of the buffer.
void place_action(Action* action){
  BB_put(ABB,action);
}
示例#8
0
void serve_drink(struct Cup* c)
{
	BB_put(drinkBB, c);
}
示例#9
0
void place_action(struct Action* action)
{
	BB_put(bb, action);
}
示例#10
0
void add_clean_cup(struct Cup* c)
{
	BB_put(cbb, c);
}