unlinkc2.c

来自「实时嵌入式操作系统内部关于定时器的应用」· C语言 代码 · 共 55 行

C
55
字号
/*
 * timer/unlink_c2.c
 *
 * Copyright (C) SGS-THOMSON Microelectronics Ltd. 1998
 *
 * Unlink a task from a timer.
 */

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "task.h"
#include "os20i.h"

void timer_unlink(tdesc_t* tdesc)
{
  descriptor_t wptr, front, pred;

  /* We don't want to have to merge two queues, so prevent any
   * other tasks running while we look at the queue.
   */
  task_lock();

  __asm {
    ldab 1, 0x80000000;
    swaptimer;
    dup;
    st front;
  }

  for ( wptr = front;
	wptr != (descriptor_t)QUEUE_EMPTY; 
	wptr = (descriptor_t)wptr[PW_TLINK])
  {
    if ((tdesc_t*)wptr[PW_TDESC] == tdesc) {
      /* Found it */
      if (wptr == front) {
	front = (descriptor_t)wptr[PW_TLINK];
      } else {
	pred[PW_TLINK] = wptr[PW_TLINK];
      }
      break; /* Can only be on a timer once */
    }
    pred = wptr;
  }

  __asm {
    ldab 1, front;
    swaptimer;
  }

  task_unlock();
}

⌨️ 快捷键说明

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