/*---------------------------------------------------------------------------- *Function: CMM_Close *Parameters: OpenHandle : *Return Value: True/False *Implementation Notes: This function closes the device context identified by OpenHandle -----------------------------------------------------------------------------*/ BOOL CMM_Close( DWORD OpenHandle ) { CODEC_MEM_CTX *CodecMem; DWORD ret; ALLOC_MEM_T *node, *tmp_node; int count=0; ret = LockCMMMutex(); if(!ret){ RETAILMSG(1, (TEXT("[CMM_Close] CMM Mutex Lock Fail\r\n"))); return FALSE; } CodecMem = (CODEC_MEM_CTX *)OpenHandle; printD("[%d][CMM Close] \n", CodecMem->inst_no); if(!CodecMem){ RETAILMSG(1, (TEXT("[CMM_Close] CMM Invalid Input Handle\r\n"))); UnlockCMMMutex(); return FALSE; } printD("[CMM_Close] CodecMem->inst_no : %d CodecMem->callerProcess : 0x%x\n", CodecMem->inst_no, CodecMem->callerProcess); __try { // release u_addr and v_addr accoring to inst_no for(node = AllocMemHead; node != AllocMemTail; node = node->next){ if(node->inst_no == CodecMem->inst_no){ tmp_node = node; node = node->prev; ReleaseAllocMem(tmp_node, CodecMem); } } } __except ( EXCEPTION_EXECUTE_HANDLER ) { RETAILMSG( 1, ( _T("CMM_Close:Exception in releasing memory\n")) ); return FALSE; } printD("[%d][CMM Close] MergeFragmentation\n", CodecMem->inst_no); MergeFragmentation(CodecMem->inst_no); ReturnInstanceNo(CodecMem->inst_no); free(CodecMem); UnlockCMMMutex(); return TRUE; }
static int s3c_cmm_release(struct inode *inode, struct file *file) { DWORD ret; CODEC_MEM_CTX *CodecMem; ALLOC_MEM_T *node, *tmp_node; ret = LockCMMMutex(); if(!ret){ LOG_MSG(LOG_ERROR, "s3c_cmm_release", "DD::CMM Mutex Lock Fail\r\n"); return -1; } CodecMem = (CODEC_MEM_CTX *)file->private_data; LOG_MSG(LOG_TRACE, "s3c_cmm_release", "[%d][CMM Close] \n", CodecMem->inst_no); if(!CodecMem){ LOG_MSG(LOG_ERROR, "s3c_cmm_close", "CMM Invalid Input Handle\r\n"); UnlockCMMMutex(); return -1; } LOG_MSG(LOG_TRACE, "s3c_cmm_close", "CodecMem->inst_no : %d\n", CodecMem->inst_no); // release u_addr and v_addr accoring to inst_no for(node = AllocMemHead; node != AllocMemTail; node = node->next){ if(node->inst_no == CodecMem->inst_no){ tmp_node = node; node = node->prev; ReleaseAllocMem(tmp_node, CodecMem); } } LOG_MSG(LOG_TRACE, "s3c_cmm_release", "[%d]instance MergeFragmentation\n", CodecMem->inst_no); MergeFragmentation(CodecMem->inst_no); ReturnInstanceNo(CodecMem->inst_no); kfree(CodecMem); UnlockCMMMutex(); return 0; }