Example #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);
}
Example #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);
	}
}
Example #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);
}
Example #4
0
// 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);
}
Example #5
0
// 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);
}
Example #6
0
// 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);
} 
Example #7
0
// 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);
}
Example #8
0
void serve_drink(struct Cup* c)
{
	BB_put(drinkBB, c);
}
Example #9
0
void place_action(struct Action* action)
{
	BB_put(bb, action);
}
Example #10
0
void add_clean_cup(struct Cup* c)
{
	BB_put(cbb, c);
}