コード例 #1
0
ファイル: stack.c プロジェクト: blueskycoco/wang-linux
/**
 * \date 30-May-2006\n
 * \brief initialize stack object
 *
 * Function Scope \e Public.\n
 * \param pStack    - pointer to the Stack_t structure\n
 * \param hOS       - handle to the OS object\n
 * \param uElemSize - size of a one stack element\n
 * \param uDep      - stack depth\n
 * \param pBuf      - pointer to the stack buffer; if NULL a memory for the stack buffer will be dynamically allocated\n
 * \param fCpy      - pointer to function copying the stack element; if NULL a default copy function will be used\n
 * \return 0 - on success, -1 - on failure\n
 */
unsigned stackInit
    (Stack_t * pStack,
     TI_HANDLE hOs,
     unsigned uElemSize,
     unsigned uDep,
     void *pBuf, void (*fCpy) (TI_HANDLE, void *, void *, unsigned)
    ) {
	pStack->hOs = hOs;
	pStack->uPtr = 0;
	pStack->uElemSize = uElemSize;
	pStack->uDep = uDep * uElemSize;

	if (pBuf) {
		pStack->pBuf = pBuf;
		pStack->bBuf = 0;
	}

	else {
		pStack->pBuf = _os_memoryAlloc(hOs, pStack->uDep);
		pStack->bBuf = TI_TRUE;
	}

	if (fCpy)
		pStack->fCpy = fCpy;
	else
		pStack->fCpy = os_memoryCopy;

	return 0;
}
コード例 #2
0
/****************************************************************************************
 *                        os_memoryCAlloc()
 ****************************************************************************************
DESCRIPTION:    Allocates an array in memory with elements initialized to 0.

ARGUMENTS:		OsContext	-	our adapter context.
				Number		-	Number of elements
				Size		-	Length in bytes of each element

RETURN:			None

NOTES:
*****************************************************************************************/
void*
_os_memoryCAlloc(
    TI_HANDLE OsContext,
    TI_UINT32 Number,
    TI_UINT32 Size,
    TI_UINT32 FileNbr,
    TI_UINT32 LineNbr
)
{
	void* pAllocatedMem;
	TI_UINT32 MemSize;

#ifdef TI_MEM_ALLOC_TRACE
	os_printf("MTT:%s:%d ::os_memoryCAlloc(0x%p, %lu, %lu) : %lu\n",__FUNCTION__,__LINE__,OsContext,Number,Size,Number*Size);
#endif
	MemSize = Number * Size;

	pAllocatedMem = _os_memoryAlloc(OsContext, MemSize, FileNbr, LineNbr);

	if (!pAllocatedMem)
		return NULL;

	memset(pAllocatedMem,0,MemSize);

	return pAllocatedMem;
}