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

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

?? os_sem.c

?? 任務一 任務管理 任務二 優先級天花板 任務三 哲學家就餐 任務四 消息隊列 任務五 時鐘中斷
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*
*********************************************************************************************************
*                                                uC/OS-II
*                                          The Real-Time Kernel
*                                          SEMAPHORE MANAGEMENT
*
*                          (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
*                                           All Rights Reserved
*
* File : OS_SEM.C
* By   : Jean J. Labrosse
*********************************************************************************************************
*/

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

#if OS_SEM_EN > 0
/*
*********************************************************************************************************
*                                           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,
*                         if 'pevent' is a NULL pointer or,
*                         if you didn't pass a pointer to a semaphore
*********************************************************************************************************
*/

#if OS_SEM_ACCEPT_EN > 0
INT16U  OSSemAccept (OS_EVENT *pevent)
{
#if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
    OS_CPU_SR  cpu_sr;
#endif    
    INT16U     cnt;


#if OS_ARG_CHK_EN > 0
    if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
        return (0);
    }
    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
        return (0);
    }
#endif
    OS_ENTER_CRITICAL();
    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                        */
}
#endif    

/*$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)
{
#if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
    OS_CPU_SR  cpu_sr;
#endif    
    OS_EVENT  *pevent;


    if (OSIntNesting > 0) {                                /* See if called from ISR ...               */
        return ((OS_EVENT *)0);                            /* ... can't CREATE from an ISR             */
    }
    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                      */
        pevent->OSEventPtr  = (void *)0;                   /* Unlink from ECB free list                */
        OS_EventWaitListInit(pevent);                      /* Initialize to 'nobody waiting' on sem.   */
    }
    return (pevent);
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                         DELETE A SEMAPHORE
*
* Description: This function deletes a semaphore and readies all tasks pending on the semaphore.
*
* Arguments  : pevent        is a pointer to the event control block associated with the desired
*                            semaphore.
*
*              opt           determines delete options as follows:
*                            opt == OS_DEL_NO_PEND   Delete semaphore ONLY if no task pending
*                            opt == OS_DEL_ALWAYS    Deletes the semaphore even if tasks are waiting.
*                                                    In this case, all the tasks pending will be readied.
*
*              err           is a pointer to an error code that can contain one of the following values:
*                            OS_NO_ERR               The call was successful and the semaphore was deleted
*                            OS_ERR_DEL_ISR          If you attempted to delete the semaphore from an ISR
*                            OS_ERR_INVALID_OPT      An invalid option was specified
*                            OS_ERR_TASK_WAITING     One or more tasks were waiting on the semaphore
*                            OS_ERR_EVENT_TYPE       If you didn't pass a pointer to a semaphore
*                            OS_ERR_PEVENT_NULL      If 'pevent' is a NULL pointer.
*
* Returns    : pevent        upon error
*              (OS_EVENT *)0 if the semaphore was successfully deleted.
*
* Note(s)    : 1) This function must be used with care.  Tasks that would normally expect the presence of
*                 the semaphore MUST check the return code of OSSemPend().
*              2) OSSemAccept() callers will not know that the intended semaphore has been deleted unless
*                 they check 'pevent' to see that it's a NULL pointer.
*              3) This call can potentially disable interrupts for a long time.  The interrupt disable
*                 time is directly proportional to the number of tasks waiting on the semaphore.
*              4) Because ALL tasks pending on the semaphore will be readied, you MUST be careful in
*                 applications where the semaphore is used for mutual exclusion because the resource(s)
*                 will no longer be guarded by the semaphore.
*********************************************************************************************************
*/

#if OS_SEM_DEL_EN > 0
OS_EVENT  *OSSemDel (OS_EVENT *pevent, INT8U opt, INT8U *err)
{
#if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
    OS_CPU_SR  cpu_sr;
#endif    
    BOOLEAN    tasks_waiting;


    if (OSIntNesting > 0) {                                /* See if called from ISR ...               */
        *err = OS_ERR_DEL_ISR;                             /* ... can't DELETE from an ISR             */
        return (pevent);
    }
#if OS_ARG_CHK_EN > 0
    if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
        *err = OS_ERR_PEVENT_NULL;
        return (pevent);
    }
    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
        *err = OS_ERR_EVENT_TYPE;
        return (pevent);
    }
#endif
    OS_ENTER_CRITICAL();
    if (pevent->OSEventGrp != 0x00) {                      /* See if any tasks waiting on semaphore    */
        tasks_waiting = TRUE;                              /* Yes                                      */
    } else {
        tasks_waiting = FALSE;                             /* No                                       */
    }
    switch (opt) {
        case OS_DEL_NO_PEND:                               /* Delete semaphore only if no task waiting */
             if (tasks_waiting == FALSE) {
                 pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
                 pevent->OSEventPtr  = OSEventFreeList;    /* Return Event Control Block to free list  */
                 OSEventFreeList     = pevent;             /* Get next free event control block        */
                 OS_EXIT_CRITICAL();
                 *err = OS_NO_ERR;
                 return ((OS_EVENT *)0);                   /* Semaphore has been deleted               */
             } else {
                 OS_EXIT_CRITICAL();
                 *err = OS_ERR_TASK_WAITING;
                 return (pevent);
             }

        case OS_DEL_ALWAYS:                                /* Always delete the semaphore              */
             while (pevent->OSEventGrp != 0x00) {          /* Ready ALL tasks waiting for semaphore    */
                 OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM);
             }
             pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
             pevent->OSEventPtr  = OSEventFreeList;        /* Return Event Control Block to free list  */
             OSEventFreeList     = pevent;                 /* Get next free event control block        */
             OS_EXIT_CRITICAL();
             if (tasks_waiting == TRUE) {                  /* Reschedule only if task(s) were waiting  */
                 OS_Sched();                               /* Find highest priority task ready to run  */
             }
             *err = OS_NO_ERR;
             return ((OS_EVENT *)0);                       /* Semaphore has been deleted               */

        default:
             OS_EXIT_CRITICAL();
             *err = OS_ERR_INVALID_OPT;
             return (pevent);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品无人区| 精品久久一区二区| 成人91在线观看| 国产麻豆成人精品| 精品在线视频一区| 国产麻豆精品视频| 国产超碰在线一区| 不卡视频在线看| 色久综合一二码| 欧美色窝79yyyycom| 欧美日韩三级视频| 日韩免费性生活视频播放| 久久久精品tv| 日韩伦理电影网| 日韩成人免费看| 韩国女主播成人在线观看| 国产99久久久国产精品潘金| 91亚洲午夜精品久久久久久| 欧美日韩视频第一区| 久久综合久久综合久久综合| 欧美国产一区二区| 亚洲黄色在线视频| 久久99精品国产.久久久久| 国产mv日韩mv欧美| 欧美三级韩国三级日本一级| 欧美成人猛片aaaaaaa| 中文字幕一区二区三区四区| 亚洲高清在线精品| 国产一区二区女| 欧洲一区二区av| 久久久精品黄色| 午夜视频在线观看一区| 风流少妇一区二区| 5858s免费视频成人| 国产精品视频第一区| 日韩中文字幕区一区有砖一区| 国产精品一区二区免费不卡| 欧美日韩在线三级| 国产欧美精品区一区二区三区| 一区二区三区免费| 国产精品一区二区在线播放| 欧美日韩国产小视频| 国产欧美一区二区在线| 日韩av午夜在线观看| 波多野结衣在线aⅴ中文字幕不卡| 欧美日韩视频在线一区二区| 国产精品久久久久久久久晋中 | 久久日韩精品一区二区五区| 中文字幕在线观看不卡| 国产在线乱码一区二区三区| 欧美日韩一区二区在线观看| 亚洲日本韩国一区| 国产精品资源在线看| 欧美一区二区三区视频免费 | 亚洲综合激情另类小说区| 精品亚洲免费视频| 欧美日韩久久不卡| 亚洲激情校园春色| 91视频在线观看免费| 国产拍欧美日韩视频二区| 国产一区二区三区观看| 欧美成人一区二区三区| 爽爽淫人综合网网站| 欧美三级在线播放| 亚洲综合一区二区三区| 色香蕉成人二区免费| 自拍偷拍亚洲综合| 成人av免费观看| 亚洲天堂网中文字| 一本到三区不卡视频| 成人欧美一区二区三区1314| 不卡视频一二三四| 亚洲欧美日韩中文播放| 91免费看视频| 一区二区免费在线播放| 欧美图区在线视频| 午夜精品福利一区二区三区av| 欧美视频中文字幕| 日韩和欧美的一区| 日韩欧美一区二区视频| 韩国三级在线一区| 欧美国产国产综合| 色综合久久中文综合久久牛| 亚洲欧美激情在线| 欧美影院精品一区| 麻豆国产欧美一区二区三区| 精品国产第一区二区三区观看体验 | 亚洲精品五月天| 91黄视频在线| 美女视频黄 久久| 国产日韩欧美精品一区| 99久久99久久久精品齐齐| 亚洲成人自拍一区| 精品1区2区在线观看| av不卡在线播放| 午夜精品福利久久久| 日韩精品一区国产麻豆| 丰满少妇在线播放bd日韩电影| 伊人夜夜躁av伊人久久| 日韩区在线观看| 顶级嫩模精品视频在线看| 亚洲精品ww久久久久久p站| 欧美精品高清视频| 国产精品69久久久久水密桃| 一二三区精品视频| 日韩精品最新网址| 色综合久久久久综合体桃花网| 午夜精品久久久久久久蜜桃app| 精品久久久久久最新网址| 9久草视频在线视频精品| 无码av中文一区二区三区桃花岛| 久久奇米777| 欧美精品在线一区二区| 粉嫩aⅴ一区二区三区四区五区| 一区二区三区在线看| 精品国产一区久久| 在线观看亚洲一区| 国产大陆a不卡| 日韩国产欧美在线观看| 国产精品免费aⅴ片在线观看| 欧美久久久久中文字幕| 一本一道久久a久久精品| 黄色小说综合网站| 亚洲福利视频一区| 国产精品理论在线观看| 26uuu亚洲| 91.com视频| 欧美性受xxxx黑人xyx性爽| 国产精品1区2区3区| 麻豆精品国产传媒mv男同| 亚洲成人一区二区在线观看| 亚洲品质自拍视频网站| 亚洲国产成人自拍| 久久色.com| 久久久久青草大香线综合精品| 欧美一区二区视频在线观看| 欧美性受xxxx黑人xyx性爽| 一本到不卡免费一区二区| av在线不卡网| k8久久久一区二区三区 | 中文字幕精品三区| 精品三级在线观看| 日韩一区二区三区视频在线观看| 欧美性受极品xxxx喷水| 欧美一a一片一级一片| 在线欧美日韩国产| 欧美日韩亚洲综合| 欧美美女直播网站| 欧美日韩大陆一区二区| 欧美精品在线观看一区二区| 欧美人妖巨大在线| 日韩一级完整毛片| 精品免费视频一区二区| 日韩你懂的在线观看| 久久久久9999亚洲精品| 亚洲国产电影在线观看| 国产精品久久久久久久裸模| 亚洲欧美综合色| 亚洲精品国产无天堂网2021| 一二三四区精品视频| 天天色 色综合| 久久er99热精品一区二区| 狠狠狠色丁香婷婷综合久久五月| 极品少妇xxxx精品少妇偷拍| 国产一区二区不卡在线| 成人av资源在线| 色屁屁一区二区| 欧美日韩一区三区| 欧美成人vr18sexvr| 欧美国产日韩一二三区| 国产精品美女久久久久久久久久久| 中文字幕一区二区三区四区| 亚洲一区在线观看免费观看电影高清 | 久久福利资源站| 丁香激情综合国产| 一本到不卡免费一区二区| 欧美人妖巨大在线| 久久久久亚洲综合| 亚洲一区视频在线| 蜜桃视频在线一区| 成人av在线资源| 欧美日韩国产片| 国产欧美日韩麻豆91| 一区二区视频在线| 麻豆国产精品一区二区三区| 成人精品视频一区二区三区尤物| 色综合久久中文综合久久牛| 欧美成人性战久久| 亚洲精品自拍动漫在线| 久久99精品国产.久久久久久 | 午夜精品久久久久久久久久久| 国内精品在线播放| 色婷婷久久久久swag精品| 日韩欧美一级特黄在线播放| 亚洲男人天堂av网| 精品一区二区免费看| 91久久精品国产91性色tv| 国产视频一区在线播放| 亚洲成人高清在线| 91丨porny丨中文|