当前位置: 首页>>代码示例>>C++>>正文


C++ intr_context函数代码示例

本文整理汇总了C++中intr_context函数的典型用法代码示例。如果您正苦于以下问题:C++ intr_context函数的具体用法?C++ intr_context怎么用?C++ intr_context使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了intr_context函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: lock_acquire

/* Acquires LOCK, sleeping until it becomes available if
   necessary.  The lock must not already be held by the current
   thread.

   This function may sleep, so it must not be called within an
   interrupt handler.  This function may be called with
   interrupts disabled, but interrupts will be turned back on if
   we need to sleep. */
void
lock_acquire (struct lock *lock)
{
  ASSERT (lock != NULL);
  ASSERT (!intr_context ());
  ASSERT (!lock_held_by_current_thread (lock));
  
  enum intr_level old_state = intr_disable();
  // If there is lock holder
  // Add this thread to donorList of lock holder
  if (lock->holder != NULL)
  {
    // Save lock to this thread 
    thread_current()->tLock = lock;
    list_push_back(&lock->holder->donorList,&thread_current()->donorElem);
  }
  intr_set_level(old_state);

  sema_down (&lock->semaphore);
  // This thread is now the holder
  // Not waiting on any lock
  thread_current()->tLock = NULL;
  lock->holder = thread_current ();
  //intr_set_level(old_state);
}
开发者ID:cthan004,项目名称:pintos,代码行数:33,代码来源:synch.c

示例2: lock_acquire

/* Acquires LOCK, sleeping until it becomes available if
   necessary.  The lock must not already be held by the current
   thread.

   This function may sleep, so it must not be called within an
   interrupt handler.  This function may be called with
   interrupts disabled, but interrupts will be turned back on if
   we need to sleep. */
void
lock_acquire (struct lock *lock)
{
  enum intr_level old_level;

  ASSERT (lock != NULL);
  ASSERT (!intr_context ());
  ASSERT (!lock_held_by_current_thread (lock));

  old_level = intr_disable ();

  if (lock->holder != NULL) 
    {
      /* Donate our priority to the thread holding the lock.
         First, update the data structures. */
      struct thread *donor = thread_current ();
      donor->want_lock = lock;
      donor->donee = lock->holder;
      list_push_back (&lock->holder->donors, &donor->donor_elem);
      
      /* Now implement the priority donation itself
         by recomputing the donee's priority
         and cascading the donation as far as necessary. */
      if (donor->donee != NULL)
        thread_recompute_priority (donor->donee);
    }

  sema_down (&lock->semaphore);
  lock->holder = thread_current ();
  intr_set_level (old_level);
}
开发者ID:WofloW,项目名称:OS-326-omega,代码行数:39,代码来源:synch.c

示例3: lock_acquire

/* Acquires LOCK, sleeping until it becomes available if
   necessary.  The lock must not already be held by the current
   thread.

   This function may sleep, so it must not be called within an
   interrupt handler.  This function may be called with
   interrupts disabled, but interrupts will be turned back on if
   we need to sleep. */
void
lock_acquire (struct lock *lock)
{
  ASSERT (lock != NULL);
  ASSERT (!intr_context ());
  ASSERT (!lock_held_by_current_thread (lock));
  
  struct thread* acquirer = thread_current();
  
  if (!thread_mlfqs) {
  
    // P2: add new lock to the lock_list.
    if (!is_thread(lock->holder)) {
      // add lock into locklist.
      bool found = 0;
      int i;
      for (i=0;i<lock_list_cnt; i++)
        if (lock_list[i] == lock) found = 1;
      
      if (found == 0)  { 
        ASSERT (lock_list_cnt < 64);
        lock_list[lock_list_cnt++] = lock;
      }
    }
    lock_sema_down (&lock->semaphore, acquirer);
  } else {
    sema_down (&lock->semaphore);
  }
  // wait for the other to release
  lock->holder = acquirer;
}
开发者ID:nakulj,项目名称:cs-402,代码行数:39,代码来源:synch.c

示例4: sema_down

/* Down or "P" operation on a semaphore.  Waits for SEMA's value
 *   to become positive and then atomically decrements it.
 *
 *   This function may sleep, so it must not be called within an
 *   interrupt handler.  This function may be called with
 *   interrupts disabled, but if it sleeps then the next scheduled
 *   thread will probably turn interrupts back on. */
void sema_down(struct semaphore *sema) {
    enum intr_level old_level;

    ASSERT(sema != NULL);
    ASSERT(!intr_context());

    old_level = intr_disable ();

    while(sema -> value == 0) {
        /*
         * 注释掉原有代码
         * list_push_back(&sema->waiters, &thread_current ()->elem);
         */

        /* 按照降序插入 */
        list_insert_ordered(
                &sema -> waiters,
                &thread_current() -> elem,
                (list_less_func *) &priority_cmp_max_to_low,
                NULL
        );
        /* 阻塞当前线程 */
        thread_block();
    }

    sema -> value--;

    intr_set_level(old_level);
}
开发者ID:ITSophia,项目名称:Pintos,代码行数:36,代码来源:synch.c

示例5: console_locked_by_current_thread

/* Returns true if the current thread has the console lock,
   false otherwise. */
static bool
console_locked_by_current_thread (void) 
{
  return (intr_context ()
          || !use_console_lock
          || lock_held_by_current_thread (&console_lock));
}
开发者ID:jwanglof,项目名称:TDIU16,代码行数:9,代码来源:console.c

示例6: lock_acquire

/* 
 --------------------------------------------------------------------
 Acquires LOCK, sleeping until it becomes available if
   necessary.  The lock must not already be held by the current
   thread.

   This function may sleep, so it must not be called within an
   interrupt handler.  This function may be called with
   interrupts disabled, but interrupts will be turned back on if
   we need to sleep. 
 NOTE: if we cannot aquire the lock and we are in regular priority
    donation scheduling, then we invoke the call to donate our
    priority. Once we move past the semaphore, we have aquired the 
    lock, and thus add it to our list of locks_held, so that this
    thread can properly recieve priortity donations. 
 --------------------------------------------------------------------
 */
void
lock_acquire (struct lock *lock)
{
    ASSERT (lock != NULL);
    ASSERT (!intr_context ());
    ASSERT (!lock_held_by_current_thread (lock));
    
    enum intr_level old_level = intr_disable();
    
    if (!thread_mlfqs) { 
        if (lock->holder != NULL) {
            thread_current()->lock_waiting_on = lock;
            //donate_priority();
        }
    }
    
    sema_down (&lock->semaphore);
    
    if (!thread_mlfqs) {
        lock->priority = PRI_MIN;
        list_push_front(&(thread_current()->locks_held), &(lock->elem));
        thread_current()->lock_waiting_on = NULL;
    }
    lock->holder = thread_current ();
    
    intr_set_level(old_level);
}
开发者ID:naftaliharris,项目名称:cs140,代码行数:44,代码来源:synch.c

示例7: lock_acquire

/* Acquires LOCK, sleeping until it becomes available if
   necessary.  The lock must not already be held by the current
   thread.

   This function may sleep, so it must not be called within an
   interrupt handler.  This function may be called with
   interrupts disabled, but interrupts will be turned back on if
   we need to sleep. */
void
lock_acquire (struct lock *lock)
{
  ASSERT (lock != NULL);
  ASSERT (!intr_context ());
  ASSERT (!lock_held_by_current_thread (lock));
	
	struct thread *holder= lock->holder;
	
	/* If the current lock is already locked, then we update the mx_priority, by comparing it
	 * with the current_thread.
	 * We check if the thread holding the lock has less priority than the current priority so it
	 * donates it priority, then we add the current lock to the list of the thread of the donating_locks. */
	if(holder != NULL){
		if(lock->mx_priority < thread_current()->priority){
			lock->mx_priority= thread_current()->priority;
		}
		
		if(thread_current()->priority > holder->priority){
			if(!list_exist(&holder->donating_locks, &lock->elem)){
				list_push_back(&holder->donating_locks, &lock->elem);
			}
			holder->priority= thread_current()->priority;
		}
		
		thread_current()->blocked=lock;
		nest_donation(holder);
	}
	else{
		list_push_back(&thread_current()->donating_locks, &lock->elem);
	}
	
  sema_down (&lock->semaphore);
  lock->holder = thread_current();
}
开发者ID:reviforks,项目名称:pintos,代码行数:43,代码来源:synch.c

示例8: sema_up

/* Up or "V" operation on a semaphore.  Increments SEMA's value
   and wakes up one thread of those waiting for SEMA, if any.

   This function may be called from an interrupt handler.
   Within an interrupt context, sema_up () always returns. */
void
sema_up (struct semaphore *sema) 
{
  enum intr_level old_level;
  bool yield = false;

  ASSERT (sema != NULL);

  old_level = intr_disable ();
  if (!list_empty (&sema->waiters)) 
  {
    struct thread *t = list_entry (list_pop_front (&sema->waiters),
                        struct thread, elem);
    thread_unblock (t);

    /* Yield to the newly unblocked thread if it has higher priority. */
    if (t->priority > thread_current ()->priority)
      yield = true;
  }
  sema->value++;
  intr_set_level (old_level);

  if (yield)
  {
    if (!intr_context ())
      thread_yield ();
    else
      intr_yield_on_return ();
  }
}
开发者ID:Hindol,项目名称:pintos,代码行数:35,代码来源:synch.c

示例9: lock_acquire

/* Acquires LOCK, sleeping until it becomes available if
   necessary.  The lock must not already be held by the current
   thread.

   This function may sleep, so it must not be called within an
   interrupt handler.  This function may be called with
   interrupts disabled, but interrupts will be turned back on if
   we need to sleep. */
void
lock_acquire (struct lock *lock)
{
  ASSERT (lock != NULL);
  ASSERT (!intr_context ());
  ASSERT (!lock_held_by_current_thread (lock));

  enum intr_level old_level = intr_disable ();

  if (lock->holder != NULL) /* If the lock is being held. */
  {
    /* Updates current thread's lock_to_acquire attribute,
       adds itself to the lock holder's donors list and
       donates priority. */
    thread_current ()->lock_to_acquire = lock;
    list_push_front (&lock->holder->priority_donors,
                     &thread_current ()->donor);
    priority_donation ();
  }

  sema_down (&lock->semaphore);

  /* The lock has been acquired: current thread is not waiting
     for it anymore. */
  thread_current ()->lock_to_acquire = NULL;
  lock->holder = thread_current ();

  intr_set_level (old_level);
}
开发者ID:xArchange,项目名称:pintos-1,代码行数:37,代码来源:synch.c

示例10: lock_acquire

/* Acquires LOCK, sleeping until it becomes available if
   necessary.  The lock must not already be held by the current
   thread.

   This function may sleep, so it must not be called within an
   interrupt handler.  This function may be called with
   interrupts disabled, but interrupts will be turned back on if
   we need to sleep. */
void
lock_acquire (struct lock *lock)
{
  ASSERT (lock != NULL);
  ASSERT (!intr_context ());
  ASSERT (!lock_held_by_current_thread (lock));
  
  struct thread *cur_thread = thread_current ();

  /* If we are not in the multi-level feedback queue scheduler
     then use priority donation */
  if(!thread_mlfqs)
  {
    /* donate priority if someone holds the lock we want */
    enum intr_level old_level = intr_disable ();
     
    if (lock->holder != NULL) {
      cur_thread->lock_waiting_for = lock;
      cur_thread->t_donating_to = lock->holder;
      thread_donate_priority(cur_thread);
    }
    intr_set_level (old_level);
  }  

  sema_down (&lock->semaphore);
  lock->holder = cur_thread;
}
开发者ID:raunk,项目名称:cs140,代码行数:35,代码来源:synch.c

示例11: sema_up

/* Up or "V" operation on a semaphore.  Increments SEMA's value
   and wakes up one thread of those waiting for SEMA, if any.

   This function may be called from an interrupt handler. */
void
sema_up (struct semaphore *sema) 
{
  enum intr_level old_level;

  ASSERT (sema != NULL);

  old_level = intr_disable ();
  sema->value++;
  if (!list_empty (&sema->waiters)) 
    {
      /* Find highest-priority waiting thread. */
      struct thread *max = list_entry (list_max (&sema->waiters,
                                                 thread_lower_priority, NULL),
                                       struct thread, elem);

      /* Remove `max' from wait list and unblock. */
      list_remove (&max->elem);
      thread_unblock (max);

      /* Yield to a higher-priority thread, if we're running in a
         context where it makes sense to do so.
         
         Kind of a funny interaction with donation here.
         We only support donation for locks, and locks turn off
         interrupts before calling us, so we automatically don't
         do the yield here, delegating to lock_release(). */
      if (!intr_context () && old_level == INTR_ON)
        thread_yield_to_higher_priority ();
    }
  intr_set_level (old_level);
}
开发者ID:WofloW,项目名称:OS-326-omega,代码行数:36,代码来源:synch.c

示例12: lock_acquire

/* Acquires LOCK, sleeping until it becomes available if
   necessary.  The lock must not already be held by the current
   thread.

   This function may sleep, so it must not be called within an
   interrupt handler.  This function may be called with
   interrupts disabled, but interrupts will be turned back on if
   we need to sleep. */
void
lock_acquire (struct lock *lock)
{
  ASSERT (lock != NULL);
  ASSERT (!intr_context ());
  ASSERT (!lock_held_by_current_thread (lock));
  ASSERT (thread_current ()->waiting_on == NULL);

  enum intr_level old_level;
  old_level = intr_disable ();
  
  /* If the lock is currently held by someone, then we need to invoke
     thread_donate_priority to donate our priority to that special
     someone. */  
  if (!thread_mlfqs && lock->holder != NULL)
    {
      thread_current ()->waiting_on = lock;
      thread_donate_priority (thread_current ());
    }

  sema_down (&lock->semaphore);

  lock->holder = thread_current ();
  thread_current ()->waiting_on = NULL;

  intr_set_level (old_level);
}
开发者ID:CSthrowaway,项目名称:cs140-w2012-stevejosh,代码行数:35,代码来源:synch.c

示例13: lock_acquire

/* Acquires LOCK, sleeping until it becomes available if
   necessary.  The lock must not already be held by the current
   thread.

   This function may sleep, so it must not be called within an
   interrupt handler.  This function may be called with
   interrupts disabled, but interrupts will be turned back on if
   we need to sleep. */
void
lock_acquire (struct lock *lock)
{
  ASSERT (lock != NULL);
  ASSERT (!intr_context ());
  ASSERT (!lock_held_by_current_thread (lock));

  /* If the lock is not being held, just grap the lock. */
  if (lock->holder == NULL)
  {
    sema_down (&lock->semaphore);
    lock->holder = thread_current ();
  }
  /* If the lock is being held and donation is needed (priority is higher than the lock holder), 
  apply donation, set the lock holder as waiting thread and reverse donation afterwards. */
  else if (thread_current ()->priority > lock->holder->original_priority)
  {
    thread_current ()->thread_waiting_for = lock->holder;
    apply_donation (thread_current ());
    sema_down (&lock->semaphore);
    lock->holder = thread_current ();
    recover_priority (thread_current ()->thread_waiting_for);
  }
  /* If the lock is being held and donation is not needed (priority is lower than the lock holder), 
  just set the lock holder as waiting thread for possible chain donation and reverse possible chain donation afterwards */
  else
  {
    thread_current ()->thread_waiting_for = lock->holder;
    sema_down (&lock->semaphore);
    lock->holder = thread_current ();
  }
}
开发者ID:atlus7,项目名称:pintos,代码行数:40,代码来源:synch.c

示例14: sema_up

/* Up or "V" operation on a semaphore.  Increments SEMA's value
   and wakes up one thread of those waiting for SEMA, if any.

   This function may be called from an interrupt handler. 

   The thread with the highest priority in the waiting list gets added
   to the ready_list. If it has a higher priority than the    
   running thread, then the running thread will be preempted. */
void
sema_up (struct semaphore *sema) 
{
  enum intr_level old_level;

  ASSERT (sema != NULL);

  old_level = intr_disable ();
  struct thread *t = NULL;

  if (!list_empty (&sema->waiters)) 
  {
    struct list_elem *next = list_max(&sema->waiters, list_comp_greater, 0);
    list_remove(next);
    t = list_entry (next, struct thread, elem);
    thread_unblock (t);
  }
   
  sema->value++;
  if(t != NULL && !intr_context()) 
  {
    check_preempt(t, false);
  }
  intr_set_level (old_level);
}
开发者ID:mrathbun,项目名称:PintosProject,代码行数:33,代码来源:synch.c

示例15: sema_down

/* Down or "P" operation on a semaphore.  Waits for SEMA's value
 *  to become positive and then atomically decrements it.
 *
 *  This function may sleep, so it must not be called within an
 *  interrupt handler.  This function may be called with
 *  interrupts disabled, but if it sleeps then the next scheduled
 *  thread will probably turn interrupts back on. */
void sema_down(struct semaphore *sema) {
    enum intr_level old_level;

    ASSERT(sema != NULL);
    ASSERT(!intr_context());

    old_level = intr_disable();
    while (sema -> value == 0) {
        /*
         * 注释掉原有的代码
         * list_push_back(&sema -> waiters, &thread_current() -> elem);
         * thread_block();
         */

        if (!thread_mlfqs) {
            donate_priority();
        }

        list_insert_ordered(
                &sema -> waiters,
                &thread_current() -> elem,
                (list_less_func *) &cmp_priority,
                NULL
        );
        thread_block();
    }

    sema -> value--;
    intr_set_level(old_level);
}
开发者ID:ITSophia,项目名称:Pintos,代码行数:37,代码来源:synch.c


注:本文中的intr_context函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。