예제 #1
0
void main (int argc, char *argv[])
{
  sem_t s_procs_completed; // Semaphore to signal the process that we're done
  sem_t s_N2;          //Semaphore as N2
  int num_N2;          //Number of N2
  int i;              //index var
  if (argc != 4) { 
    Printf("Usage: "); Printf(argv[0]); Printf("  <handle_to_pass_complete_signal><s_procs_completed_str> <s_N2_str> <num_N2_str>\n"); 
    Exit();
  } 

  // Convert the command-line strings into integers for use as handles
  s_procs_completed = dstrtol(argv[1], NULL, 10);
  s_N2 = dstrtol(argv[2],NULL,10);
  num_N2 =dstrtol(argv[3],NULL,10);
  
  for(i=0;i<num_N2;i++){
     Printf("Inject a N2\n");
     sem_signal(s_N2);
  }
  // Signal the semaphore to tell the original process that we're done
 //  Printf("injection_n2 completed!\n");
  if(sem_signal(s_procs_completed) != SYNC_SUCCESS) {
    Printf("Bad semaphore s_procs_completed (%d) in ", s_procs_completed); Printf(argv[0]); Printf(", exiting...\n");
    Exit();
  }
}
예제 #2
0
파일: tim_shmcli.c 프로젝트: rkks/refer
client()
{
	int	i;

	/*
	 * Tell the server we're here and ready,
	 * then just receive while the server sends us things.
	 */

	sem_wait(clisem);		/* get control of shared memory */
	mesgptr->mesg_len = MESGLEN;
	mesgptr->mesg_type = MESGLEN;
	sem_signal(servsem);		/* wake up server */

	for (i = 0; i < NUMMESG; i++) {
		sem_wait(clisem);	/* wait for server */

		if (mesgptr->mesg_len != MESGLEN)
			err_sys("client: incorrect length");
		if (mesgptr->mesg_type != (i + 1))
			err_sys("client: incorrect type");

		sem_signal(servsem);	/* wake up server */
	}
}
예제 #3
0
void main (int argc, char *argv[])
{
  sem_t s_procs_completed; // Semaphore to signal the process that we're done
  sem_t s_N;         //Semaphore N
  sem_t s_O2;          //Semaphore O2
  sem_t s_NO2;        //Semaphore NO2
  int num_N_O2_NO2;       //number of reaction
  int i;             //index var

  if (argc != 6) { 
    Printf("Usage: "); Printf(argv[0]); Printf(" <handle_to_signal_complete><s_H2O> <s_H2> <s_O2>  <num_H2O_H2_O2> \n"); 
    Exit();
  } 

  // Convert the command-line strings into integers for use as handles
  s_procs_completed = dstrtol(argv[1], NULL, 10);
  s_N =dstrtol(argv[2],NULL,10);
  s_O2 =dstrtol(argv[3],NULL,10);
  s_NO2 =dstrtol(argv[4],NULL,10);
  num_N_O2_NO2 = dstrtol(argv[5],NULL,10);

  for(i=0;i<num_N_O2_NO2;i++){
      sem_wait(s_N);
      sem_wait(s_O2);
      Printf("Create a NO2\n");
      sem_signal(s_NO2);
  }
     
//  Printf("reaction3 completed\n");
  if(sem_signal(s_procs_completed) != SYNC_SUCCESS) {
    Printf("Bad semaphore s_procs_completed (%d) in ", s_procs_completed); Printf(argv[0]); Printf(", exiting...\n");
    Exit();
}
}
예제 #4
0
void canarrive(void* daddy) { 
	sem_acquire(&lock);
  numcan++;
	if(numcan == 3 || (numcan > 0 && nummiss == 2)){
	  sem_signal(&can);
		sem_signal(&can);
		printf(1, "\nRow Boat");
		if (nummiss == 3){
		  printf(1, " with 3 missionaries");
			nummiss = 0;
		}
		else if(numcan == 3){
			printf(1, " with 3 cannibals");
			numcan = 0;
		}
		else{
			printf(1, " with 1 cannibal 2 missionaries");
			numcan = numcan - 1;
			nummiss = nummiss -2;
		}

	}
	sem_signal(&lock);
	texit();
}
예제 #5
0
void dominant_monkey_climb()
{
  sem_acquire(&tree);
printf(1,"dominant Monkey %d gets coconut\n", getpid());
sem_signal(&tree);
  sem_signal(&dominant_monkey);
  texit();
}
예제 #6
0
/* Transfer one packet of data from the AICA->SH4 queue. Expects to
   find AICA_CMD_MAX_SIZE dwords of space available. Returns -1
   if failure, 0 for no packets available, 1 otherwise. Failure
   might mean a permanent failure since the queue is probably out of sync. */
int snd_aica_to_sh4(void *packetout) {
	uint32	bot, start, stop, top, size, cnt, *pkt32;

	sem_wait(sem_qram);

	/* Set these up for reference */
	bot = SPU_RAM_BASE + AICA_MEM_RESP_QUEUE;
	assert_msg( g2_read_32(bot + offsetof(aica_queue_t, valid)), "Queue is not yet valid" );

	top = SPU_RAM_BASE + AICA_MEM_RESP_QUEUE + g2_read_32(bot + offsetof(aica_queue_t, size));
	start = SPU_RAM_BASE + AICA_MEM_RESP_QUEUE + g2_read_32(bot + offsetof(aica_queue_t, tail));
	stop = SPU_RAM_BASE + AICA_MEM_RESP_QUEUE + g2_read_32(bot + offsetof(aica_queue_t, head));
	cnt = 0;
	pkt32 = (uint32 *)packetout;

	/* Is there anything? */
	if (start == stop) {
		sem_signal(sem_qram);
		return 0;
	}

	/* Check for packet size overflow */
	size = g2_read_32(start + offsetof(aica_cmd_t, size));
	if (cnt >= AICA_CMD_MAX_SIZE) {
		sem_signal(sem_qram);
		dbglog(DBG_ERROR, "snd_aica_to_sh4(): packet larger than %d dwords\n", AICA_CMD_MAX_SIZE);
		return -1;
	}

	/* Find stop point for this packet */
	stop = start + size*4;
	if (stop > top)
		stop -= top - (SPU_RAM_BASE + AICA_MEM_RESP_QUEUE);
	
	while (start != stop) {
		/* Fifo wait if necessary */
		if (!(cnt % 8))
			g2_fifo_wait();
		cnt++;

		/* Read the next dword */
		*pkt32++ = g2_read_32(start);

		/* Move our counters */
		start += 4;
		if (start >= top)
			start = bot;
		cnt++;
	}

	/* Finally, write a new tail value to signify that we've removed a packet */
	g2_write_32(bot + offsetof(aica_queue_t, tail), start - (SPU_RAM_BASE + AICA_MEM_RESP_QUEUE));

	sem_signal(sem_qram);

	return 1;
}
예제 #7
0
void barber() {
  while(true) {
    sem_wait(customer_waiting);
    sem_wait(seats_mutex);
    free_seats++;
    cut_hair();
    sem_signal(barber_sleeping);
    sem_signal(seats_mutex);
  }
}
예제 #8
0
void oReady(void *arg_ptr) {
	sem_acquire(&h);
	sem_acquire(&h);
	sem_signal(&o);
	sem_signal(&o);
	lock_acquire(&mutex);
	water_molecules++;
	lock_release(&mutex);
	texit();
}
예제 #9
0
파일: fat.c 프로젝트: giuse88/nucleo
BOOL append_fat (VOL_PTR tab , const dword chain, dword * addr) {
  
  fat_ptr fat=NULL; 
  dword cluster_ultimo=0, cluster_new=0;
  
  if(!(tab)) {
    set_errno(EINVAL,"Volume errato (%s-line%d)", __FILE__, __LINE__); 
    return FALSE; 
  }
  
  if(chain <2 ) { 
     set_errno(EINVAL,"Cluster riservato");
    return FALSE; 
  }
  
  fat=tab->fat; 
  
  sem_wait(tab->sem_fat); 
  
    if(!get_ultimo_fat(fat, chain, &cluster_ultimo)) {
      sem_signal(tab->sem_fat); 
      return FALSE; 
    }
    
  if(!getFree_fat(fat, tab->size_fat,&cluster_new)) {
     sem_signal(tab->sem_fat);
    return FALSE; 
  }
  
  //devo scrivere nell'ultimo l'indirizzo del nuovo cluster
    
    if(!scrivi_fat(tab, cluster_ultimo, cluster_new))  {
      sem_signal(tab->sem_fat);
      return FALSE; 
    }
    
  if(!scrivi_fat(tab, cluster_new, EOC_32)) {
    // se fallisce provo a ripristinare la situazione precedente
    if(!scrivi_fat(tab, cluster_ultimo,  EOC_32)) 
      set_errno(EIO,"Errore irrecuperabile, possibile perdita di dati");    
      sem_signal(tab->sem_fat); 
     return FALSE; 
    }
  
  // ... ----->Ultimo---->new(EOC); 
  // finito inserimento 

  sem_signal(tab->sem_fat); 
  
  if(addr)
    *addr=cluster_new; 
  
  return TRUE; 
  
}
예제 #10
0
void main(int argc, char ** argv)
{
    uint32 h_mem;
    sem_t s_procs_completed;

    Molecules * mols;
    int ct;

    if (argc != 3) {
        Printf("Usage: ");
        Printf(argv[0]);
        Printf(" <handle_to_shared_memory_page> <handle_to_page_mapped_semaphore>\n");
        Exit();
    }

    // Convert the command-line strings into integers for use as handles
    h_mem = dstrtol(argv[1], NULL, 10); // The "10" means base 10
    s_procs_completed = dstrtol(argv[2], NULL, 10);

    // Map shared memory page into this process's memory space
    if ((mols = (Molecules *) shmat(h_mem)) == NULL) {
        Printf("Could not map the shared page to virtual address in ");
        Printf(argv[0]);
        Printf(", exiting..\n");
        Exit();
    }

    for(ct = 0; ct < mols->init_so4; ct++) {
        // Consume SO4
        sem_wait(mols->so4);

        // Produce so2
        sem_signal(mols->so2);
        Printf("A molecule SO2 is created\n");

        // Produce O2
        sem_signal(mols->o2);
        Printf("A molecule O2 is created\n");
    }


    // Signal the semaphore to tell the original process that we're done
    Printf("Reaction 2: PID %d is complete.\n", getpid());


    if(sem_signal(s_procs_completed) != SYNC_SUCCESS) {
        Printf("Bad semaphore s_procs_completed (%d) in ", s_procs_completed);
        Printf(argv[0]);
        Printf(", exiting...\n");
        Exit();
    }

    return;
}
예제 #11
0
void CannibalArrives()
{
	sem_aquire(&boat);
	
	sem_aquire(&display);
	printf(1, "1: (%d) cannibal arrived, %d, %d\n", getpid(), total, con);
	sem_signal(&display);	


	sem_aquire(&mutex2);
	while(total + 2 == 5) { con++;
	sem_signal(&mutex2);
	sem_signal(&boat);
	
	sem_aquire(&display);
	printf(1, "1: (%d) cannibal denied boarding, %d, %d\n", getpid(), total, con);
	sem_signal(&display);

	sem_aquire(&prevention);

	sem_aquire(&display);
	printf(1, "1: (%d) cannibal prevented meal, %d, %d\n", getpid(), total, con);
	sem_signal(&display);

	
	sem_aquire(&boat);
	sem_aquire(&mutex2);
	}
	sem_signal(&mutex2);
	sem_aquire(&mutex2);
	total += 2;
	sem_signal(&mutex2);
	
	sem_aquire(&display);
	printf(1, "2: (%d) cannibal enters boat, %d, %d\n", getpid(), total, con);
	sem_signal(&display);	
	
	sem_aquire(&mutex);
	bp++;
	sem_signal(&mutex);
	if (bp < 3)	sem_aquire(&loading);
	
	
	
	// sem_aquire(&display);
	// printf(1, "bp cannibal: %d\n", bp);
	// sem_signal(&display);
	
	RowBoat();
	sem_signal(&loading);

	
	texit();
}
예제 #12
0
static void cb_default(const char *str) {
	cb_sem_data_t *t;

	t = malloc(sizeof(cb_sem_data_t));
	sem_wait(cb_mutex);
	strncpy(t->line, str, 255); t->line[255] = '\0';
	t->next = (cb_sem_data_t *)cb_queue;
	cb_queue = t;
	sem_signal(cb_mutex);

	sem_signal(cb_sem);
}
예제 #13
0
파일: h2o.c 프로젝트: athai005/xv6_lab2
void oReady(void* v)
{
   sem_acquire(&h);
   sem_acquire(&h);
   sem_signal(&o);
   sem_signal(&o);
   sem_acquire(&l);
   water++;
   printf(1,"water molecule created\n");
   sem_signal(&l);

   texit();
}
예제 #14
0
void MissionaryArrives()
{
	sem_aquire(&boat);
	
	sem_aquire(&display);
	printf(1, "1: (%d) missionary arrived, %d, %d\n", getpid(), total, con);
	sem_signal(&display);


	sem_aquire(&mutex2);	
	while(total + 1 == 5){ con++;
	sem_signal(&mutex2);
	sem_signal(&boat);

	sem_aquire(&display);
	printf(1, "1: (%d) missionary denied boarding, %d, %d\n", getpid(), total, con);
	sem_signal(&display);

	sem_aquire(&prevention);

	sem_aquire(&display);
	printf(1, "1: (%d) missionary prevented death, %d, %d\n", getpid(), total, con);
	sem_signal(&display);
	
	sem_aquire(&boat);
	sem_aquire(&mutex2);
	}
	sem_signal(&mutex2);
	sem_aquire(&mutex2);
	total += 1;
	sem_signal(&mutex2);
	
	sem_aquire(&display);
	printf(1, "2: (%d) missionary enters boat, %d, %d\n", getpid(), total, con);
	sem_signal(&display);

	sem_aquire(&mutex);
	bp++;
	sem_signal(&mutex);
	if (bp < 3)	sem_aquire(&loading);

	// sem_aquire(&display);
	// printf(1, "bp missionary: %d\n", bp);
	// sem_signal(&display);
	
	RowBoat();
	sem_signal(&loading);
	
	
	texit();
}
예제 #15
0
void customer() {
  sem_wait(seats_mutex);
  if(free_seats > 0) {
    free_seats--;     
    sem_signal(customer_waiting);
    sem_signal(seats_mutex);
    sem_wait(barber_sleeping);
    get_haircut();
  }
  else {
    sem_signal(seats_mutex);
    leave();
  }
}
예제 #16
0
파일: fat.c 프로젝트: giuse88/nucleo
BOOL delete_fat (VOL_PTR tab, const dword chain) { 
  

  fat_ptr fat=NULL; 
  dword cluster_ultimo=0,cluster_penultimo=0; 
  dword backup=0; 
  
  if(!(tab)) {
    set_errno(EINVAL,"Volume errato (%s-line%d)", __FILE__, __LINE__); 
    return FALSE; 
  }
  
  if(chain < 2) {
    set_errno(1,"Cluster riservati");
    return FALSE; 
  }
    
    
  fat=tab->fat; 
  leggi_fat(fat,cluster_penultimo,&backup);
  
  
  sem_wait(tab->sem_fat); 
  
  if(!get_ultimo_fat(fat, chain, &cluster_ultimo)) {
    sem_signal(tab->sem_fat);
    return FALSE; 
  }
  
  if(!get_penUltimo_fat(fat, chain, &cluster_penultimo)) {
    sem_signal(tab->sem_fat);
    return FALSE;   
  }
  
  if(!scrivi_fat(tab, cluster_penultimo, EOC_32)) 
    return FALSE; 

  
  if(!scrivi_fat(tab, cluster_ultimo, FREE_32)) {
    if(!scrivi_fat(tab, cluster_penultimo,  backup)) 
      set_errno(1,"Errore irrecuperabile, possibile perdita di dati");    
    sem_signal(tab->sem_fat);
    return FALSE; 
  }
  
  sem_signal(tab->sem_fat); 
  
  return TRUE;
 
}
예제 #17
0
void main(int argc, char * argv[])
{
	//Local Variables
	int num = 0, i, j;
	sem_t sem_sulphate, sem_sulphur, sem_oxygen, proc_sem;

	if(argc != 6)
	{
		Printf("Usage: "); Printf(argv[0]); 
	    Exit();
	}

	num = dstrtol(argv[1], NULL, 10);
	sem_sulphate = dstrtol(argv[2], NULL, 10);
	sem_sulphur = dstrtol(argv[3], NULL, 10);
	sem_oxygen = dstrtol(argv[4], NULL, 10);
	proc_sem = dstrtol(argv[5], NULL, 10);

	for(i = 0; i < num; i++)
	{
		if (sem_wait(sem_sulphate) != SYNC_SUCCESS) {
   			Printf("Bad semaphore of sulphate sem wait (%d) in reaction 2", sem_sulphate); Printf(argv[0]); Printf("\n");
    		Exit();
  		}

  		for(j = 0; j < SO2_NUM; j++)
  		{
			if((sem_signal(sem_sulphur))!= SYNC_SUCCESS) {
   			Printf("Bad semaphore for SO2 increment in reaction 2 : (%d) ", getpid()); Printf(argv[0]); Printf(", exiting...\n");
    		Exit();
    		}
    		Printf("Created new sulphur dioxide (S02) molecule\n");
  		}

  		for(j = 0; j < O_NUM; j++)
  		{
			if(sem_signal(sem_oxygen) != SYNC_SUCCESS) {
   			Printf("Bad semaphore for O increment in reaction 2 : (%d) ", getpid()); Printf(argv[0]); Printf(", exiting...\n");
    		Exit();
  			}
    		Printf("Created new oxygen (O2) molecule\n");
  		}
 	}

 	if(sem_signal(proc_sem) != SYNC_SUCCESS) {
    	Printf("Bad semaphore for proc sem increment in reaction  : %d ", getpid()); Printf(argv[0]); Printf(", exiting...\n");
    Exit();
 	}
}
예제 #18
0
void main(int argc, char * argv[])
{
	//Local Variables
	int num = 0, i, j;
	sem_t sem_sulphur, sem_oxygen, sem_hydrogen, sem_acid, proc_sem;

	if(argc != 7)
	{
		Printf("Usage: "); Printf(argv[0]); 
	    Exit();
	}

	num = dstrtol(argv[1], NULL, 10);
	sem_hydrogen = dstrtol(argv[2], NULL, 10);
	sem_oxygen = dstrtol(argv[3], NULL, 10);
	sem_sulphur = dstrtol(argv[4], NULL, 10);
	sem_acid = dstrtol(argv[5], NULL, 10);
  proc_sem = dstrtol(argv[6], NULL, 10);

	for(i = 0; i < num; i++)
	{
		if (sem_wait(sem_hydrogen) != SYNC_SUCCESS) {
   			Printf("Bad semaphore of hydrogen sem wait (%d) in reaction 3", sem_hydrogen); Printf(argv[0]); Printf("\n");
    		Exit();
  		}

		if (sem_wait(sem_oxygen) != SYNC_SUCCESS) {
   			Printf("Bad semaphore of oxygen sem wait (%d) in reaction 3", sem_oxygen); Printf(argv[0]); Printf("\n");
    		Exit();
  		}

		if (sem_wait(sem_sulphur) != SYNC_SUCCESS) {
   			Printf("Bad semaphore of sulphate sem wait (%d) in reaction 3", sem_sulphur); Printf(argv[0]); Printf("\n");
    		Exit();
  		}

		if(sem_signal(sem_acid) != SYNC_SUCCESS) {
 			Printf("Bad semaphore for SO2 increment in reaction 3 : (%d) ", getpid()); Printf(argv[0]); Printf(", exiting...\n");
  		Exit();
  		}

  		Printf("Created new sulphuric acid (H2S04) molecule\n");
 	}

 	if(sem_signal(proc_sem) != SYNC_SUCCESS) {
    	Printf("Bad semaphore for proc sem increment in reaction 3 : %d ", getpid()); Printf(argv[0]); Printf(", exiting...\n");
    Exit();
 	}
}
예제 #19
0
int el_loader_init(void)
{
  PRINTF("entrylist_load_init...\n");

  spinlock_init(&loader_mutex);
  memset(&loader, 0, sizeof(loader));
  loader_status = LOADER_INIT;
  loader_thd = 0;
  PRINTF("entrylist_load_init : create semaphore.\n");
  loader_sem = sem_create(1);
  PRINTF("entrylist_load_init : semaphore [%p].\n",loader_sem);
  if (!loader_sem) {
    printf("entrylist_load_init : can not create semaphore.\n");
    return -1;
  }
  PRINTF("entrylist_load_init : first wait semaphore.\n");
  sem_wait(loader_sem);

  PRINTF("entrylist_load_init : create thread.\n");
  loader_thd = thd_create(THD_DEFAULTS, loader_thread, loader_sem);
  if (!loader_thd) {
    printf("entrylist_load_init : thread failed.\n");
    sem_signal(loader_sem);
    sem_destroy(loader_sem);
    loader_sem = 0;
    printf("entrylist_load_init : can not create loader thread.\n");
    return -1;
  }
  PRINTF("entrylist_load_init : thread created, rename it.\n");
  thd_set_label((kthread_t *)loader_thd, "Loader-thd");
  PRINTF("entrylist_load_init : complete (thd=%p).\n", loader_thd);
  return 0;
}
예제 #20
0
파일: q2_3.c 프로젝트: zhan1182/OS-Design
void main (int argc, char *argv[])
{
  sem_t s_procs_completed; // Semaphore to signal the original process that we're done

  int N = 10000;
  int f_N;

  if (argc != 2) { 
    Printf("Usage: %s <handle_to_procs_completed_semaphore>\n"); 
    Exit();
  } 

  // Convert the command-line strings into integers for use as handles
  s_procs_completed = dstrtol(argv[1], NULL, 10);

  
  f_N = f(N);
  
  Printf("f %d = %d\n", N, f_N);
  
  

  // Signal the semaphore to tell the original process that we're done
  if(sem_signal(s_procs_completed) != SYNC_SUCCESS) {
    Printf("hello_world (%d): Bad semaphore s_procs_completed (%d)!\n", getpid(), s_procs_completed);
    Exit();
  }

  Printf("q2.3 cause the call stack to grow larger than 1 page (%d): Done!\n", getpid());
}
예제 #21
0
파일: producer.c 프로젝트: srwilkers/CStuff
void main(int argc, char*argv[])
{
    int handle;
    atoms *atom;
    sem_t semaphore;

    handle = dstrtol(argv[1], NULL, 10);
    semaphore = dstrtol(argv[2], NULL, 10);

    atom = (atoms *)shmat(handle);
    //sem_wait(semaphore);

    while (1)
    {
        sem_wait(semaphore);
        if (atom->count == MAX)
            exit();
        lock_acquire(atom->lock);
        atom->n_atoms++;
        Printf("N atom created.\n");
        atom->o_atoms++;
        Printf("O atom created.\n");
        atom->count++;
        lock_release(atom->lock);
        sem_signal(semaphore);
    }
    //sem_signal(semaphore);
}
예제 #22
0
void main (int argc, char *argv[])
{
  missile_code mc;         // Used to access missile codes from mailbox
  mbox_t mbox_N;           // Handle to the mbox_N
  mbox_t mbox_O2;
  mbox_t mbox_NO2;
  sem_t s_procs_completed; // Semaphore to signal the original process that we're done

  if (argc != 5) { 
    Printf("Usage: %s <handle_to_mbox_N><handle_to_mbox_O2><handle_to_mbox_NO2> <handle_to_page_mapped_semaphore>\n"); 
    Exit();
  } 

  // Convert the command-line strings into integers for use as handles
  mbox_N = dstrtol(argv[1], NULL, 10); // The "10" means base 10
  mbox_O2 = dstrtol(argv[2],NULL,10);
  mbox_NO2 = dstrtol(argv[3],NULL,10);

  s_procs_completed = dstrtol(argv[4], NULL, 10);

  // Open the mailbox
  if (mbox_open(mbox_N) == MBOX_FAIL) {
    Printf("Could not open the mbox_N!\n");
    Exit();
  }
  if (mbox_open(mbox_O2) == MBOX_FAIL) {
    Printf("Could not open the mbox_N!\n");
    Exit();
  }
  if (mbox_open(mbox_NO2) == MBOX_FAIL) {
    Printf("Could not open the mbox_N!\n");
    Exit();
  }

  // Wait for a message from the mailbox
  if (mbox_recv(mbox_N, sizeof(mc), (void *)&mc) == MBOX_FAIL) {
    Printf("Could not receive message from mbox_N!\n");
    Exit();
  }
  if (mbox_recv(mbox_O2, sizeof(mc), (void *)&mc) == MBOX_FAIL) {
    Printf("Could not receive message from mbox_O2!\n");
    Exit();
  }
  if (mbox_send(mbox_NO2, sizeof(missile_code), (void *)&mc) == MBOX_FAIL) {
    Printf("Could not send message to mbox_NO2!\n");
    Exit();
  }
  else Printf("Got 1 NO2!\n");
 
  // Now print a message to show that everything worked
 // Printf("spawn_me (%d): Received missile code: %c\n", getpid(), mc.really_important_char);

  // Signal the semaphore to tell the original process that we're done
  if(sem_signal(s_procs_completed) != SYNC_SUCCESS) {
    Printf("spawn_me (%d): Bad semaphore s_procs_completed (%d)!\n", getpid(), s_procs_completed);
    Exit();
  }

//  Printf("spawn_me (%d): Done!\n", getpid());
}
예제 #23
0
/* Shutdown the player */
void sndmp3_shutdown() {
	sndmp3_status = STATUS_QUIT;
	sem_signal(sndmp3_halt_sem);
	while (sndmp3_status != STATUS_ZOMBIE)
		thd_pass();
	spu_disable();
}
예제 #24
0
/* Start playback (implies song load) */
int sndmp3_start(const char *fn, int loop) {
	/* Can't start again if already playing */
	if (sndmp3_status == STATUS_PLAYING)
		return -1;

	/* Initialize MP3 engine */
	if (fn) {
		if (libmpg123_init(fn) < 0)
			return -1;
	
		/* Set looping status */
		sndmp3_loop = loop;
	}

	/* Wait for player thread to be ready */
	while (sndmp3_status != STATUS_READY)
		thd_pass();

	/* Tell it to start */
	if (fn)
		sndmp3_status = STATUS_STARTING;
	else
		sndmp3_status = STATUS_REINIT;
	sem_signal(sndmp3_halt_sem);

	return 0;
}
예제 #25
0
void smoker_tobacco(){
	int semid, shmid;
	key_t key;
	struct table *Table;

	if ( (key = ftok("/dev/null", 65)) == (key_t) -1 ) {
		perror("ftok");
		exit(-1);
	}

	if ( (semid = semget(key, 8, 0666))  < 0 ) {
		perror("semget");
		exit(-1);
	}

	if ( (shmid = shmget(key, sizeof(struct table), 0666)) < 0 ) {
		perror("shmid");
		exit(-1);
	}

	Table = shmat(shmid, NULL, 0);

	while(1) {
		sem_wait(semid,TOBACCO_SEM,1);
		printf("Smoker with TOBACCO making cigarrette\n");
		sleep(3);
		sem_signal(semid,AGENT,1);
	}

	shmdt(Table);
	exit(0);
}
예제 #26
0
파일: 2.c 프로젝트: tashanicole56/ECE469
void main (int argc, char *argv[])
{
  sem_t s_procs_completed; // Semaphore to signal the original process that we're done
  int* memory_location; // Somewhere in the middle of 1024KB memory space

  if (argc != 2) { 
    Printf("Usage: %s <handle_to_procs_completed_semaphore>\n"); 
    Exit();
  } 

  // Convert the command-line strings into integers for use as handles
  s_procs_completed = dstrtol(argv[1], NULL, 10);

  // Print test name
  Printf("Test Out of Bounds Virtual Access (%d): Start\n", getpid());

  // Bad practice but signal the original process first
  // Do this because this process is going to die and we don't
  // want the original process to hand
  if(sem_signal(s_procs_completed) != SYNC_SUCCESS) {
    Printf("Out of Bounds Virtual Access (%d): Bad semaphore s_procs_completed (%d)!\n", getpid(), s_procs_completed);
    Exit();
  }

  // Access address in middle of virtual memory
  // Virtual memory is 1024KB so accessing memory
  // location 0x8000000 is somewhere outside of
  // the virtual memory and should seg fault
  memory_location = 0x8000000;
  Printf("Accessing Memory Location: %d (decimal)\n", memory_location);
  *memory_location = 0xDEADBEEF;

  Printf("Test Out of Bounds Virtual Access (%d): Done!\n", getpid());
}
예제 #27
0
void main (int argc, char *argv[])
{
  sem_t s_procs_completed; // Semaphore to signal the original process that we're done
  int program_index;
  int i=0,j=0;             // Loop index variables

  if (argc != 3) { 
    Printf("Usage: %s <program index> <handle_to_page_mapped_semaphore> (argc was %d)\n", argc); 
    Exit();
  } 

  // Convert the command-line strings into integers for use as handles
  program_index = dstrtol(argv[1], NULL, 10);
  s_procs_completed = dstrtol(argv[2], NULL, 10);

  // Now print messages to see if priority scheduling is working
  for(i=0; i<30; i++) {
    Printf("spawn_me (%d): %c%d\n", getpid(), 'A'+program_index, i);
    for(j=0; j<50000; j++);  // just busy-wait awhile
  }

  // Signal the semaphore to tell the original process that we're done
  if(sem_signal(s_procs_completed) != SYNC_SUCCESS) {
    Printf("spawn_me (%d): Bad semaphore s_procs_completed (%d)!\n", getpid(), s_procs_completed);
    Exit();
  }

  Printf("spawn_me (%d): Done!\n", getpid());
}
예제 #28
0
파일: queue.c 프로젝트: DC-SWAT/DreamShell
int QuePut( QUEUE *pQueue, void *pMsg) {
    if( pQueue->qMax != QUE_NO_LIMIT) { /* bounded queue */
#ifdef _WIN32
        WaitForSingleObject( pQueue->qNotFull, INFINITE);
#elif defined(_arch_dreamcast)
		sem_wait(pQueue->qNotFull);
#endif
    }

    OsLockMutex( ( void *) pQueue->qMutex, INFINITE);

    InsertMsgAtQueueTail( pQueue, pMsg);

    OsUnlockMutex( ( void *) pQueue->qMutex);

#ifdef _WIN32
    ReleaseSemaphore( pQueue->qNotEmpty, 1, NULL);
#elif defined(_arch_dreamcast)
	sem_signal(pQueue->qNotEmpty);
#else
    {
        char    b;
        write( pQueue->qNotEmpty[QUEUE_PIPE_OUT], &b, 1);
    }
#endif

    return( 0);
}
예제 #29
0
파일: ssignal.c 프로젝트: maxupunk/DIR685
void press_button(int value_code)
{
	struct input_event event;
	int fd;
	fd=open("/dev/input/event0",O_RDWR);
	if (fd < 0)
	{
       perror("Can't open device...\n");
       sem_signal(g_sem_id);
       exit(1);
    }     	
	event.type = EV_KEY;
    event.code = value_code;
    event.value = 1;    	
    gettimeofday(&event.time,0);
    
    if(write(fd,&event,sizeof(event))==-1)
       	printf("write failed \n");
    fflush(0);
    event.type = EV_KEY;
    event.code = value_code;
    event.value = 0;    	
    gettimeofday(&event.time,0);
    if(write(fd,&event,sizeof(event))==-1)
     	printf("write failed \n");
   	fflush(0);
	close(fd);	
}
예제 #30
0
파일: queue.c 프로젝트: DC-SWAT/DreamShell
int _QueGet( QUEUE *pQueue, void **ppMsg) {
    QMSG    *pQMsg;

    OsLockMutex( ( void *) pQueue->qMutex, INFINITE);

    pQMsg = RemoveMsgFromQueueHead( pQueue);

    OsUnlockMutex( ( void *) pQueue->qMutex);

    if( pQueue->qMax != QUE_NO_LIMIT) {
#ifdef _WIN32
        ReleaseSemaphore( pQueue->qNotFull, 1, NULL);
#elif defined(_arch_dreamcast)
		sem_signal(pQueue->qNotFull);
#endif
    }
#if !defined(_WIN32) && !defined(_arch_dreamcast)
    {
        char    b;
        read( pQueue->qNotEmpty[QUEUE_PIPE_IN], &b, 1);
    }
#endif

    *ppMsg = pQMsg->pMsg;

    free( pQMsg);

    return( 0);
}