📄 fm.c
字号:
block_ptr -> fm_prev_ptr = NU_NULL;
block_ptr -> fm_next_ptr = NU_NULL;
}
} /* end of FM_Place_On_List */
/************************************************************************/
/* */
/* FUNCTION "FM_Remove_From_List" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function is used to unlink a structure from a */
/* specified linked list. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* FM_Deallocate_Partition Deallocate a partition */
/* FM_Allocate_Partition Remove partition avail list */
/* */
/* ROUTINES CALLED */
/* */
/* None */
/* */
/* INPUTS */
/* */
/* ptr_head_ptr Pointer to list head ptr */
/* ptr_tail_ptr Pointer to list tail ptr */
/* block_ptr Pointer to block */
/* */
/* OUTPUTS */
/* */
/* Suspension List */
/* */
/************************************************************************/
void FM_Remove_From_List(struct FM_LIST_STRUCT **ptr_head_ptr,
struct FM_LIST_STRUCT **ptr_tail_ptr,
struct FM_LIST_STRUCT *block_ptr)
{
/* Determine if this block is still linked in. */
if ((block_ptr -> fm_prev_ptr != NU_NULL) ||
(block_ptr -> fm_next_ptr != NU_NULL) ||
(block_ptr == *ptr_head_ptr))
{
/* Check the previous pointers. */
if (block_ptr -> fm_prev_ptr != NU_NULL)
{
/* Link the previous suspension block to the next. */
(block_ptr -> fm_prev_ptr) -> fm_next_ptr =
block_ptr -> fm_next_ptr;
}
else
{
/* We are deleting the head node, adjust the head pointer. */
*ptr_head_ptr = block_ptr -> fm_next_ptr;
/* Adjust the head of the list. */
if (*ptr_head_ptr != NU_NULL)
(*ptr_head_ptr) -> fm_prev_ptr = NU_NULL;
}
/* Check the next pointers. */
if (block_ptr -> fm_next_ptr != NU_NULL)
{
/* Link the next suspension block to the previous. */
(block_ptr -> fm_next_ptr) -> fm_prev_ptr =
block_ptr -> fm_prev_ptr;
}
else
{
/* We are deleting the tail node, adjust the tail pointer. */
*ptr_tail_ptr = block_ptr -> fm_prev_ptr;
/* Adjust the tail of the list. */
if (*ptr_tail_ptr != NU_NULL)
(*ptr_tail_ptr) -> fm_next_ptr = NU_NULL;
}
/* Reset the pointers of the removed suspension block. */
block_ptr -> fm_next_ptr = NU_NULL;
block_ptr -> fm_prev_ptr = NU_NULL;
}
} /* end FM_Remove_From_List */
/************************************************************************/
/* */
/* FUNCTION "FM_Allocate_Partition" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function allocates a partition from the specified */
/* partition id. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* Service routines that request partition allocation */
/* */
/* ROUTINES CALLED */
/* */
/* FM_Remove_From_List Remove partition avail list */
/* SKP_Get_Task_ID Get the current task ID */
/* */
/* INPUTS */
/* */
/* partition_id Partition Identification */
/* */
/* OUTPUTS */
/* */
/* return(memory_ptr) Return memory pointer */
/* */
/************************************************************************/
unsigned int *FM_Allocate_Partition(signed int partition_id)
{
struct FM_BLOCK_CONTROL_STRUCT
*PCB_ptr; /* Pointer to PCB entry */
struct FM_BLOCK_HEADER_STRUCT
*header_ptr; /* Pointer to partition hdr */
unsigned int *memory_ptr; /* Pointer to memory */
/* Point to the partition control block. */
PCB_ptr = &FM_PCB_List[partition_id];
/* See if there any partitions left. */
if (PCB_ptr -> fm_available_head != NU_NULL)
{
/* Yes, there are more partitions. */
/* Point to the partition in the front. */
header_ptr = PCB_ptr -> fm_available_head;
/* Remove this partition from the available list. */
FM_Remove_From_List(
(struct FM_LIST_STRUCT **) &(PCB_ptr -> fm_available_head),
(struct FM_LIST_STRUCT **) &(PCB_ptr -> fm_available_tail),
(struct FM_LIST_STRUCT *) header_ptr);
/* Mark the header as in use. */
header_ptr -> fm_in_use = NU_TRUE;
/* Save off the task id. */
header_ptr -> fm_task_id = SKP_Get_Task_ID();
/* Set up the memory pointer. */
memory_ptr = ((unsigned int *) header_ptr) +
(sizeof(struct FM_BLOCK_HEADER_STRUCT)/sizeof(unsigned
int));
/* Decrement the number of free partitions. */
PCB_ptr -> fm_free_partitions--;
}
else
/* Set the memory pointer to NULL in order to indicate that there
are no more partitions available at this time. */
memory_ptr = NU_NULL;
/* Return the memory pointer to the caller. */
return(memory_ptr);
} /* end of FM_Allocate_Partition */
/************************************************************************/
/* */
/* FUNCTION "FM_Deallocate_Partition" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function deallocates a partition from the specified list, */
/* if the partition is currently in use (allocated). */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* Service routines that request partition deallocation */
/* */
/* ROUTINES CALLED */
/* */
/* FM_Place_On_List Place partition on avail lst*/
/* FM_Remove_From_List Remove from wait list */
/* SKP_Ready_Task Place the task on ready lst */
/* SKD_Leave_Task Leave the task if necessary */
/* */
/* INPUTS */
/* */
/* memory_ptr Pointer to partition */
/* */
/* OUTPUTS */
/* */
/* return(status) */
/* */
/************************************************************************/
signed int FM_Deallocate_Partition(unsigned int *memory_ptr)
{
struct FM_BLOCK_CONTROL_STRUCT
*PCB_ptr; /* Pointer to PCB entry */
struct FM_BLOCK_HEADER_STRUCT
*header_ptr; /* Pointer to partition hdr */
struct FM_SUSPENSION_STRUCT
*suspend_ptr; /* Pointer to suspension */
unsigned int *temp_ptr; /* Temporary pointer */
signed int status; /* Status of request */
/* Move the partition pointer back to the start of the partition header. */
temp_ptr = memory_ptr -
(sizeof(struct FM_BLOCK_HEADER_STRUCT)/sizeof(unsigned int));
/* Use a partition header pointer. */
header_ptr = (struct FM_BLOCK_HEADER_STRUCT *) temp_ptr;
/* Check to see if the partition is in use. Additionally, check to see
if the header has been corrupted. */
if ((header_ptr -> fm_in_use == NU_TRUE) &&
(header_ptr -> fm_pattern_1 == TOP_PATTERN) &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -