int main(void) { vector_init(&sem_list); Qvector_init(&waiting_list); Qvector_free(&waiting_list); vector_free(&sem_list); return 0; }
/*===========================================================================* * main * *===========================================================================*/ int main(int argc, char **argv) { /* This is the main routine of this service. The main loop consists of * three major activities: getting new work, processing the work, and * sending the reply. The loop never terminates, unless a panic occurs. */ message m_in; int result; sef_startup(); vector_init(&sem_list); Qvector_init(&waiting_list); stackInit(&sem_stack,5); /* Main loop - get work and do it, forever. */ while (TRUE) { /* Wait for incoming message, sets 'callnr' and 'who'. */ get_work(&m_in); //printf("SEM recieved message %d\n",callnr); if (is_notify(callnr)) { printf("SEM: warning, got illegal notify from: %d\n", m_in.m_source); result = EINVAL; goto send_reply; } int arg = m_in.m1_i1; switch(callnr) { case SEM_INIT: //printf("Sem_init called, semaphore size 3%d.\n",arg); result = sem_init(arg); break; case SEM_UP: //printf("Sem_up called on semaphore %d.\n",arg); result = sem_up(arg); break; case SEM_DOWN: //printf("Sem_down called on semaphore %d. source: %d\n",arg,who_e); result = sem_down(arg,m_in.m_source); break; case SEM_RELEASE: //printf("Sem_release called on semaphore %d.\n",arg); result = sem_release(arg); break; default: printf("SEMAPHORE: warning, got illegal request from %d\n", m_in.m_source); result = EINVAL; } send_reply: /* Finally send reply message, unless disabled. */ if (result != EDONTREPLY) { m_in.m_type = result; /* build reply message */ reply(who_e, &m_in); /* send it away */ } } Qvector_free(&waiting_list); vector_free(&sem_list); return(OK); /* shouldn't come here */ }