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

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

?? os_sem.c

?? LPC2104/5/6嵌入式系統(tǒng)程序實例,帶有PROTUES7.1仿真文件,適合做入門指導
?? 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一区二区三区免费野_久草精品视频
国产一区二区三区蝌蚪| 亚洲精品视频在线看| 制服丝袜中文字幕亚洲| 欧美激情一区二区三区四区| 国产日韩欧美精品电影三级在线| 中文字幕一区二区视频| 亚洲电影视频在线| 国产精品资源网| 色天天综合色天天久久| 欧美丰满嫩嫩电影| 国产日韩欧美不卡| 午夜精品久久久久影视| 国产精品1区2区3区| 欧美性大战久久久| 国产精品进线69影院| 午夜国产精品影院在线观看| 成人深夜福利app| 欧美本精品男人aⅴ天堂| 亚洲丝袜精品丝袜在线| 国产一区二区在线观看免费| 色欧美日韩亚洲| 自拍视频在线观看一区二区| 午夜精品免费在线| 色偷偷久久人人79超碰人人澡| 欧美一级片在线| 一区二区三区四区亚洲| 99久久99久久免费精品蜜臀| 欧美成人一区二区| 青青草国产精品亚洲专区无| 欧美视频一区二区三区| 亚洲乱码国产乱码精品精98午夜| 国产精品99久久久久久似苏梦涵| 欧美一级日韩一级| 久久精品国产亚洲a| 精品福利二区三区| 国产精品亚洲一区二区三区妖精 | 在线观看欧美日本| 一区二区成人在线| 欧美日韩精品欧美日韩精品一| 亚洲成在线观看| 91麻豆精品91久久久久同性| 国v精品久久久网| 中文字幕的久久| 91丨九色porny丨蝌蚪| 一区二区三区在线影院| 欧美日韩精品三区| 亚洲一区二区综合| 欧美va亚洲va国产综合| 国产精品一区二区三区乱码| 国产日韩欧美高清| 欧美日韩成人激情| 成人免费福利片| 亚洲综合图片区| 精品国产91亚洲一区二区三区婷婷| 国产精品888| 亚洲成a人v欧美综合天堂| 久久奇米777| 欧美婷婷六月丁香综合色| 国产精品综合网| 丝袜美腿亚洲综合| 国产精品免费av| 欧美电影免费提供在线观看| 在线视频国产一区| 国产成人午夜99999| 视频一区欧美精品| 亚洲欧洲性图库| 久久久久免费观看| 欧美伦理视频网站| 欧美日韩一区二区三区在线看| 国产福利一区二区三区在线视频| 亚洲va欧美va天堂v国产综合| 久久久一区二区三区捆绑**| 5月丁香婷婷综合| 97久久精品人人澡人人爽| 丰满少妇在线播放bd日韩电影| 亚洲高清免费视频| 精品一区二区三区在线观看 | 麻豆91在线播放免费| 免费看黄色91| 九色|91porny| 激情成人综合网| 国产一区二区免费看| 国产一区高清在线| 国产成人小视频| www.色精品| 欧美日高清视频| 欧美一级国产精品| 欧美精品一区二区三区四区 | 国产精品综合一区二区三区| 懂色av一区二区三区免费观看| 国产福利不卡视频| 91农村精品一区二区在线| 在线观看亚洲一区| 欧美一区二区三区四区在线观看| 欧美mv和日韩mv的网站| 国产精品久久毛片| 日韩精品一二区| 成人国产在线观看| 在线综合+亚洲+欧美中文字幕| 9191成人精品久久| 日本一二三不卡| 成人午夜电影小说| 在线精品视频免费观看| 精品国产精品网麻豆系列| 亚洲欧洲精品一区二区三区不卡| 午夜精品久久久久影视| 成人不卡免费av| 精品1区2区在线观看| 亚洲午夜免费视频| 波多野结衣亚洲| 精品久久久久99| 日本欧美一区二区在线观看| 成人av网站在线观看| 精品国产露脸精彩对白| 午夜久久福利影院| 精品视频全国免费看| 亚洲影院免费观看| 色综合久久久久| 18欧美乱大交hd1984| 国产精品一区二区果冻传媒| 欧美一区日韩一区| 免费成人在线播放| 日韩一级视频免费观看在线| 懂色av一区二区夜夜嗨| 国产精品丝袜一区| 风间由美一区二区三区在线观看 | 久久不见久久见免费视频1| 欧美性一二三区| 亚洲国产精品久久艾草纯爱 | 久久久无码精品亚洲日韩按摩| 蜜臀av性久久久久蜜臀aⅴ四虎| 欧美精品一二三| 国产传媒一区在线| 国产精品黄色在线观看| 91精品福利在线| 亚洲电影一级黄| 国产亚洲精品精华液| 成人国产一区二区三区精品| 亚洲卡通动漫在线| 欧美二区乱c少妇| 国产一区二区伦理片| 国产精品久99| 欧美日本在线看| 欧美日韩免费观看一区二区三区| 日韩精品电影在线观看| 久久伊人中文字幕| 91亚洲国产成人精品一区二区三| 亚洲国产精品久久艾草纯爱| 久久综合五月天婷婷伊人| 色爱区综合激月婷婷| 久久99热国产| 一级特黄大欧美久久久| 久久精品欧美一区二区三区不卡 | 欧美va在线播放| 在线观看免费一区| 成人国产精品免费观看| 老司机免费视频一区二区| 亚洲视频在线观看一区| 久久久精品影视| 欧美一区二区三区电影| 成人网在线免费视频| 国内精品久久久久影院一蜜桃| 偷窥国产亚洲免费视频| 一色桃子久久精品亚洲| 亚洲精品国产视频| 中文字幕视频一区二区三区久| 久久先锋资源网| 久久欧美中文字幕| 久久久久久**毛片大全| 3751色影院一区二区三区| 欧美一区二区高清| 欧美不卡一区二区三区| 欧美一级欧美三级在线观看| 777xxx欧美| 欧美sm美女调教| 中文字幕乱码一区二区免费| 国产欧美日韩激情| 国产日产精品一区| 亚洲免费观看在线观看| 亚洲人成人一区二区在线观看| 一区二区三区在线观看视频| 亚洲国产美国国产综合一区二区| 日韩国产精品久久久久久亚洲| 国产美女一区二区| 成熟亚洲日本毛茸茸凸凹| 91成人看片片| 日韩免费高清av| 国产精品美女一区二区| 午夜精品福利一区二区三区蜜桃| 日韩精品91亚洲二区在线观看| 精品亚洲porn| 91黄色免费网站| 国产亚洲一本大道中文在线| 综合婷婷亚洲小说| 激情深爱一区二区| 一本一道久久a久久精品| 精品精品欲导航| 亚洲va天堂va国产va久| 国产精品88888| 欧美一区二区三区性视频|