亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? sys.c

?? lm3s下lwip的udp
?? C
字號:
/**
 * @file
 * lwIP Operating System abstraction
 *
 */

/*
 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 * OF SUCH DAMAGE.
 *
 * This file is part of the lwIP TCP/IP stack.
 *
 * Author: Adam Dunkels <adam@sics.se>
 *
 */

#include "lwip/opt.h"

#if (NO_SYS == 0) /* don't build if not configured for use in lwipopts.h */

#include "lwip/sys.h"
#include "lwip/def.h"
#include "lwip/memp.h"
#include "lwip/tcpip.h"

/**
 * Struct used for sys_sem_wait_timeout() to tell wether the time
 * has run out or the semaphore has really become available.
 */
struct sswt_cb
{
  s16_t timeflag;
  sys_sem_t *psem;
};

/**
 * Wait (forever) for a message to arrive in an mbox.
 * While waiting, timeouts (for this thread) are processed.
 *
 * @param mbox the mbox to fetch the message from
 * @param msg the place to store the message
 */
void
sys_mbox_fetch(sys_mbox_t mbox, void **msg)
{
  u32_t time;
  struct sys_timeouts *timeouts;
  struct sys_timeo *tmptimeout;
  sys_timeout_handler h;
  void *arg;

 again:
  timeouts = sys_arch_timeouts();

  if (!timeouts || !timeouts->next) {
    UNLOCK_TCPIP_CORE();
    time = sys_arch_mbox_fetch(mbox, msg, 0);
    LOCK_TCPIP_CORE();
  } else {
    if (timeouts->next->time > 0) {
      UNLOCK_TCPIP_CORE();
      time = sys_arch_mbox_fetch(mbox, msg, timeouts->next->time);
      LOCK_TCPIP_CORE();
    } else {
      time = SYS_ARCH_TIMEOUT;
    }

    if (time == SYS_ARCH_TIMEOUT) {
      /* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
         could be fetched. We should now call the timeout handler and
         deallocate the memory allocated for the timeout. */
      tmptimeout = timeouts->next;
      timeouts->next = tmptimeout->next;
      h   = tmptimeout->h;
      arg = tmptimeout->arg;
      memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
      if (h != NULL) {
        LWIP_DEBUGF(SYS_DEBUG, ("smf calling h=%p(%p)\n", (void*)&h, arg));
        h(arg);
      }

      /* We try again to fetch a message from the mbox. */
      goto again;
    } else {
      /* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
         occured. The time variable is set to the number of
         milliseconds we waited for the message. */
      if (time < timeouts->next->time) {
        timeouts->next->time -= time;
      } else {
        timeouts->next->time = 0;
      }
    }
  }
}

/**
 * Wait (forever) for a semaphore to become available.
 * While waiting, timeouts (for this thread) are processed.
 *
 * @param sem semaphore to wait for
 */
void
sys_sem_wait(sys_sem_t sem)
{
  u32_t time;
  struct sys_timeouts *timeouts;
  struct sys_timeo *tmptimeout;
  sys_timeout_handler h;
  void *arg;

 again:

  timeouts = sys_arch_timeouts();

  if (!timeouts || !timeouts->next) {
    sys_arch_sem_wait(sem, 0);
  } else {
    if (timeouts->next->time > 0) {
      time = sys_arch_sem_wait(sem, timeouts->next->time);
    } else {
      time = SYS_ARCH_TIMEOUT;
    }

    if (time == SYS_ARCH_TIMEOUT) {
      /* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
        could be fetched. We should now call the timeout handler and
        deallocate the memory allocated for the timeout. */
      tmptimeout = timeouts->next;
      timeouts->next = tmptimeout->next;
      h = tmptimeout->h;
      arg = tmptimeout->arg;
      memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
      if (h != NULL) {
        LWIP_DEBUGF(SYS_DEBUG, ("ssw h=%p(%p)\n", (void*)&h, (void *)arg));
        h(arg);
      }

      /* We try again to fetch a message from the mbox. */
      goto again;
    } else {
      /* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
         occured. The time variable is set to the number of
         milliseconds we waited for the message. */
      if (time < timeouts->next->time) {
        timeouts->next->time -= time;
      } else {
        timeouts->next->time = 0;
      }
    }
  }
}

/**
 * Create a one-shot timer (aka timeout). Timeouts are processed in the
 * following cases:
 * - while waiting for a message using sys_mbox_fetch()
 * - while waiting for a semaphore using sys_sem_wait() or sys_sem_wait_timeout()
 * - while sleeping using the inbuilt sys_msleep()
 *
 * @param msecs time in milliseconds after that the timer should expire
 * @param h callback function to call when msecs have elapsed
 * @param arg argument to pass to the callback function
 */
void
sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg)
{
  struct sys_timeouts *timeouts;
  struct sys_timeo *timeout, *t;

  timeout = memp_malloc(MEMP_SYS_TIMEOUT);
  if (timeout == NULL) {
    LWIP_ASSERT("sys_timeout: timeout != NULL", timeout != NULL);
    return;
  }
  timeout->next = NULL;
  timeout->h = h;
  timeout->arg = arg;
  timeout->time = msecs;

  timeouts = sys_arch_timeouts();

  LWIP_DEBUGF(SYS_DEBUG, ("sys_timeout: %p msecs=%"U32_F" h=%p arg=%p\n",
    (void *)timeout, msecs, (void*)&h, (void *)arg));

  if (timeouts == NULL) {
    LWIP_ASSERT("sys_timeout: timeouts != NULL", timeouts != NULL);
    return;
  }

  if (timeouts->next == NULL) {
    timeouts->next = timeout;
    return;
  }

  if (timeouts->next->time > msecs) {
    timeouts->next->time -= msecs;
    timeout->next = timeouts->next;
    timeouts->next = timeout;
  } else {
    for(t = timeouts->next; t != NULL; t = t->next) {
      timeout->time -= t->time;
      if (t->next == NULL || t->next->time > timeout->time) {
        if (t->next != NULL) {
          t->next->time -= timeout->time;
        }
        timeout->next = t->next;
        t->next = timeout;
        break;
      }
    }
  }
}

/**
 * Go through timeout list (for this task only) and remove the first matching
 * entry, even though the timeout has not triggered yet.
 *
 * @note This function only works as expected if there is only one timeout
 * calling 'h' in the list of timeouts.
 *
 * @param h callback function that would be called by the timeout
 * @param arg callback argument that would be passed to h
*/
void
sys_untimeout(sys_timeout_handler h, void *arg)
{
  struct sys_timeouts *timeouts;
  struct sys_timeo *prev_t, *t;

  timeouts = sys_arch_timeouts();

  if (timeouts == NULL) {
    LWIP_ASSERT("sys_untimeout: timeouts != NULL", timeouts != NULL);
    return;
  }
  if (timeouts->next == NULL) {
    return;
  }

  for (t = timeouts->next, prev_t = NULL; t != NULL; prev_t = t, t = t->next) {
    if ((t->h == h) && (t->arg == arg)) {
      /* We have a match */
      /* Unlink from previous in list */
      if (prev_t == NULL)
        timeouts->next = t->next;
      else
        prev_t->next = t->next;
      /* If not the last one, add time of this one back to next */
      if (t->next != NULL)
        t->next->time += t->time;
      memp_free(MEMP_SYS_TIMEOUT, t);
      return;
    }
  }
  return;
}

/**
 * Timeout handler function for sys_sem_wait_timeout()
 *
 * @param arg struct sswt_cb* used to signal a semaphore and end waiting.
 */
static void
sswt_handler(void *arg)
{
  struct sswt_cb *sswt_cb = (struct sswt_cb *) arg;

  /* Timeout. Set flag to TRUE and signal semaphore */
  sswt_cb->timeflag = 1;
  sys_sem_signal(*(sswt_cb->psem));
}

/**
 * Wait for a semaphore with timeout (specified in ms)
 *
 * @param sem semaphore to wait
 * @param timeout timeout in ms (0: wait forever)
 * @return 0 on timeout, 1 otherwise
 */
int
sys_sem_wait_timeout(sys_sem_t sem, u32_t timeout)
{
  struct sswt_cb sswt_cb;

  sswt_cb.psem = &sem;
  sswt_cb.timeflag = 0;

  /* If timeout is zero, then just wait forever */
  if (timeout > 0) {
    /* Create a timer and pass it the address of our flag */
    sys_timeout(timeout, sswt_handler, &sswt_cb);
  }
  sys_sem_wait(sem);
  /* Was it a timeout? */
  if (sswt_cb.timeflag) {
    /* timeout */
    return 0;
  } else {
    /* Not a timeout. Remove timeout entry */
    sys_untimeout(sswt_handler, &sswt_cb);
    return 1;
  }
}

/**
 * Sleep for some ms. Timeouts are processed while sleeping.
 *
 * @param ms number of milliseconds to sleep
 */
void
sys_msleep(u32_t ms)
{
  sys_sem_t delaysem = sys_sem_new(0);

  sys_sem_wait_timeout(delaysem, ms);

  sys_sem_free(delaysem);
}


#endif /* NO_SYS */

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品免费播放| 成人的网站免费观看| 亚洲男人的天堂在线aⅴ视频| 精品国产免费人成在线观看| 日韩欧美亚洲国产另类| 欧美一级在线免费| 精品蜜桃在线看| 久久精品视频一区| 久久亚洲综合av| 久久精品一区二区三区四区| 中文字幕在线观看一区二区| 欧美亚洲国产一区二区三区| 一本色道久久综合狠狠躁的推荐 | 国产成a人亚洲精品| 国模套图日韩精品一区二区| 国产一区二区电影| 不卡大黄网站免费看| 91啪九色porn原创视频在线观看| 色婷婷综合久久久中文一区二区| 欧美特级限制片免费在线观看| 欧美喷潮久久久xxxxx| 26uuuu精品一区二区| 久久奇米777| 亚洲精品久久7777| 麻豆极品一区二区三区| 成人短视频下载| 国产亚洲一区二区三区| 国产精品视频一区二区三区不卡| 国产精品美女www爽爽爽| 亚洲精品国产无天堂网2021| 日韩在线观看一区二区| 国产精品影视网| 欧美在线|欧美| 久久老女人爱爱| 亚洲高清免费观看| 国产成人夜色高潮福利影视| 欧美色成人综合| 中文乱码免费一区二区| 日韩成人午夜电影| 99国产欧美另类久久久精品| 在线播放国产精品二区一二区四区 | 91视频精品在这里| 欧美成人免费网站| 亚洲第一主播视频| jlzzjlzz亚洲日本少妇| 51久久夜色精品国产麻豆| 国产精品乱码人人做人人爱 | 欧美高清dvd| 亚洲欧洲国产日韩| 国产精品99久久久久久有的能看| 欧美日韩黄色影视| 国产精品高清亚洲| 国产一区二区三区电影在线观看| 欧美巨大另类极品videosbest| 17c精品麻豆一区二区免费| 久久99国产乱子伦精品免费| 成人小视频免费观看| 精品噜噜噜噜久久久久久久久试看| 亚洲国产精品99久久久久久久久 | 蜜桃av一区二区| 欧美亚洲一区二区在线| 欧美国产成人精品| 美女精品一区二区| 91精品国产免费| 夜夜爽夜夜爽精品视频| 91色九色蝌蚪| 国产精品久久久一区麻豆最新章节| 国内久久婷婷综合| 欧美一区二区在线播放| 亚洲电影视频在线| 色香色香欲天天天影视综合网| 国产精品理论片| 成人三级在线视频| 国产午夜精品福利| 国产91精品入口| 亚洲国产精品成人综合| 成人免费观看男女羞羞视频| 国产亚洲美州欧州综合国| 国内精品不卡在线| 国产亚洲欧美日韩在线一区| 国产精品1区2区3区在线观看| 精品久久久久久久久久久久久久久久久 | 国产精品久线观看视频| 国产999精品久久久久久绿帽| 欧美高清在线精品一区| 成人av在线观| 亚洲视频一区二区在线| 欧洲一区在线电影| 日韩精品乱码av一区二区| 91精品国产综合久久久蜜臀粉嫩| 日韩成人免费看| 久久久久久久久久久久电影 | 欧美图片一区二区三区| 午夜视频一区二区| 精品国产免费一区二区三区四区| 国产成人免费在线观看不卡| 综合色天天鬼久久鬼色| 欧美日韩久久不卡| 国产美女在线精品| 国产精品国产馆在线真实露脸| av一区二区久久| 亚洲va韩国va欧美va| 精品国产一区二区三区久久久蜜月| 国产一区二区伦理| 亚洲精品中文在线观看| 日韩欧美二区三区| 91亚洲永久精品| 美国三级日本三级久久99| 国产精品理论在线观看| 欧美一二三区精品| 99久久精品久久久久久清纯| 三级欧美韩日大片在线看| 国产亲近乱来精品视频| 欧美三级韩国三级日本一级| 日韩成人免费电影| 亚洲色图第一区| 日韩欧美电影一二三| 99热精品国产| 精彩视频一区二区三区| 一区二区三区成人在线视频| 久久久午夜精品| 欧美精品免费视频| 91香蕉视频黄| 国产精品18久久久| 日本三级亚洲精品| 亚洲一区二区在线播放相泽 | 日日噜噜夜夜狠狠视频欧美人| 国产精品无遮挡| 精品欧美久久久| 3d动漫精品啪啪一区二区竹菊| 成人精品免费看| 国模少妇一区二区三区| 日日摸夜夜添夜夜添精品视频| 亚洲久本草在线中文字幕| 日本一区二区三区国色天香| 欧美一二三区在线| 欧美精品一卡两卡| 日本福利一区二区| 99久久夜色精品国产网站| 精品一区二区免费在线观看| 午夜精品久久一牛影视| 夜夜操天天操亚洲| 伊人开心综合网| 玉足女爽爽91| 亚洲免费看黄网站| 亚洲欧美色图小说| 亚洲美女在线国产| 亚洲精品乱码久久久久久日本蜜臀| 欧美国产激情二区三区| 中文字幕的久久| 国产精品人妖ts系列视频| 中文字幕av一区二区三区高| 国产日韩影视精品| 国产精品人成在线观看免费 | 色噜噜狠狠成人中文综合| 国精产品一区一区三区mba视频| 首页国产欧美久久| 免费三级欧美电影| 蜜臀av亚洲一区中文字幕| 免费av成人在线| 国产一区二区在线免费观看| 精品一区二区三区视频在线观看| 激情综合色播五月| 国产91高潮流白浆在线麻豆 | 日韩一区欧美一区| 亚洲精品国产第一综合99久久| 亚洲综合色噜噜狠狠| 午夜国产精品一区| 精品一区二区三区视频在线观看| 国产毛片一区二区| 97久久人人超碰| 欧美日韩精品电影| 欧美精品一区二区三区高清aⅴ | 精品一区二区在线免费观看| 精品国产一二三| 日本欧美久久久久免费播放网| 亚洲国产成人91porn| 免费高清在线一区| 国内欧美视频一区二区| 91小视频免费观看| 欧美一级黄色大片| 久久久久久久综合色一本| 亚洲男人的天堂在线观看| 丝袜美腿亚洲色图| 国产精品亚洲а∨天堂免在线| 91丨九色丨尤物| 日韩女优视频免费观看| 国产精品美女久久久久高潮| 亚洲国产成人高清精品| 国产一区 二区| 91福利区一区二区三区| 欧美成人vps| 亚洲欧美国产高清| 久久精品国产77777蜜臀| 99精品视频免费在线观看| 欧美videofree性高清杂交| 亚洲欧美日韩一区| 韩国v欧美v日本v亚洲v| 色琪琪一区二区三区亚洲区| 久久久精品欧美丰满|