📄 em.c
字号:
/************************************************************************/
/* */
/* Copyright 1990-1992 by Accelerated Technology */
/* */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the */
/* subject matter of this material. All manufacturing, reproduction, */
/* use, and sales rights pertaining to this subject matter are */
/* governed by the license agreement. The buyer or recipient of this */
/* package, implicitly accepts the terms of the license. */
/* */
/************************************************************************/
/************************************************************************/
/* */
/* FILE DESCRIPTION */
/* */
/* This file contains routines that facilitate event management */
/* using event groups. */
/* */
/* ROUTINES */
/* */
/* EM_Initialize Event Manager Initialization*/
/* EM_Place_On_List Place on suspension list */
/* EM_Remove_From_List Remove from suspension list */
/* EM_Set_Events Set event flags of a group */
/* EM_Check_Events Check if events are present */
/* EM_Wait_For_Events Wait for events */
/* EM_Max_Event_Groups Returns the maximum */
/* number of event groups */
/* */
/* NOTES */
/* */
/* Routines except for EM_Max_Event_Groups expect that interrupts */
/* are locked out upon invocation. */
/* */
/************************************************************************/
/* Define necessary include files. */
#include "nu_defs.h" /* General constants */
#include "in_extr.h" /* Initialize references */
#include "em_defs.h" /* Data structure defns */
#include "sk_extr.h" /* Scheduler routine defs */
/* Define global data structures to the resource manager. */
/* The pointer "EM_ECB_List" is used to point to the list of
sequentially allocated Event Control Blocks (ECBs). */
struct EM_EVENT_CONTROL_STRUCT *EM_ECB_List;
/* The signed variable "EM_Total_Event_Groups" contains the total number of
system event groups, as derived from the queue definition list. */
signed int EM_Total_Event_Groups;
/* Define internal function prototypes. */
void EM_Place_On_List(struct EM_SUSPENSION_STRUCT **ptr_head_ptr,
struct EM_SUSPENSION_STRUCT **ptr_tail_ptr,
struct EM_SUSPENSION_STRUCT *suspend_ptr);
void EM_Remove_From_List(struct EM_SUSPENSION_STRUCT **ptr_head_ptr,
struct EM_SUSPENSION_STRUCT **ptr_tail_ptr,
struct EM_SUSPENSION_STRUCT *suspend_ptr);
/************************************************************************/
/* */
/* FUNCTION "EM_Initialize" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function is used to allocate and initialize all of the */
/* event control blocks and the total number of event groups */
/* variable. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* INP_Initialize High level initialization */
/* */
/* ROUTINES CALLED */
/* */
/* INP_Memory_Alloc Allocate initial memory */
/* */
/* INPUTS */
/* */
/* IN_System_Event_Groups Total System event groups */
/* */
/* OUTPUTS */
/* */
/* EM_ECB_List[] Resource Control Blocks */
/* EM_Total_Event_Groups Total number of event groups*/
/* */
/************************************************************************/
void EM_Initialize(unsigned int system_event_groups)
{
int i; /* Working variable */
int bytes; /* Number of bytes to alloc */
/* Initialize the event management variables. Save the total number
of event groups into a global variable. */
EM_Total_Event_Groups = system_event_groups;
/* If there are any system event groups, allocate and initialize the
associated Event Control Block (ECB) for each event group. */
if (EM_Total_Event_Groups)
{
/* Allocate memory for all of the ECBs. */
bytes = sizeof(struct EM_EVENT_CONTROL_STRUCT) * EM_Total_Event_Groups;
EM_ECB_List = (struct EM_EVENT_CONTROL_STRUCT *)
INP_Memory_Alloc(bytes);
}
/* Initialize each ECB. This includes clearing all of the event flags of
each group. */
for (i = 0; i < EM_Total_Event_Groups; i++)
{
/* Initialize the ECB entry. */
EM_ECB_List[i].em_event_flags = 0;
/* Initialize the wait pointers. */
EM_ECB_List[i].em_wait_head = NU_NULL;
EM_ECB_List[i].em_wait_tail = NU_NULL;
}
} /* end of EM_Initialize */
/************************************************************************/
/* */
/* FUNCTION "EM_Place_On_List" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function is used to link a suspension structure on a */
/* specified linked list. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* EM_Wait_For_Events Wait for system events */
/* */
/* ROUTINES CALLED */
/* */
/* None */
/* */
/* INPUTS */
/* */
/* ptr_head_ptr Pointer to list head ptr */
/* ptr_tail_ptr Pointer to list tail ptr */
/* suspend_ptr Pointer to suspend block */
/* */
/* OUTPUTS */
/* */
/* Suspension List */
/* */
/************************************************************************/
void EM_Place_On_List(struct EM_SUSPENSION_STRUCT **ptr_head_ptr,
struct EM_SUSPENSION_STRUCT **ptr_tail_ptr,
struct EM_SUSPENSION_STRUCT *suspend_ptr)
{
/* Determine if there is another suspension block to update. */
if (*ptr_tail_ptr != NU_NULL)
{
/* Yup, there are others currently suspended, place the new
suspension request at the end. */
(*ptr_tail_ptr) -> em_next_susp = suspend_ptr;
suspend_ptr -> em_prev_susp = *ptr_tail_ptr;
suspend_ptr -> em_next_susp = NU_NULL;
*ptr_tail_ptr = suspend_ptr;
}
else
{
/* Place the suspension request right up front. */
*ptr_head_ptr = suspend_ptr;
*ptr_tail_ptr = suspend_ptr;
suspend_ptr -> em_prev_susp = NU_NULL;
suspend_ptr -> em_next_susp = NU_NULL;
}
} /* end of EM_Place_On_List */
/************************************************************************/
/* */
/* FUNCTION "EM_Remove_From_List" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function is used to unlink a suspension structure from a */
/* specified linked list. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* EM_Release_Resource Release a resource */
/* */
/* ROUTINES CALLED */
/* */
/* None */
/* */
/* INPUTS */
/* */
/* ptr_head_ptr Pointer to list head ptr */
/* ptr_tail_ptr Pointer to list tail ptr */
/* suspend_ptr Pointer to suspend block */
/* */
/* OUTPUTS */
/* */
/* Suspension List */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -