📄 mk_queu.c
字号:
/*+MHDR*/
/*
# clearcase: CmicroRel2.3
+------------------------------------------------------------------------------+
| Modulname : MK_QUEU.C |
| Author : S&P Media GmbH Germany |
+------------------------------------------------------------------------------+
| |
| |
| Description : |
| This module represents the mechanism of the SDL-signalqueue. |
| A signal is represented by the following structure : |
| |
| +------------------------------------------------------+ |
| | Signal (signal-instance-data) | |
| +------------------------------------------------------+ |
| | Pointer to successor | |
| +------------------------------------------------------+ |
| | SAVE-state | |
| +------------------------------------------------------+ |
| |
| Normally, signals are put at the end of the linked list, but not in |
| the case of "SAVE". |
| |
| The ordering of the signals in the queue is as follows: |
| 1. order by priority. The signal with the highest priority is inserted in |
| the queue at the first position. |
| 2. order by time of arrival. If several signals with the same priority |
| are queued, they are inserted according to their arrival. |
| |
| Using a preemptive kernel, there possibly are several queues. |
| The user doesn't have to take regard of this fact, because the kernel |
| is the only client of the queues. The Cmicro Kernel's behaviour doesn't |
| change because of the the existence of more than one queue from the user's |
| point of view. |
| |
| The address of a signal-element is to be the same as the address of |
| the signal itself. The Cmicro Kernel uses the signal address to access a |
| signal. |
| |
| M1 Errormessages, which are routed to the ErrorHandler |
| -------------------------------------------------------- |
| - none - |
| |
| M2 Exported functions of this module : |
| -------------------------------------------------------- |
| void xmk_InitQueue (void) |
| xmk_T_MESSAGE* xmk_FirstSignal (void) |
| xmk_T_MESSAGE* xmk_NextSignal (void) |
| void xmk_InsertSignal (xmk_T_MESSAGE) |
| void xmk_RemoveCurrentSignal (void) |
| void xmk_RemoveSignalBySignalID (xmk_T_SIGNAL) |
| void xmk_RemoveSignalsByProcessID (xPID) |
| xmk_T_MESSAGE* xmk_AllocSignal (void) |
| void xmk_FreeSignal (xmk_T_MESSAGE) |
| xmk_T_BOOL xmk_TestAndSetSaveState (xmk_T_STATE) |
| xmk_T_BOOL xmk_QueueEmpty (void) |
| void xmk_QueryQueue (xmk_T_CMD_QUERY_QUEUE_CNF) |
| |
| M3 Static functions of this module : |
| -------------------------------------------------------- |
| - none - |
| |
+------------------------------------------------------------------------------+
*/
/*-MHDR*/
/*
+------------------------------------------------------------------------------+
| |
| Copyright by Telelogic AB 1993 - 1998 |
| Copyright by S&P Media GmbH Germany 1993 - 1998 |
| |
| This Program is owned by Telelogic and is protected by national |
| copyright laws and international copyright treaties. Telelogic |
| grants you the right to use this Program on one computer or in |
| one local computer network at any one time. |
| Under this License you may only modify the source code for the purpose |
| of adapting it to your environment. You must reproduce and include |
| any copyright and trademark notices on all copies of the source code. |
| You may not use, copy, merge, modify or transfer the Program except as |
| provided in this License. |
| Telelogic does not warrant that the Program will meet your |
| requirements or that the operation of the Program will be |
| uninterrupted and error free. You are solely responsible that the |
| selection of the Program and the modification of the source code |
| will achieve your intended results and that the results are actually |
| obtained. |
| |
+------------------------------------------------------------------------------+
*/
#ifndef __MK_QUEU_C_
#define __MK_QUEU_C_
/*+IMPORT*/
/*==================== I M P O R T =========================================*/
#include "ml_typw.h"
/*-------------------- Variables -----------------------------------------*/
/*
** Pointer to <root-process-table>
*/
#ifndef NO_GLOBAL_VARS
/* Modified by GBU,990518 */
extern XCONST XPDTBL xmk_ROM_ptr xPDTBL[MAX_SDL_PROCESS_TYPES+1];
#ifdef XMK_USE_MAX_ERR_CHECK
extern unsigned char xmk_InitState;
#endif
#endif
/*============================================================================*/
/*-IMPORT*/
/*+MGG*/
/*==================== V A L U E S O F T H I S M O D U L E =============*/
/*-------------------- Constants, Macros ----------------------------------*/
/*-------------------- Typedefinitions ----------------------------------*/
#if defined(XMK_ADD_PROFILE) || defined(XMK_ADD_CQUERY_QUEUE)
/*
** In order to be able to test the number of used signals in the queue(s)
** xmk_max_q_cnt is updated with every change of the number of signals.
** The maximum counter value can be investigated whenever needed.
** This, of course, is only useful when nearly all of the critical phases
** have been running.
*/
#ifndef NO_GLOBAL_VARS
/*
** counter for the current number of signals in the queue(s)
*/
int xmk_act_q_cnt;
/*
** counter for maximum number of signals in the queues
*/
int xmk_max_q_cnt;
#endif /* NO_GLOBAL_VARS */
#define XMK_Q_INIT_MAX \
xmk_act_q_cnt=0; \
xmk_max_q_cnt=0;
#define XMK_Q_SET_MAX if (xmk_act_q_cnt > xmk_max_q_cnt ) \
xmk_max_q_cnt = xmk_act_q_cnt;
#define XMK_Q_INCR_ACT xmk_act_q_cnt ++;
#define XMK_Q_DECR_ACT if (xmk_act_q_cnt) xmk_act_q_cnt --;
#else
#define XMK_Q_INIT_MAX
#define XMK_Q_SET_MAX
#define XMK_Q_INCR_ACT
#define XMK_Q_DECR_ACT
#endif /* ... XMK_ADD_PROFILE || XMK_ADD_CQUERY_QUEUE */
/*+PREEMPT*/
#ifdef XMK_USE_PREEMPTIVE
/*
** Internal value (priority-level of signal's receiver)
*/
#define EPRIOLEVEL xPDTBL[EPIDTYPE(p_Message->rec)]->PrioLevel
#endif
/*-PREEMPT*/
/*-------------------- Functions -----------------------------------------*/
/*-------------------- Variables -----------------------------------------*/
/*
** array which represents the available signals
*/
#ifndef NO_GLOBAL_VARS
static T_E_SIGNAL xmk_SignalArrayVar [ XMK_MAX_SIGNALS ] ;
/*
** pointer to list of free signals
*/
static T_E_SIGNAL *xmk_FreeListPointer ;
/*
** pointer to list of queued signals
** when using a preemptive kernel, this pointer is
** updated with every context-switch
*/
T_E_SIGNAL XMK_QUEUE_PTR ;
/*
** pointer to the signal that is currently worked on
** when using a preemptive kernel, this pointer is
** updated with every context-switch
*/
T_E_SIGNAL XMK_CURRENTSIGNAL_PTR ;
#endif /* NO_GLOBAL_VARS */
/*============================================================================*/
/*-MGG*/
/*+FHDR E*/
/*
+------------------------------------------------------------------------------+
| Functionname : xmk_InitQueue |
| Author : S&P Media GmbH Germany |
+------------------------------------------------------------------------------+
| |
| Description : |
| This function initializes the signal queue. It must be called before any |
| other Cmicro Kernel function, e.g.before xmk_InitSDL(). All relevant |
| pointers are initialized. All signal-elements are put into the free-list. |
| The SAVE-state of all signals is set to false. |
| |
| Parameter : - |
| |
| Return : - |
| |
+------------------------------------------------------------------------------+
*/
/*-FHDR E*/
/*+FDEF E*/
#ifndef XNOPROTO
void xmk_InitQueue( void )
#else
void xmk_InitQueue()
#endif
/*-FDEF E*/
{
#if XMK_MAX_SIGNALS<255
X_REGISTER unsigned char i ;
#else
X_REGISTER int i ;
#endif
#ifdef XMK_ADD_PRINTF_QUEUE
XMK_FUNCTION("xmk_InitQueue");
#endif
#ifdef XMK_USE_MAX_ERR_CHECK
xmk_InitState = 2; /* Queue is initialized */
#endif
/*
** Initialize Queue memory ...
*/
(void)memset ((void xmk_RAM_ptr) xmk_SignalArrayVar , 0, sizeof (xmk_SignalArrayVar ));
/*
** Initialize all the pointers
*/
xmk_FreeListPointer = (T_E_SIGNAL xmk_RAM_ptr) NULL ;
#ifdef XMK_USE_PREEMPTIVE
XMK_QUEUE_ADR = (T_E_SIGNAL xmk_RAM_ptr xmk_RAM_ptr) NULL ;
XMK_CURRENTSIGNAL_ADR = (T_E_SIGNAL xmk_RAM_ptr xmk_RAM_ptr) NULL ;
#else
XMK_QUEUE = (T_E_SIGNAL xmk_RAM_ptr) NULL ;
XMK_CURRENTSIGNAL = (T_E_SIGNAL xmk_RAM_ptr) NULL ;
#endif
XMK_Q_INIT_MAX
/*
** Insert all the signals in the free-list
*/
for( i = 0; i < XMK_MAX_SIGNALS; i++ )
{
xmk_FreeSignal( ( xmk_T_MESSAGE xmk_RAM_ptr )&xmk_SignalArrayVar [ i ] ) ;
} /* END FOR */
#ifdef XMK_ADD_PRINTF_QUEUE
XMK_TRACE_EXIT("xmk_InitQueue");
#endif
} /* END OF FUNCTION */
/*+FHDR E*/
/*
+------------------------------------------------------------------------------+
| Functionname : xmk_FirstSignal |
| Author : S&P Media GmbH Germany |
+------------------------------------------------------------------------------+
| |
| Description : |
| The first signal in the current queue, which is the one with the highest |
| priority, is copied to the pointer to currently treated signal and |
| returned to the caller. |
| |
| The functions returns a pointer to the first signal in the queue or NULL, |
| if there are no signals in the queue. |
| |
| Parameter : - |
| |
| Return : pointer to first signal in queue |
| (NULL, if no signals in queue) |
| |
+------------------------------------------------------------------------------+
*/
/*-FHDR E*/
/*+FDEF E*/
#ifndef XNOPROTO
xmk_T_MESSAGE xmk_RAM_ptr xmk_FirstSignal( void )
#else
xmk_T_MESSAGE xmk_RAM_ptr xmk_FirstSignal( )
#endif
/*-FDEF E*/
{
#ifdef XMK_ADD_PRINTF_QUEUE
XMK_FUNCTION("xmk_FirstSignal");
#endif
XMK_BEGIN_CRITICAL_PATH;
XMK_CURRENTSIGNAL = XMK_QUEUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -