示例#1
0
文件: sync.c 项目: ahimelman/project3
/* TODO: Release lock m and block the thread (enqueued on c).  When unblocked,
   re-acquire m */
void condition_wait(lock_t * m, condition_t * c){
    enter_critical();
    lock_release_helper(m);
    block(&c->wait_queue);
    lock_acquire_helper(m);
    leave_critical();
}
示例#2
0
/* Extra credit */
void do_setpriority(priority_t priority){
  if( priority >= 1 ){
    enter_critical();
    current_running->priority = priority;
    leave_critical();
  }
}
示例#3
0
文件: sync.c 项目: robertsami/COS318
// Return 0 on succes
// Return 1 on failure due to deadlock (extra credit)
int lock_acquire(lock_t * l){
    enter_critical();
    int result = lock_acquire_helper(l);
    leave_critical();

    return result;
}
示例#4
0
文件: sync.c 项目: robertsami/COS318
/* TODO: Block until the semaphore value is greater than zero and decrement it */
void semaphore_down(semaphore_t * s){
  enter_critical();
  while(s->val <= 0)
    block(&s->wait_queue);
  s->val--;
  leave_critical();
}
示例#5
0
/* Unblock the first thread waiting on c, if extant */
void condition_signal(condition_t * c)
{
  enter_critical();
  ASSERT(disable_count);
  unblock_one( &c->wait_queue );
  leave_critical();
}
示例#6
0
pid_t do_getpid(){
  pid_t pid;  
  enter_critical();
  pid = current_running->pid;
  leave_critical();
  return pid;
}
示例#7
0
/* Extra credit */
priority_t do_getpriority(){
  priority_t priority;  
  enter_critical();
  priority = current_running->priority;
  leave_critical();
  return priority;
}
示例#8
0
文件: wav_multi.c 项目: ZigZagJoe/68k
int main() {
 	TIL311 = 0x98;
 	
 	srand();
 	
 	sem_init(&lcd_sem);
	
	lcd_init();
	serial_start(SERIAL_SAFE);
	
	puts("Hello! Starting tasks.\n");
    
    enter_critical();
    
    create_task(&task_time,0);
    create_task(&task_echo,0);
  	create_task(&task_scroller,0);
    create_task(&task_wav_play,0);
    
  /*	for (int i = 0; i < 16; i++)
  		create_task(&breeder_task,0);*/
  		
  	leave_critical();
  	yield();  
  	
  	puts("Tasks started, main() returning.\n");	
  	
	return 0;
}
示例#9
0
/* Unblock all threads waiting on c */
void condition_broadcast(condition_t * c)
{
  enter_critical();
  ASSERT(disable_count);
  unblock_all( &c->wait_queue );
  leave_critical();
}
示例#10
0
/* Call scheduler to run the 'next' process */
void yield(void)
{
  enter_critical();
  current_running->yield_count++;
  scheduler_entry();
  leave_critical();
}
示例#11
0
文件: sync.c 项目: ahimelman/project3
/* TODO: Block until the semaphore value is greater than zero and decrement it */
void semaphore_down(semaphore_t * s){
    enter_critical();
    if (s->value > 0)
        --s->value;
    else
        block(&s->wait_queue);
    leave_critical();      
}
示例#12
0
文件: sync.c 项目: robertsami/COS318
/* TODO: Unblock the first thread waiting on c, if it exists */
void condition_signal(condition_t * c){
	// disable int
  enter_critical();

	// wake up
  unblock_one(&c->blocked);

	// enable int
  leave_critical();
}
示例#13
0
文件: sync.c 项目: robertsami/COS318
/* TODO: Unblock all threads waiting on c */
void condition_broadcast(condition_t * c){
	// disable int
  enter_critical();

  // wake up
  unblock_all(&c->blocked);

  // enable int
  leave_critical();
}
示例#14
0
文件: sync.c 项目: robertsami/COS318
/* TODO: Block until all n threads have called barrier_wait */
void barrier_wait(barrier_t * b){
  enter_critical();
  if(--b->num_left == 0) {
    unblock_all(&b->wait_queue);
    b->num_left = b->num_start;
  }
  else
    block(&b->wait_queue);
  leave_critical();
}
示例#15
0
/* Increment the semaphore value atomically */
void semaphore_up(semaphore_t * s)
{
  enter_critical();

  if(s->value < 1 && !queue_empty(&s->wait_queue))
    unblock_one(&s->wait_queue);
  else
    s->value++;

  leave_critical();
}
示例#16
0
文件: sync.c 项目: ahimelman/project3
/* TODO: Block until all n threads have called barrier_wait */
void barrier_wait(barrier_t * b){
    enter_critical();
    if (++b->curr < b->n) {
        block(&b->wait_queue);
    }
    else { 
        unblock_all(&b->wait_queue);
        b->curr = 0;
    }
    leave_critical();  
}
示例#17
0
/* Block until the semaphore value is greater than zero and decrement it */
void semaphore_down(semaphore_t * s)
{
  enter_critical();

  if( s->value < 1 )
    block( &s->wait_queue );
  else
    s->value--;

  leave_critical();
}
示例#18
0
/* Change current_running to the next task */
void scheduler(){
  ASSERT(disable_count);
  check_sleeping(); // wake up sleeping processes
  while (is_empty(&ready_queue)){     
    leave_critical();
    enter_critical();
    check_sleeping();
  }
  current_running = (pcb_t *) dequeue(&ready_queue);
  ASSERT(NULL != current_running);
  ++current_running->entry_count;
}
示例#19
0
void do_sleep(int milliseconds)
{
  enter_critical();

  current_running->sleep_until = do_gettimeofday() + milliseconds;
  current_running->status = BLOCKED;
  queue_put_sort(
    &sleep_queue,
    (node_t*) current_running,
    &order_by_wake_up);

  scheduler_entry();
  leave_critical();
}
示例#20
0
int my_thread( void *dummy )
{
	int	i, temp;

	for (i = 0; i < maximum; i++) 
		{
		enter_critical();
		temp = counter;
		temp += 1;
		counter = temp;
		leave_critical();
		}
	return	0;
}
示例#21
0
文件: sync.c 项目: robertsami/COS318
/* TODO: Release lock m and block the thread (enqueued on c).  When unblocked,
   re-acquire m */
void condition_wait(lock_t * m, condition_t * c){
	// disable interrupts
  //enter_critical();

	// release lock
  lock_release(m);
  enter_critical();
	// block
  block(&c->blocked);
  leave_critical();
	// acquire lock
  lock_acquire(m);

	// enable interrupts
  //leave_critical();
}
示例#22
0
/* TODO: Blocking sleep. Caution: this function currently cannot be pre-empted! */
void do_sleep(int milliseconds){
  ASSERT( !disable_count );

  enter_critical();
  uint64_t deadline;
  
  deadline = time_elapsed + milliseconds;
  
  current_running->deadline = deadline;
  current_running->status = SLEEPING;

  enqueue_sort(&sleep_wait_queue, (node_t *)current_running, (node_lte)&lte_deadline);

  scheduler_entry();
  leave_critical(); 
}
示例#23
0
/* Block until all n threads have called barrier_wait */
void barrier_wait(barrier_t * b)
{
  enter_critical();

  if( b->size + 1 >= b->quorum )
  {
    b->size = 0;
    unblock_all( &b->wait_queue );
  }
  else
  {
    b->size ++;
    block( &b->wait_queue );
  }

  leave_critical();
}
示例#24
0
/*
 * q is a pointer to the waiting list where current_running should be
 * inserted.
 */
void block(pcb_t ** q, int *spinlock)
{
  pcb_t *tmp;

  enter_critical();

  if (spinlock)
    spinlock_release(spinlock);

  /* mark the job as blocked */
  current_running->status = BLOCKED;

  /* Insert into waiting list */
  tmp = *q;
  (*q) = current_running;
  current_running->next_blocked = tmp;

  /* remove job from ready queue, pick next job to run and dispatch it */
  scheduler_entry();
  leave_critical();
}
示例#25
0
文件: sync.c 项目: robertsami/COS318
void lock_release(lock_t * l){
    enter_critical();
    lock_release_helper(l);
    leave_critical();
}
示例#26
0
文件: sync.c 项目: ahimelman/project3
/* TODO: Unblock the first thread waiting on c, if it exists */
void condition_signal(condition_t * c){
    enter_critical();
    unblock_one(&c->wait_queue);     
    leave_critical();
}
示例#27
0
文件: sync.c 项目: robertsami/COS318
/* TODO: Increment the semaphore value atomically */
void semaphore_up(semaphore_t * s){
  enter_critical();
  if(s->val++ == 0)
    unblock_one(&s->wait_queue);
  leave_critical();
}
示例#28
0
文件: sync.c 项目: ahimelman/project3
/* TODO: Unblock all threads waiting on c */
void condition_broadcast(condition_t * c){
    enter_critical();
    unblock_all(&c->wait_queue);  
    leave_critical();
}
示例#29
0
文件: sync.c 项目: ahimelman/project3
/* TODO: Increment the semaphore value atomically */
void semaphore_up(semaphore_t * s){
    enter_critical();
    if (!unblock_one(&s->wait_queue)) 
        ++s->value;
    leave_critical();  
}
示例#30
0
void do_yield(){
  enter_critical();
  put_current_running();
  scheduler_entry();
  leave_critical();
}