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

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

?? os_sem.c

?? 講UC/OS的書
?? C
字號:
/*
*********************************************************************************************************
*                                                uC/OS-II
*                                          The Real-Time Kernel
*                                          SEMAPHORE MANAGEMENT
*
*                        (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
*                                           All Rights Reserved
*
*                                                  V2.00
*
* File : OS_SEM.C
* By   : Jean J. Labrosse
*********************************************************************************************************
*/

#ifndef  OS_MASTER_FILE
#include "includes.h"
#endif

#if OS_SEM_EN
/*
*********************************************************************************************************
*                                           ACCEPT SEMAPHORE
*
* Description: This function checks the semaphore to see if a resource is available or, if an event
*              occurred.  Unlike OSSemPend(), OSSemAccept() does not suspend the calling task if the
*              resource is not available or the event did not occur.
*
* Arguments  : pevent     is a pointer to the event control block
*
* Returns    : >  0       if the resource is available or the event did not occur the semaphore is
*                         decremented to obtain the resource.
*              == 0       if the resource is not available or the event did not occur or,
*                         you didn't pass a pointer to a semaphore
*********************************************************************************************************
*/

INT16U OSSemAccept (OS_EVENT *pevent)
{
    INT16U cnt;


    OS_ENTER_CRITICAL();
    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
        OS_EXIT_CRITICAL();
        return (0);
    }
    cnt = pevent->OSEventCnt;
    if (cnt > 0) {                                    /* See if resource is available                  */
        pevent->OSEventCnt--;                         /* Yes, decrement semaphore and notify caller    */
    }
    OS_EXIT_CRITICAL();
    return (cnt);                                     /* Return semaphore count                        */
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                           CREATE A SEMAPHORE
*
* Description: This function creates a semaphore.
*
* Arguments  : cnt           is the initial value for the semaphore.  If the value is 0, no resource is
*                            available (or no event has occurred).  You initialize the semaphore to a 
*                            non-zero value to specify how many resources are available (e.g. if you have
*                            10 resources, you would initialize the semaphore to 10).
*
* Returns    : != (void *)0  is a pointer to the event control clock (OS_EVENT) associated with the
*                            created semaphore
*              == (void *)0  if no event control blocks were available
*********************************************************************************************************
*/

OS_EVENT *OSSemCreate (INT16U cnt)
{
    OS_EVENT *pevent;


    OS_ENTER_CRITICAL();
    pevent = OSEventFreeList;                              /* Get next free event control block        */
    if (OSEventFreeList != (OS_EVENT *)0) {                /* See if pool of free ECB pool was empty   */
        OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
    }
    OS_EXIT_CRITICAL();
    if (pevent != (OS_EVENT *)0) {                         /* Get an event control block               */
        pevent->OSEventType = OS_EVENT_TYPE_SEM;
        pevent->OSEventCnt  = cnt;                         /* Set semaphore value                      */
        OSEventWaitListInit(pevent);
    }
    return (pevent);
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                           PEND ON SEMAPHORE
*
* Description: This function waits for a semaphore.
*
* Arguments  : pevent        is a pointer to the event control block associated with the desired 
*                            semaphore.
*
*              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
*                            wait for the resource up to the amount of time specified by this argument.  
*                            If you specify 0, however, your task will wait forever at the specified 
*                            semaphore or, until the resource becomes available (or the event occurs).
*
*              err           is a pointer to where an error message will be deposited.  Possible error
*                            messages are:
*
*                            OS_NO_ERR          The call was successful and your task owns the resource 
*                                               or, the event you are waiting for occurred.
*                            OS_TIMEOUT         The semaphore was not received within the specified 
*                                               timeout.
*                            OS_ERR_EVENT_TYPE  If you didn't pass a pointer to a semaphore.
*                            OS_ERR_PEND_ISR    If you called this function from an ISR and the result
*                                               would lead to a suspension.
*
* Returns    : none
*********************************************************************************************************
*/

void OSSemPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)
{
    OS_ENTER_CRITICAL();
    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
        OS_EXIT_CRITICAL();
        *err = OS_ERR_EVENT_TYPE;
    }
    if (pevent->OSEventCnt > 0) {                     /* If sem. is positive, resource available ...   */
        pevent->OSEventCnt--;                         /* ... decrement semaphore only if positive.     */
        OS_EXIT_CRITICAL();
        *err = OS_NO_ERR;
    } else if (OSIntNesting > 0) {                    /* See if called from ISR ...                    */
        OS_EXIT_CRITICAL();                           /* ... can't PEND from an ISR                    */
        *err = OS_ERR_PEND_ISR;
    } else {                                          /* Otherwise, must wait until event occurs       */
        OSTCBCur->OSTCBStat    |= OS_STAT_SEM;        /* Resource not available, pend on semaphore     */
        OSTCBCur->OSTCBDly      = timeout;            /* Store pend timeout in TCB                     */
        OSEventTaskWait(pevent);                      /* Suspend task until event or timeout occurs    */
        OS_EXIT_CRITICAL();
        OSSched();                                    /* Find next highest priority task ready         */
        OS_ENTER_CRITICAL();
        if (OSTCBCur->OSTCBStat & OS_STAT_SEM) {      /* Must have timed out if still waiting for event*/
            OSEventTO(pevent);
            OS_EXIT_CRITICAL();
            *err = OS_TIMEOUT;                        /* Indicate that didn't get event within TO      */
        } else {
            OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
            OS_EXIT_CRITICAL();
            *err = OS_NO_ERR;
        }
    }
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                         POST TO A SEMAPHORE
*
* Description: This function signals a semaphore
*
* Arguments  : pevent        is a pointer to the event control block associated with the desired 
*                            semaphore.
*
* Returns    : OS_NO_ERR          The call was successful and the semaphore was signaled.
*              OS_SEM_OVF         If the semaphore count exceeded its limit.  In other words, you have 
*                                 signalled the semaphore more often than you waited on it with either
*                                 OSSemAccept() or OSSemPend().
*              OS_ERR_EVENT_TYPE  If you didn't pass a pointer to a semaphore
*********************************************************************************************************
*/

INT8U OSSemPost (OS_EVENT *pevent)
{
    OS_ENTER_CRITICAL();
    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
        OS_EXIT_CRITICAL();
        return (OS_ERR_EVENT_TYPE);
    }
    if (pevent->OSEventGrp) {                              /* See if any task waiting for semaphore    */
        OSEventTaskRdy(pevent, (void *)0, OS_STAT_SEM);    /* Ready highest prio task waiting on event */
        OS_EXIT_CRITICAL();
        OSSched();                                    /* Find highest priority task ready to run       */
        return (OS_NO_ERR);
    } else {
        if (pevent->OSEventCnt < 65535) {             /* Make sure semaphore will not overflow         */
            pevent->OSEventCnt++;                     /* Increment semaphore count to register event   */
            OS_EXIT_CRITICAL();
            return (OS_NO_ERR);
        } else {                                      /* Semaphore value has reached its maximum       */
            OS_EXIT_CRITICAL();
            return (OS_SEM_OVF);
        }
    }
}
/*
*********************************************************************************************************
*                                          QUERY A SEMAPHORE
*
* Description: This function obtains information about a semaphore
*
* Arguments  : pevent        is a pointer to the event control block associated with the desired 
*                            semaphore
*
*              pdata         is a pointer to a structure that will contain information about the 
*                            semaphore.
*
* Returns    : OS_NO_ERR          The call was successful and the message was sent
*              OS_ERR_EVENT_TYPE  If you are attempting to obtain data from a non semaphore.
*********************************************************************************************************
*/

INT8U OSSemQuery (OS_EVENT *pevent, OS_SEM_DATA *pdata)
{
    INT8U  i;
    INT8U *psrc;
    INT8U *pdest;
    
    
    OS_ENTER_CRITICAL();
    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
        OS_EXIT_CRITICAL();
        return (OS_ERR_EVENT_TYPE);
    }
    pdata->OSEventGrp = pevent->OSEventGrp;                /* Copy message mailbox wait list           */
    psrc              = &pevent->OSEventTbl[0];
    pdest             = &pdata->OSEventTbl[0];
    for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
        *pdest++ = *psrc++;   
    }
    pdata->OSCnt      = pevent->OSEventCnt;                /* Get semaphore count                      */
    OS_EXIT_CRITICAL();
    return (OS_NO_ERR);
}
#endif

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
喷水一区二区三区| 国产欧美一区二区精品秋霞影院 | 欧美一区中文字幕| 亚洲成人中文在线| 91麻豆精品国产自产在线| 日韩av一级片| 久久先锋资源网| www.亚洲人| 一区二区三区产品免费精品久久75| 在线观看亚洲a| 青青草国产精品亚洲专区无| 精品国产91亚洲一区二区三区婷婷| 国产成人av影院| 亚洲欧美另类久久久精品| 欧美性感一类影片在线播放| 日韩国产一二三区| 欧美精品一区二区三区视频| 国产成人在线色| 亚洲综合男人的天堂| 日韩午夜av电影| 高清国产一区二区| 亚洲成人动漫av| 欧美国产综合色视频| 欧美四级电影在线观看| 国产一区 二区 三区一级| 亚洲激情校园春色| 精品成人a区在线观看| 777午夜精品免费视频| 国产精品99久久久久久宅男| 亚洲免费在线播放| 日韩亚洲欧美在线| 91久久奴性调教| 玖玖九九国产精品| 亚洲精品综合在线| 久久久国产综合精品女国产盗摄| 一本到三区不卡视频| 国内一区二区在线| 图片区小说区国产精品视频| 久久久久久久久久久久电影| 欧美日韩一区不卡| 国产成人精品亚洲午夜麻豆| 亚洲国产精品尤物yw在线观看| 久久蜜臀精品av| 欧美日韩国产美| 色综合久久综合网97色综合| 国产综合久久久久久久久久久久| 亚洲在线视频网站| 国产精品久久福利| 国产视频一区在线播放| 日韩丝袜美女视频| 欧美三电影在线| 色婷婷精品久久二区二区蜜臀av | 精品视频在线免费| 不卡一二三区首页| 国产麻豆一精品一av一免费 | 久久精品国产99久久6| 亚洲一区二区三区四区五区黄 | 色婷婷综合久久久久中文一区二区 | 精品一区二区影视| 亚洲高清不卡在线| 免费成人在线观看| 一区二区成人在线视频| 日韩一区欧美一区| 国产欧美日本一区视频| 欧美一区二区在线播放| 欧美日韩在线播放三区四区| 97精品超碰一区二区三区| 国产精品资源网站| 国产一区二区毛片| 国产揄拍国内精品对白| 老司机精品视频导航| 丝袜亚洲另类丝袜在线| 亚洲国产毛片aaaaa无费看| 伊人色综合久久天天人手人婷| 亚洲婷婷综合久久一本伊一区 | 亚洲精品免费视频| 亚洲天堂免费看| 亚洲欧美日韩精品久久久久| 综合亚洲深深色噜噜狠狠网站| 国产精品欧美一级免费| 国产精品久久久久久久久久免费看 | 国产一区二区在线看| 国产在线视频一区二区三区| 精品一区二区久久久| 国产麻豆一精品一av一免费| 国产高清视频一区| 不卡视频一二三四| 日本高清不卡一区| 91精品国产综合久久精品麻豆 | 日韩精品电影在线观看| 麻豆成人久久精品二区三区红 | 久久美女高清视频| 久久精品免费在线观看| 国产精品久久久久久久久果冻传媒 | 国产精品一区二区黑丝| 成人国产精品免费网站| 91香蕉视频污在线| 欧美色老头old∨ideo| 在线电影欧美成精品| 精品国产乱码久久久久久蜜臀 | 精品88久久久久88久久久| 久久一区二区视频| 亚洲色图19p| 丝袜诱惑亚洲看片| 国产高清成人在线| 在线视频国内一区二区| 日韩一区和二区| 亚洲国产精品精华液2区45| 亚洲午夜精品17c| 韩国av一区二区| 91久久精品网| 久久免费看少妇高潮| 一区二区激情视频| 国产一区二区在线影院| 欧洲一区在线电影| 久久尤物电影视频在线观看| 亚洲欧洲综合另类在线| 免费观看91视频大全| av一区二区不卡| 日韩欧美卡一卡二| 一区二区三区精品| 国产盗摄一区二区| 91精品国产色综合久久不卡蜜臀| 日本一区二区三区免费乱视频 | 亚洲精品日日夜夜| 国产一区美女在线| 欧美日韩在线播放三区四区| 国产欧美视频在线观看| 五月天一区二区| 91在线看国产| 久久夜色精品一区| 午夜欧美在线一二页| 成人18精品视频| 337p粉嫩大胆色噜噜噜噜亚洲| 亚洲国产日韩精品| 一本色道久久综合亚洲精品按摩| 亚洲精品一区二区三区四区高清 | 免费欧美在线视频| 色香蕉久久蜜桃| 欧美激情综合网| 国产一区在线观看视频| 日韩视频免费观看高清完整版在线观看| 亚洲图片你懂的| 成人精品视频一区| 久久久影视传媒| 久久电影国产免费久久电影| 欧美日韩高清一区| 亚洲国产精品久久人人爱| 不卡的av电影| 久久精品无码一区二区三区| 久久成人羞羞网站| 日韩精品在线一区| 日本亚洲电影天堂| 制服丝袜亚洲精品中文字幕| 亚洲va欧美va天堂v国产综合| 91麻豆国产福利精品| 国产精品盗摄一区二区三区| 国产91综合一区在线观看| 精品国产91久久久久久久妲己| 日韩国产在线观看一区| 欧美一区二区三区人| 午夜精品aaa| 欧美精品久久99久久在免费线| 亚洲va欧美va人人爽| 91精品国产欧美日韩| 调教+趴+乳夹+国产+精品| 欧美日韩美少妇| 日本不卡一区二区三区| 欧美一区二区高清| 韩国女主播成人在线观看| 精品国产污网站| 国产精品影音先锋| 久久久精品欧美丰满| 成人久久18免费网站麻豆 | 欧美一区二区三区视频免费| 免费高清视频精品| 久久久亚洲午夜电影| 国产成人精品一区二区三区四区| 欧美激情在线观看视频免费| 91麻豆免费观看| 一区二区三区精品视频| 69久久99精品久久久久婷婷 | 不卡在线观看av| 亚洲美女屁股眼交| 欧美日韩精品福利| 麻豆成人综合网| 国产精品伦理在线| 欧美丝袜第三区| 蜜桃久久久久久| 国产精品美女久久久久久| 在线中文字幕不卡| 精品一区二区免费视频| 国产精品视频在线看| 91高清视频在线| 麻豆国产精品视频| 国产精品国产三级国产aⅴ中文 | 亚洲综合在线视频| 欧美日韩黄视频| 国产成a人无v码亚洲福利| 一区二区三国产精华液|