?? bbpc_sem.h
字號:
<HTML><HEAD><TITLE>/home/asysweb/public_html/cortex/examples/exmpl1/src/bbpc_sem.h</TITLE></HEAD><BODY><pre><font color="#6920ac">/*************************************************************************/</font><font color="#6920ac">/* */</font><font color="#6920ac">/* Copyright (c) 1997-1999 Australian Real Time Embedded Systems */</font><font color="#6920ac">/* */</font><font color="#6920ac">/* PROPRIETARY RIGHTS of Australian Real Time Embedded Systems */</font><font color="#6920ac">/* are involved in the subject matter of this material. All reproduction,*/</font><font color="#6920ac">/* manufacturing, use, and sales rights pertaining to this subject matter*/</font><font color="#6920ac">/* are governed by the license agreement. The recipient of this software */</font><font color="#6920ac">/* implicitly accepts the terms of the license. */</font><font color="#6920ac">/* */</font><font color="#6920ac">/*************************************************************************/</font><font color="#6920ac">/* * The Bounded Buffer Consumers and Producers problem * (semaphore implementation) * -------------------------------------------------- * * This program solves the bounded buffer producers and consumers * problem with semaphores. This implementation is direct translation * into CORTEX environment of the classical semaphore solution presented * in operation systems textbooks. * * In this program, the semaphore Mutex is used to synchronize access to the * shared variable Count in critical section of code where Count is updated. * This semaphore is used for mutual exclusion synchronisation. The other two * semaphores, Elements and Spaces, are used to synchronize the producer and * consumer process so the producer doesn't try to put something into a full * buffer and the consumer doesn't try to take something from an empty * buffer. These semaphores are used for conditional synchronisation, also * called event synchronisation. */</font><b><font color='DarkGreen'>#ifndef</font></b><font color="maroon"> __BBPC_SEM__H</font><b><font color='DarkGreen'>#define</font></b> <font color="maroon"><a name="__BBPC_SEM__H">__BBPC_SEM__H</a></font><b><font color='DarkGreen'>#ifdef</font></b><font color="maroon"> __cplusplus</font><i>extern</i> <font color="DarkGreen">"C"</font> {<b><font color='DarkGreen'>#endif</font></b><font color="maroon"> <font color="#6920ac">/* __cplusplus */</font></font><b><font color='DarkGreen'>#include</font></b> <a href="cortex.h.FIND-INC"><font color="blue">"cortex.h"</font></a><font color="#6920ac">/*********************** * PRIVATE CONSTANSTS * ***********************/</font><font color="#6920ac">/* the counded buffer size */</font><b><font color='DarkGreen'>#ifndef</font></b><font color="maroon"> BOUNDED_BUFFER_SIZE</font><b><font color='DarkGreen'>#define</font></b> <font color="maroon"><a name="BOUNDED_BUFFER_SIZE">BOUNDED_BUFFER_SIZE</a></font> 3<b><font color='DarkGreen'>#endif</font></b><font color="maroon"> <font color="#6920ac">/* BOUNDED_BUFFER_SIZE */</font> </font><font color="#6920ac">/* number of producers */</font><b><font color='DarkGreen'>#ifndef</font></b><font color="maroon"> NUM_PRODUCERS</font><b><font color='DarkGreen'>#define</font></b> <font color="maroon"><a name="NUM_PRODUCERS">NUM_PRODUCERS</a></font> 3<b><font color='DarkGreen'>#endif</font></b><font color="maroon"> <font color="#6920ac">/* NUM_PRODUCERS */</font></font><font color="#6920ac">/* number of consumers */</font><b><font color='DarkGreen'>#ifndef</font></b><font color="maroon"> NUM_CONSUMERS</font><b><font color='DarkGreen'>#define</font></b> <font color="maroon"><a name="NUM_CONSUMERS">NUM_CONSUMERS</a></font> 2<b><font color='DarkGreen'>#endif</font></b><font color="maroon"> <font color="#6920ac">/* NUM_CONSUMERS */</font></font><font color="#6920ac">/* task priority */</font><b><font color='DarkGreen'>#ifndef</font></b><font color="maroon"> PRIORITY</font><b><font color='DarkGreen'>#define</font></b> <font color="maroon"><a name="PRIORITY">PRIORITY</a></font> TASK_LOWEST_PRIORITY<b><font color='DarkGreen'>#endif</font></b><font color="maroon"> <font color="#6920ac">/* PRIORITY */</font></font><font color="#6920ac">/* consumer/producer time-slice */</font><b><font color='DarkGreen'>#ifndef</font></b><font color="maroon"> TIMESLICE</font><b><font color='DarkGreen'>#define</font></b> <font color="maroon"><a name="TIMESLICE">TIMESLICE</a></font> 1 <font color="#6920ac">/* in system ticks */</font><b><font color='DarkGreen'>#endif</font></b><font color="maroon"> <font color="#6920ac">/* TIMESLICE */</font></font><b><font color='DarkGreen'>#ifndef</font></b><font color="maroon"> CNAP</font><b><font color='DarkGreen'>#define</font></b> <font color="maroon"><a name="CNAP">CNAP</a></font> 3 <font color="#6920ac">/* secs */</font><b><font color='DarkGreen'>#endif</font></b><font color="maroon"> <font color="#6920ac">/* CNAP */</font></font><b><font color='DarkGreen'>#ifndef</font></b><font color="maroon"> PNAP</font><b><font color='DarkGreen'>#define</font></b> <font color="maroon"><a name="PNAP">PNAP</a></font> 3 <font color="#6920ac">/* secs */</font><b><font color='DarkGreen'>#endif</font></b><font color="maroon"> <font color="#6920ac">/* PNAP */</font></font><b><font color='DarkGreen'>#ifndef</font></b><font color="maroon"> RUNTIME</font><b><font color='DarkGreen'>#define</font></b> <font color="maroon"><a name="RUNTIME">RUNTIME</a></font> 30 <font color="#6920ac">/* secs */</font><b><font color='DarkGreen'>#endif</font></b><font color="maroon"> <font color="#6920ac">/* RUNTIME */</font></font><font color="#6920ac">/****************** * PRIVATE MACROS * ******************/</font><font color="#6920ac">/* None */</font><font color="#6920ac">/*********************** * PRIVATE DATA TYPES * ***********************/</font><font color="#6920ac">/* None */</font><font color="#6920ac">/***************** * PRIVATE DATA * *****************/</font><font color="#6920ac">/* mutual exclusion sunchronisation semaphore */</font><i>sema_Semaphore_t</i> Mutex, *pMutex;<font color="#6920ac">/* consumer synchronisation semaphore */</font><i>sema_Semaphore_t</i> Elements, *pElements;<font color="#6920ac">/* producer synchronisation semaphore */</font><i>sema_Semaphore_t</i> Spaces, *pSpaces;<font color="#6920ac">/* bounded buffer and associates */</font><i>crtx_Uint32_t</i> Buffer[<a href="#BOUNDED_BUFFER_SIZE">BOUNDED_BUFFER_SIZE</a>];<i>crtx_Int_t</i> Count;<i>crtx_Int_t</i> PutIn;<i>crtx_Int_t</i> TakeOut;<font color="#6920ac">/* producers and consumes task IDs */</font><i>task_ID_t</i> Producers[<a href="#NUM_PRODUCERS">NUM_PRODUCERS</a>];<i>task_ID_t</i> Consumers[<a href="#NUM_CONSUMERS">NUM_CONSUMERS</a>];<font color="#6920ac">/********************************* * LOCAL PROCEDURES PROTOTYPES * *********************************/</font><font color="#6920ac">/* CORTEX main thread */</font><font size="+1"><i>crtx_Void_t</i> <a href="crtx_Main.FIND-FUNC">crtx_Main</a>(<i>crtx_Int_t</i> ArgC_a, <i>crtx_Void_t</i> *pArgV_a, <i>crtx_Void_t</i> *pEnvV_a);</font><font color="#6920ac">/* Producer task prototype */</font><font size="+1"><i>crtx_Void_t</i> <a href="Producer.FIND-FUNC">Producer</a>(<i>crtx_Void_t</i>);</font><font color="#6920ac">/* Consumer task prototype */</font><font size="+1"><i>crtx_Void_t</i> <a href="Consumer.FIND-FUNC">Consumer</a>(<i>crtx_Void_t</i>);</font><font color="#6920ac">/* procedure to deposit item to the buffer */</font><font size="+1"><i>crtx_Void_t</i> <a href="Deposit.FIND-FUNC">Deposit</a>(<i>crtx_Uint32_t</i> Item_a);</font><font color="#6920ac">/* procedure to fetch item from the buffer */</font><font size="+1"><i>crtx_Uint32_t</i> <a href="Fetch.FIND-FUNC">Fetch</a>(<i>crtx_Void_t</i>);</font><font color="#6920ac">/* ===== END OF THE DEFINITION FILE ===== */</font><b><font color='DarkGreen'>#ifdef</font></b><font color="maroon"> __cplusplus</font>}<b><font color='DarkGreen'>#endif</font></b><font color="maroon"> <font color="#6920ac">/* __cplusplus */</font></font><b><font color='DarkGreen'>#endif</font></b><font color="maroon"> <font color="#6920ac">/* __BBPC_SEM__H */</font></font></pre></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -