⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mutex.lst

📁 嵌入式系统内核模拟器
💻 LST
📖 第 1 页 / 共 2 页
字号:
                          mut->owner = _tasks[current].prio.normal;
                          __nprio_lock(current);
              
                          if (current == mut->owner) {
                              /*change owner-priority to ceiling-priority*/
                              __memcpy(&_tasks[ceiling], &_tasks[current], sizeof(task_t));
                              _tasks[current].state = (STATE_ZOMBIE|STATE_RESERVED);
                              _tasks[current].prio.current = ceiling;
                              __ready_que_remove(current);
                              __ready_que_add(ceiling);
                              _current_prio = ceiling;
                          }
                          CRITICAL_EXIT;
                          return EOK;
              #if CFG_ARG_CHK > 0
                      /*prevent a task waiting the same mutex again.*/
                      } else if (mut->owner == _tasks[current].prio.normal) {
                          CRITICAL_EXIT;
                          return EAGAIN;
              #endif
C51 COMPILER V6.12  MUTEX                                                                  12/07/2004 17:58:46 PAGE 5   

                      }
                      __ipc_block(&mut->waits, 0);
                      CRITICAL_EXIT;
              
                      __schedule();
                  }
              }
              
              #if CFG_IPC_TIMEOUT_EN > 0
              err_t mutex_timewait(mutex_t __p_* mut, tick_t ticks)
              {
                  register u8 current;
                  register u8 ceiling;
              
                  __ASSERT(mut != NULL);
              
              #if CFG_ARG_CHK > 0
                  if (_sched_lock > 0) {
                      return ELOCK;
                  }
              #else
                  __ASSERT(_sched_lock == 0);
              #endif
              
                  while (true) {
                      CRITICAL_ENTER;
                      current = _current_prio;
                      ceiling = mut->ceiling;
                      
                      if (mut->owner == NULL_PRIO) {
                          mut->owner = _tasks[current].prio.normal;
                          __nprio_lock(current);
              
                          if (current == mut->owner) {
                              /*change owner-priority to ceiling-priority*/
                              __memcpy(&_tasks[ceiling], &_tasks[current], sizeof(task_t));
                              _tasks[current].state = (STATE_ZOMBIE|STATE_RESERVED);
                              _tasks[current].prio.current = ceiling;
                              __ready_que_remove(current);
                              __ready_que_add(ceiling);
                              _current_prio = ceiling;
                          }
                          CRITICAL_EXIT;
                          return EOK;
              #if CFG_ARG_CHK > 0
                      /*prevent a task waiting the same mutex again.*/
                      } else if (mut->owner == _tasks[current].prio.normal) {
                          CRITICAL_EXIT;
                          return EAGAIN;
              #endif
                      }
                      __ipc_block(&mut->waits, ticks);
                      CRITICAL_EXIT;
              
                      __schedule();
              
                      CRITICAL_ENTER;
                      current = _current_prio;
                      if (_tasks[current].state & STATE_BLOCKED) {
                          __ipc_timeout(&mut->waits);
                          CRITICAL_EXIT;
                          return ETIMEOUT;
C51 COMPILER V6.12  MUTEX                                                                  12/07/2004 17:58:46 PAGE 6   

                      }
                      __adjust_delay(current, ticks);
                      CRITICAL_EXIT;
                  }
              }
              #endif
              
              err_t mutex_trywait(mutex_t __p_* mut)
              {
                  register u8 current;
                  register u8 ceiling;
              
                  __ASSERT(mut != NULL);
              
              #if CFG_ARG_CHK > 0
                  if (_sched_lock > 0) {
                      return ELOCK;
                  }
              #else
                  __ASSERT(_sched_lock == 0);
              #endif
              
                  CRITICAL_ENTER;
                  current = _current_prio;
                  ceiling = mut->ceiling;
                      
                  if (mut->owner == NULL_PRIO) {
                      mut->owner = _tasks[current].prio.normal;
                      __nprio_lock(current);
              
                      if (current == mut->owner) {
                          /*change owner-priority to ceiling-priority*/
                          __memcpy(&_tasks[ceiling], &_tasks[current], sizeof(task_t));
                          _tasks[current].state = (STATE_ZOMBIE|STATE_RESERVED);
                          _tasks[current].prio.current = ceiling;
                          __ready_que_remove(current);
                          __ready_que_add(ceiling);
                          _current_prio = ceiling;
                      }
                      CRITICAL_EXIT;
                      return EOK;    
                  }
                  CRITICAL_EXIT;
                  return ENAVAIL;
              }
              #endif
              
              err_t mutex_release(mutex_t __p_* mut)
              {
                  register u8 current;
                  register u8 owner;
              
                  __ASSERT(mut != NULL);
              
              #if CFG_ARG_CHK > 0
                  if (_sched_lock > 0) {
                      return ELOCK;
                  }
              #else
                  __ASSERT(_sched_lock == 0);
              #endif
              
C51 COMPILER V6.12  MUTEX                                                                  12/07/2004 17:58:46 PAGE 7   

                  CRITICAL_ENTER;
                  current = _current_prio;
                  owner   = mut->owner;
              
                  __nprio_unlock(current);
                  
                  if (current == mut->ceiling) {
                      /*change current-priority to owner-priority*/
                      __memcpy(&_tasks[owner], &_tasks[current], sizeof(task_t));
                      _tasks[current].state  = STATE_ZOMBIE;
                      __ready_que_remove(current);
                      __ready_que_add(owner);
                      /*!!! the current priority has been changed already:)*/
                      _current_prio = owner;
              #if CFG_ARG_CHK > 0
                  } else if (owner != _tasks[current].prio.normal) {
                      __nprio_lock(current); /*!!!we have been unlock it above*/
                      CRITICAL_EXIT;
                      return EINVAL;
              #endif
                  }
              
                  mut->owner = NULL_PRIO;
                  __ipc_resume(&mut->waits);
                  CRITICAL_EXIT;
              
                  __schedule();
                  return EOK;
              }
              
              u8 mutex_getowner(mutex_t __p_* mut)
              {
                  register u8 val;
              
                  __ASSERT(mut != NULL);
              
                  CRITICAL_ENTER;
                  val = mut->owner;
                  CRITICAL_EXIT;
                  return val;
              }
              
              u8 mutex_getprio(mutex_t __p_* mut)
              {
                  register u8 val;
              
                  __ASSERT(mut != NULL);
              
                  CRITICAL_ENTER;
                  val = mut->ceiling;
                  CRITICAL_EXIT;
                  return val;
              }
              
              err_t mutex_destroy(mutex_t __p_* mut)
              {
                  __ASSERT(mut != NULL);
              
                  if (mut->owner != NULL_PRIO) {
                      return EEXIST;
                  }
                  _tasks[mut->ceiling].state = STATE_NONE;
C51 COMPILER V6.12  MUTEX                                                                  12/07/2004 17:58:46 PAGE 8   

                  return EOK;
              }
              #endif
 430          
 431          /*===========================================================================*/
 432          
 433          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   ----    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -