?? tx_br.c
字號:
/**************************************************************************/
/* */
/* Copyright (c) 1996-2000 by Express Logic Inc. */
/* */
/* This software is copyrighted by and is the sole property of Express */
/* Logic, Inc. All rights, title, ownership, or other interests */
/* in the software remain the property of Express Logic, Inc. This */
/* software may only be used in accordance with the corresponding */
/* license agreement. Any unauthorized use, duplication, transmission, */
/* distribution, or disclosure of this software is expressly forbidden. */
/* */
/* This Copyright notice may not be removed or modified without prior */
/* written consent of Express Logic, Inc. */
/* */
/* Express Logic, Inc. reserves the right to modify this software */
/* without notice. */
/* */
/* Express Logic, Inc. */
/* 11440 West Bernardo Court info@expresslogic.com */
/* Suite 366 http://www.expresslogic.com */
/* San Diego, CA 92127 */
/* */
/**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** ThreadX Component */
/** */
/** Block Pool (BLO) */
/** */
/**************************************************************************/
/**************************************************************************/
#define TX_SOURCE_CODE
/* Include necessary system files. */
#include "tx_api.h"
#include "tx_thr.h"
#include "tx_tim.h"
#include "tx_blo.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_block_release PORTABLE C */
/* 3.0f */
/* AUTHOR */
/* */
/* William E. Lamie, Express Logic, Inc. */
/* */
/* DESCRIPTION */
/* */
/* This function returns a previously allocated block to its */
/* associated memory block pool. */
/* */
/* INPUT */
/* */
/* block_ptr Pointer to memory block */
/* */
/* OUTPUT */
/* */
/* TX_SUCCESS Successful completion status */
/* */
/* CALLS */
/* */
/* _tx_timer_deactivate Deactivate timer routine */
/* _tx_thread_resume Resume thread service */
/* _tx_thread_system_return Return to system routine */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 12-31-1996 William E. Lamie Initial Version 3.0 */
/* 11-11-1997 William E. Lamie Modified comment(s), */
/* resulting in version 3.0b. */
/* 03-01-1998 William E. Lamie Optimized post RESTORE */
/* processing, resulting in */
/* version 3.0d. */
/* 01-01-1999 William E. Lamie Modified comment(s), */
/* resulting in version 3.0e. */
/* 11-01-1999 William E. Lamie Modified comment(s), */
/* added logic to track events,*/
/* resulting in version 3.0f. */
/* */
/**************************************************************************/
UINT _tx_block_release(VOID *block_ptr)
{
TX_INTERRUPT_SAVE_AREA
REG_1 TX_BLOCK_POOL *pool_ptr; /* Pool pointer */
REG_2 TX_THREAD *thread_ptr; /* Working thread pointer */
REG_3 CHAR_PTR work_ptr; /* Working block pointer */
/* Disable interrupts to put this block back in the pool. */
TX_DISABLE
/* Pickup the pool pointer which is just previous to the starting
address of the block that the caller sees. */
work_ptr = ((CHAR_PTR) block_ptr) - sizeof(CHAR_PTR);
pool_ptr = *((TX_BLOCK_POOL_PTR *) work_ptr);
/* Log this kernel call. */
TX_EL_BLOCK_RELEASE_INSERT
/* Determine if there are any threads suspended on the block pool. */
thread_ptr = pool_ptr -> tx_block_pool_suspension_list;
if (thread_ptr)
{
/* Remove the suspended thread from the list. */
/* See if this is the only suspended thread on the list. */
if (thread_ptr == thread_ptr -> tx_suspended_next)
{
/* Yes, the only suspended thread. */
/* Update the head pointer. */
pool_ptr -> tx_block_pool_suspension_list = TX_NULL;
}
else
{
/* At least one more thread is on the same expiration list. */
/* Update the list head pointer. */
pool_ptr -> tx_block_pool_suspension_list = thread_ptr -> tx_suspended_next;
/* Update the links of the adjacent threads. */
(thread_ptr -> tx_suspended_next) -> tx_suspended_previous =
thread_ptr -> tx_suspended_previous;
(thread_ptr -> tx_suspended_previous) -> tx_suspended_next =
thread_ptr -> tx_suspended_next;
}
/* Decrement the suspension count. */
pool_ptr -> tx_block_pool_suspended_count--;
/* Prepare for resumption of the first thread. */
/* Clear cleanup routine to avoid timeout. */
thread_ptr -> tx_suspend_cleanup = TX_NULL;
/* Temporarily disable preemption. */
_tx_thread_preempt_disable++;
/* Restore interrupts. */
TX_RESTORE
/* Return this block pointer to the suspended thread waiting for
a block. */
*((CHAR_PTR *) thread_ptr -> tx_additional_suspend_info) = (CHAR_PTR) block_ptr;
/* Deactivate the timeout timer if necessary. */
if (thread_ptr -> tx_thread_timer.tx_list_head)
{
/* Deactivate the thread's timeout timer. */
_tx_timer_deactivate(&(thread_ptr -> tx_thread_timer));
}
else
{
/* Clear the remaining time to ensure timer doesn't get activated. */
thread_ptr -> tx_thread_timer.tx_remaining_ticks = 0;
}
/* Put return status into the thread control block. */
thread_ptr -> tx_suspend_status = TX_SUCCESS;
/* Resume thread. */
if (_tx_thread_resume(thread_ptr))
/* Preemption is required, transfer control back to
system. */
_tx_thread_system_return();
/* Return success. */
return(TX_SUCCESS);
}
else
{
/* No thread is suspended for a memory block. */
/* Put the block back in the available list. */
*((CHAR_PTR *) work_ptr) = pool_ptr -> tx_block_pool_available_list;
/* Adjust the head pointer. */
pool_ptr -> tx_block_pool_available_list = work_ptr;
/* Increment the count of available blocks. */
pool_ptr -> tx_block_pool_available++;
}
/* Restore interrupts. */
TX_RESTORE
/* Return completion status. */
return(TX_SUCCESS);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -