ULONG  VOS_CreateSemaphore( ULONG ulInitValue ,VOS_Sem **pstVosSem)
{
    VOS_Sem *pstVosSemTemp = VOS_NULL ;
    LONG lResult = VOS_OK ; 

    pstVosSemTemp = (VOS_Sem *) VOS_malloc(sizeof(VOS_Sem));
    if ( VOS_NULL == pstVosSemTemp )
    {
        return VOS_ERR_MEM ;
    }

#if VOS_APP_OS == VOS_OS_LINUX
    lResult = sem_init(&pstVosSemTemp->sem, 0, ulInitValue );
    if ( VOS_OK != lResult ) 
    {
        VOS_free(pstVosSemTemp);
        return VOS_ERR_SYS ;
    }
#elif VOS_APP_OS == VOS_OS_WIN32
    //pstVosSemTemp->sem = CreateSemaphore(NULL,(long)ulInitValue,(long)ulInitValue,NULL);
    pstVosSemTemp->sem = CreateSemaphore(NULL, (long)ulInitValue, (long)ulInitValue+1, NULL);
    if (NULL == pstVosSemTemp->sem)
    {
		VOS_free(pstVosSemTemp);
        return VOS_ERR_SYS ;
    }
    (void)lResult;
#endif
    *pstVosSem = pstVosSemTemp;

    return VOS_OK ;
}
Beispiel #2
0
	VOS_Mutex *VOS_CreateMutex(void )
	{
		ULONG ulResult = VOS_OK ;

		VOS_Mutex *pstMutex = VOS_NULL ;

		pstMutex = (VOS_Mutex *) VOS_malloc (sizeof(VOS_Mutex));//lint !e838
		if (NULL == pstMutex)
		{
			return NULL;
		}
    
		#if VOS_APP_OS == VOS_OS_LINUX
		ulResult = (ULONG)pthread_mutex_init( &pstMutex->mutex, 0);
		if( VOS_OK != ulResult )
		{
			VOS_free( pstMutex );        
			return VOS_NULL ;    
		}
		#elif VOS_APP_OS == VOS_OS_WIN32
		pstMutex->mutex = CreateMutex(NULL,0,NULL);
		if (NULL == pstMutex->mutex)
		{
			VOS_free( pstMutex );        
			return VOS_NULL ;    
		}
		#endif

		return pstMutex ;
	}//lint !e529
ULONG  VOS_CreateSemaphore( ULONG ulInitValue ,VOS_Sem **pstVosSem)
{
    VOS_Sem *pstVosSemTemp = VOS_NULL ;   

    pstVosSemTemp = (VOS_Sem *) VOS_malloc(sizeof(VOS_Sem));//lint !e838
    if ( VOS_NULL == pstVosSemTemp )
    {
        return VOS_ERR_MEM ;
    }

#if VOS_APP_OS == VOS_OS_LINUX
	LONG lResult = VOS_OK ; 
    lResult = sem_init(&pstVosSemTemp->sem, 0, ulInitValue );
    if ( VOS_OK != lResult ) 
    {
        VOS_free(pstVosSemTemp);
        return VOS_ERR_SYS ;
    }
#elif VOS_APP_OS == VOS_OS_WIN32
    pstVosSemTemp->sem = CreateSemaphore(NULL,(LONG)ulInitValue,(LONG)ulInitValue,NULL);
    if (NULL == pstVosSemTemp->sem)
    {
        VOS_free(pstVosSemTemp);
        return VOS_ERR_SYS ;
    }
#endif
    *pstVosSem = pstVosSemTemp;

    return VOS_OK ;
}//lint !e529
/*******************************************************************************
  Function:       CNVSTimer::exit()
  Description:    退出定时检测线程
  Calls:            
  Called By:      
  Input:          无 
  Output:         无 
  Return:         无 
*******************************************************************************/
void CNVSTimer::exit()
{
    if(NULL == m_pVosThread)
    {
        IVS_RUN_LOG_ERR("NVSTimer exit: m_pVosThread is null");
        return;
    }

    //先停止线程
    this->m_bExit = VOS_TRUE;
    
    errno = 0;   
    long ret_val = VOS_ThreadJoin(m_pVosThread);
    if (ret_val != VOS_OK)
    {
        IVS_RUN_LOG_ERR("Wait timer thread exit failed. ret_val(%ld). error(%d):%s", ret_val, errno, strerror(errno));
    }

    //释放内存
    VOS_free(m_pVosThread);
    m_pVosThread = VOS_NULL;

    //再释放资源
    clearTimer();

    //释放锁
    (void)VOS_DestroyMutex(m_pMutexListOfTrigger);
    m_pMutexListOfTrigger = VOS_NULL;

    IVS_DBG_LOG("FILE(%s)LINE(%d): CNVSTimer::exit: exit complete.", _TIMER_FL_);
  
    return;
};
ULONG  VOS_CreateThread( VOS_THREAD_FUNC pfnThread, VOID *args, VOS_Thread **pstVosThread,ULONG ulStackSize)
{    
    VOS_Thread *pstThread = (VOS_Thread*)VOS_malloc(sizeof(VOS_Thread)); 
    if( VOS_NULL == pstThread )
    {
        return VOS_ERR_MEM; 
    }
    
#if VOS_APP_OS == VOS_OS_LINUX
    if ( pthread_attr_init(&pstThread->attr) != 0 )
    {
        VOS_free(pstThread);        
        return VOS_ERR ;
    }    

    pthread_attr_setdetachstate(&pstThread->attr, PTHREAD_CREATE_JOINABLE );

    if( 0 == ulStackSize )
    {
        ulStackSize = VOS_DEFAULT_STACK_SIZE;
    }    
    if (pthread_attr_setstacksize(&pstThread->attr, (size_t)ulStackSize))
    {
        VOS_free(pstThread);    
        return VOS_ERR ;
    }    

    if ( pthread_create(&pstThread->pthead, &pstThread->attr, pfnThread, args) != 0 ) 
    {
        VOS_free(pstThread);
        return VOS_ERR ;
    }
#elif VOS_APP_OS == VOS_OS_WIN32
    pstThread->pthead = CreateThread(NULL,ulStackSize,pfnThread,args,0,&pstThread->ptheadID);
    if (NULL == pstThread->pthead)
    {
        VOS_free(pstThread);
        return VOS_ERR ;
    }
#endif
    *pstVosThread = pstThread ;
    
    return VOS_OK;
}
Beispiel #6
0
	ULONG VOS_DestroyMutex( VOS_Mutex *pstMutex )
	{
		ULONG ulResult = VOS_OK ;

		#if VOS_APP_OS == VOS_OS_LINUX
		pthread_mutex_destroy( &pstMutex->mutex );
		#elif VOS_APP_OS == VOS_OS_WIN32
		CloseHandle(pstMutex->mutex);
		#endif
		VOS_free( pstMutex );

		return ulResult ;
	}
VOID VOS_DeleteThread( VOS_Thread *pstVosThread )
{
    //如果线程指针为空,则直接返回
    if(NULL == pstVosThread)
    {
        return;
    }

    VOS_StopThread( pstVosThread );

    VOS_free( pstVosThread );
    return ;
}
ULONG VOS_DestroySemaphore( VOS_Sem *pstVosSem )
{
    if ( VOS_NULL == pstVosSem ) 
    {
        return VOS_ERR_PARAM ;
    }

#if VOS_APP_OS == VOS_OS_LINUX
    sem_destroy( &pstVosSem->sem );
#elif VOS_APP_OS == VOS_OS_WIN32
    (void)CloseHandle(pstVosSem->sem);
#endif

    VOS_free( pstVosSem );	

    return VOS_OK ;
}
IVS_INT32 CSDKDecoderMgr::CleanupSDK()
{
	if(!m_bInit)
	{
		return IVS_TVWALL_INIT_NO;
	}
	m_bThreadExit = TRUE;
	m_bInit = FALSE;
	VOS_ThreadJoin(m_pVosThread);
	if(NULL!=m_pVosThread)
	{
		VOS_free(m_pVosThread);
		m_pVosThread = NULL;
	}
	//清除登录信息
	(void)VOS_MutexLock(m_pDecoderInfoMapMutex);
	for(SDK_DECODER_INFO_MAP::iterator ite=m_decoderInfoMap.begin();ite!=m_decoderInfoMap.end();ite++)
	{
		SDK_DECODER_INFO* pInfo = dynamic_cast<SDK_DECODER_INFO*>(ite->second);//lint !e611
		if(NULL!=pInfo)
		{
			//////////////////////////////////////////////////////////////////////////
			//2013-1-28 高书明 先屏蔽HWPuSDK相关函数,与BP的dll冲突
			//(void)IVS_PU_Logout(pInfo->ulIdentifyID);
			//////////////////////////////////////////////////////////////////////////
			pInfo->bOnline = FALSE;
			pInfo->ulIdentifyID = 0;
		}
	}
	(void)VOS_MutexUnlock(m_pDecoderInfoMapMutex);
	m_pCallBackFun = NULL;
	m_pUserData = NULL;
	//////////////////////////////////////////////////////////////////////////
	//2013-1-28 高书明 先屏蔽HWPuSDK相关函数,与BP的dll冲突
	//BOOL bSucc = IVS_PU_Cleanup();
	//return bSucc ? IVS_SUCCEED:IVS_FAIL;
	return IVS_FAIL;
	//////////////////////////////////////////////////////////////////////////
}
Beispiel #10
0
/*******************************************************************************
  Function:       CNVSTimer::~CNVSTimer()
  Description:    析构函数
  Calls:            
  Called By:      
  Input:          无
  Output:         无 
  Return:         无
*******************************************************************************/
CNVSTimer::~CNVSTimer()
{
    try
    {
        if(NULL != m_plistTrigger)
        {
            ListOfTriggerIte itListOfTrigger = m_plistTrigger->begin();
            IVS_DBG_LOG("FILE(%s)LINE(%d): CNVSTimer::~CNVSTimer: thread = %u", 
                _TIMER_FL_, VOS_pthread_self());
            while(itListOfTrigger != m_plistTrigger->end())
            {
				CTimerItem* pTimerItem = (*itListOfTrigger).second;//lint !e64
                VOS_DELETE(pTimerItem);
				pTimerItem = NULL;
                ++itListOfTrigger;
            };
            m_plistTrigger->clear();
            VOS_DELETE(m_plistTrigger);
            m_plistTrigger = NULL;
        }
    
        if(m_pVosThread != NULL)
        {
            VOS_free(m_pVosThread);
        }
        m_pVosThread = NULL;

        if(m_pMutexListOfTrigger != NULL)
        {
            (void)VOS_DestroyMutex(m_pMutexListOfTrigger);
        }
        m_pMutexListOfTrigger = NULL;
    }
    catch (...)
    {
    }
};
CSDKDecoderMgr::~CSDKDecoderMgr(void)
{
	m_bThreadExit = TRUE;
	m_pCallBackFun = NULL;
	m_pUserData = NULL;

	
	VOS_ThreadJoin(m_pVosThread);
	try
	{
		CSDKDecoderMgr::RemoveDecMgrObj(this);
		RemoveDecoderInfo();
	}
	catch (...)
	{
	}	
	VOS_DestroyMutex(m_pDecoderInfoMapMutex);
	m_pDecoderInfoMapMutex = NULL;
	if(NULL!=m_pVosThread)
	{
		VOS_free(m_pVosThread);
		m_pVosThread = NULL;
	}
}