ClRcT 
clLogUtilLibInitialize(void)
{
    ClRcT  rc = CL_OK;
    ClCharT *pEOName = NULL;
    if( gUtilLibInitialized == CL_TRUE )
    {
        return CL_OK;
    }
    rc = clOsalMutexErrorCheckInit(&gLogMutex);
    if( CL_OK != rc )
    {
        fprintf(stderr, "Mutex init failed rc[0x %x]\n", rc);
        return rc;
    }
    rc = clOsalCondInit(&gLogCond);
    if( CL_OK != rc )
    {
        fprintf(stderr, "Cond init failed rc[0x %x]\n", rc);
        clOsalMutexDestroy(&gLogMutex);
        return rc;
    }
    pEOName = CL_EO_NAME;
    if(pEOName && !strncasecmp(pEOName, "LOG", 3))
    {
        gClLogServer = CL_TRUE;
    }

    clLogDebugFilterInitialize();

    gUtilLibInitialized = CL_TRUE;
    rc = clOsalTaskCreateAttached((ClCharT *)CL_LOG_UTIL_TASK_NAME, CL_OSAL_SCHED_OTHER,
            CL_OSAL_THREAD_PRI_NOT_APPLICABLE, CL_OSAL_MIN_STACK_SIZE,
            clLogDeferredHandler, NULL, &taskId);
    if( CL_OK != rc )
    {
        fprintf(stderr, "Thread creation failed rc[0x %x]", rc);
        clOsalCondDestroy(&gLogCond);
        clOsalMutexDestroy(&gLogMutex);
        return rc;
    }
    
    return CL_OK;
}
ClRcT clEoQueueDeleteSync(ClIocPriorityT priority, ClBoolT force)
{
    ClEoQueueT *pQueue = NULL;
    ClRcT rc = CL_EO_RC(CL_ERR_INVALID_PARAMETER);

    if(priority >= CL_IOC_MAX_PRIORITIES)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Invalid parameter\n"));
        goto out;
    }

    rc = CL_EO_RC(CL_ERR_NOT_EXIST);

    CL_EO_QUEUE_LOCK(&gClEoQueueMutex);
    if(!(pQueue = gpClEoQueues[priority]))
    {
        CL_EO_QUEUE_UNLOCK(&gClEoQueueMutex);
        CL_DEBUG_PRINT(CL_DEBUG_WARN, ("Queue priority:%d doesnt exist\n",priority));
        goto out;
    }
    gpClEoQueues[priority] = NULL;
    CL_EO_QUEUE_UNLOCK(&gClEoQueueMutex);

    /*Quiesce the queue*/
    pQueue->state = CL_EO_QUEUE_STATE_QUIESCED;

    /*Delete the thread pool associated with the queue*/
    rc = CL_OK;
    if(pQueue->pThreadPool)
    {
        rc = clThreadPoolDeleteSync((ClThreadPoolHandleT)pQueue->pThreadPool, 
                                    force);
        if(rc != CL_OK)
        {
            CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Error deleting thread pool.rc=0x%x\n",rc));
        }
    }
    clOsalMutexDestroy(&pQueue->mutex);
    clOsalCondDestroy(&pQueue->cond);
    clHeapFree(pQueue);
    out:
    return rc;
} 
ClRcT
clLogFlushIntervalThreadCreate(ClLogSvrStreamDataT  *pSvrStreamData, 
                               ClOsalTaskIdT        *pTaskId)
{
    ClRcT  rc = CL_OK;

    /* create a mutex for this thread, no need to destroy this mutex as
     * memory is not allocated for this mutex */
    rc = clOsalMutexInit_L(&pSvrStreamData->flushIntervalMutex);
    if( CL_OK != rc )
    {
        clLogError("SVR", "FLU", "Mutex creation failed rc [0x %x]", rc);
        return rc;
    }
    rc = clOsalCondInit_L(&pSvrStreamData->flushIntervalCondvar);
    if( CL_OK != rc )
    {
        clLogError("SVR", "FLU", "Mutex creation failed rc [0x %x]", rc);
        clOsalMutexDestroy_L(&pSvrStreamData->flushIntervalMutex);
        return rc;
    }
    pSvrStreamData->flushIntervalThreadStatus =
        CL_LOG_FLUSH_INTERVAL_STATUS_ACTIVE;
    rc = clOsalTaskCreateAttached(pSvrStreamData->shmName.pValue,
            CL_OSAL_SCHED_OTHER, CL_OSAL_THREAD_PRI_NOT_APPLICABLE,
            CL_OSAL_MIN_STACK_SIZE, clLogFlushIntervalThread, 
            pSvrStreamData, pTaskId);
    if( CL_OK != rc )
    {
        clLogError("SVR", "FLU", "Creating thread for flush interval fails rc[0x %x]",
                rc);
        clOsalCondDestroy(&pSvrStreamData->flushIntervalCondvar);
        clOsalMutexDestroy_L(&pSvrStreamData->flushIntervalMutex);
        return rc;
    }
    return rc;
}
예제 #4
0
static void sendHashDeleteCallBack(ClCntKeyHandleT userKey,
                                   ClCntDataHandleT userData)
{
    ClRmdRecordSendT *rec = (ClRmdRecordSendT *) userData;
    CL_FUNC_ENTER();
    if (userData)
    {
        /*
         * The check on the flag is a must now since sync
         * path also invokes this code. Added as a fix to
         * Bug - 3748.
         */
        if (rec->flags & CL_RMD_CALL_ASYNC)
        {
            /*
             * cleanup for Async Info 
             */
            if (rec->recType.asyncRec.timerID)
            {
                clTimerDeleteAsync(&rec->recType.asyncRec.timerID);
            }
            
            clHeapFree(rec);
        }
        else
        {
            /* Before destroying the condition variable, make sure it is not being used in clOsalCondWait(). */
            clOsalCondSignal(&rec->recType.syncRec.syncCond);
            /*
             * cleanup for Sync Info
             */
            clOsalCondDestroy(&rec->recType.syncRec.syncCond);
        }
    }

    CL_FUNC_EXIT();
}
ClRcT
clLogUtilLibFinalize(ClBoolT  logLibInit)
{
    ClRcT  rc = CL_OK;
    /* Notify the thread to stop */
    rc = clOsalMutexLock(&gLogMutex);
    if( CL_OK != rc )
    {
        return rc;
    }
    gUtilLibInitialized = CL_FALSE;
    clLogDebugFilterFinalize();
    /* 
     * signalling to that guy to wake up
     */
    clOsalCondSignal(&gLogCond);
    clOsalMutexUnlock(&gLogMutex);
    /* Wait till that thread finishes its own job */
    clOsalTaskJoin(taskId);

    /*
     * This is hardcoded, have to find out the best way to solve this problem
     * once all the data have been flushed, log library will be finalized.
     */
    if( CL_TRUE == logLibInit )
    {	
    	clLogFinalize(1);
    }
    /*
     * just destroying provided, all initialed libraried will be
     * finalized by main EO function. 
     */
    clOsalCondDestroy(&gLogCond);
    clOsalMutexDestroy(&gLogMutex);
    return CL_OK;
}
예제 #6
0
static ClRcT initializeAmf(void)
{
    ClRcT         rc = CL_OK; 
    ClRcT         retCode;
    ClIocPhysicalAddressT notificationForComp = { CL_IOC_BROADCAST_ADDRESS, 0};
    
    clLogCompName = (ClCharT*) "MSG"; /* Override generated eo name with a short name for our server */
    clAppConfigure(&clEoConfig,clEoBasicLibs,clEoClientLibs);
  
    clMsgRegisterWithCpm();
     
    if(gClMsgInit == CL_TRUE)
    {
        rc = CL_MSG_RC(CL_ERR_INITIALIZED);
        clLogError("MSG", "INI", "The Message Service is already initialized. error code [0x%x].", rc);
        goto error_out;
    }
    
    gLocalAddress = clIocLocalAddressGet();
    gLocalPortId = CL_IOC_MSG_PORT;

    /* Initializing a database to maintain client information */
    rc = clHandleDatabaseCreate((void (*)(void*))NULL, &gMsgClientHandleDb);
     
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to initialize the handle database. error code [0x%x].", rc);
        goto error_out;
    }
    
    /* Initializing IDL for server to server and server to client communication. */
    rc = clMsgCommIdlInitialize();
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to initialize the IDL. error code [0x%x].", rc);
        goto error_out_2;
    }
    
    /* Initializing a database for maintaining queues. */
    rc = clMsgQueueInitialize();
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to initialize the queue databases. error code [0x%x].", rc);
        goto error_out_3;
    }
   
    rc = clMsgReceiverDatabaseInit();
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to initialize \"receiver database\". error code [0x%x].", rc);
        goto error_out_4;
    }

    rc = clOsalMutexInit(&gClMsgFinalizeLock);
    CL_ASSERT(rc == CL_OK);
    
    rc = clOsalCondInit(&gClMsgFinalizeCond);
    CL_ASSERT(rc == CL_OK);

    /* Initializing the Group-Information */
    rc = clOsalMutexInit(&gClGroupDbLock);
    CL_ASSERT(rc == CL_OK);

    rc = clCpmNotificationCallbackInstall(notificationForComp, &clMsgNotificationReceiveCallback, NULL, &gMsgNotificationHandle);
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to install the notification callback function. error code [0x%x].", rc);
        goto error_out_5;
    }
   
    /* Initializing the IDL generated code. */
    rc = clMsgIdlClientInstall();
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to install Server Table. error code [0x%x].", rc);
        goto error_out_6;
    }

    rc = clMsgIdlClientTableRegister(CL_IOC_MSG_PORT);
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to register Server Table. error code [0x%x].", rc);
        goto error_out_7;
    }

    rc = clMsgCltClientTableRegister(CL_IOC_MSG_PORT);
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to register Client Table. error code [0x%x].", rc);
        goto error_out_8;
    }

    rc = clMsgCltSrvClientInstall();
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to install Client Server Table. error code [0x%x].", rc);
        goto error_out_9;
    }
  
    rc = clMsgCltSrvClientTableRegister(CL_IOC_MSG_PORT);
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to register Client Server Table. error code [0x%x].", rc);
        goto error_out_10;
    }

    rc = clMsgFinalizeBlockInit();
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to initialize the msg-finalize blocker. error code [0x%x].", rc);
        goto error_out_11;
    }
   
    clMsgDebugCliRegister();

    rc = clOsalTaskCreateDetached("MsgCkptInitAsync", CL_OSAL_SCHED_OTHER, CL_OSAL_THREAD_PRI_NOT_APPLICABLE, 0,
                                 clMsgCachedCkptInitAsync, NULL);
    CL_ASSERT(rc == CL_OK);

    goto out;
error_out_11:
    retCode = clMsgCltSrvClientTableDeregister();
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to deregister Client Table. error code [0x%x].", retCode);
error_out_10:
    retCode = clMsgCltSrvClientUninstall();
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to destroy the just opened handle database. error code [0x%x].", retCode);
error_out_9:
    retCode = clMsgCltClientTableDeregister();
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to deregister Client Table. error code [0x%x].", retCode);
error_out_8:
    retCode = clMsgIdlClientTableDeregister();
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to deregister Server Table. error code [0x%x].", retCode);
error_out_7:
    retCode = clMsgIdlClientUninstall();
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to destroy the just opened handle database. error code [0x%x].", retCode);
error_out_6:
    retCode = clCpmNotificationCallbackUninstall(&gMsgNotificationHandle);
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to uninstall the notification callback function. error code [0x%x].", retCode);
error_out_5:
    retCode = clOsalMutexDestroy(&gClGroupDbLock);
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to destroy the group db mutex. error code [0x%x].", retCode);

    retCode = clOsalCondDestroy(&gClMsgFinalizeCond);
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to destroy the finalization condition. error code [0x%x].", retCode);

    retCode = clOsalMutexDestroy(&gClMsgFinalizeLock);
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to destroy the finalization mutex. error code [0x%x].", retCode);

    clMsgReceiverDatabaseFin();

error_out_4:
    retCode = clMsgQueueFinalize();
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to finalize the queue databases. error code [0x%x].", retCode);
error_out_3:
    clMsgCommIdlFinalize();
error_out_2:
    retCode = clHandleDatabaseDestroy(gMsgClientHandleDb);
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to destroy the handle database. error code [0x%x].", retCode);
error_out:
out:
    return rc;  
    
}//end of intializeAmf
ClRcT clEoQueueCreate(ClEoQueueHandleT *pHandle,
                      ClIocPriorityT priority,
                      ClThreadPoolModeT mode,
                      ClInt32T maxThreads,
                      ClInt32T threadPriority,
                      ClEoJobCallBackT pJobHandler,
                      ClPtrT pUserData
                      )
{
    ClEoQueueT *pQueue =NULL;
    ClThreadPoolHandleT threadPool=0;
    ClRcT rc = CL_EO_RC(CL_ERR_INVALID_PARAMETER);

    if(pHandle == NULL)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Invalid parameter\n"));
        goto out;
    }

    if( priority >= CL_IOC_MAX_PRIORITIES )
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Invalid priority %d\n",priority));
        goto out;
    }

    rc = CL_EO_RC(CL_ERR_OP_NOT_PERMITTED);

    CL_EO_QUEUE_LOCK(&gClEoQueueMutex);
    if(gpClEoQueues[priority])
    {
        CL_EO_QUEUE_UNLOCK(&gClEoQueueMutex);
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Queue with priority:%d already active\n",priority));
        goto out;
    }
    CL_EO_QUEUE_UNLOCK(&gClEoQueueMutex);

    if(!threadPriority)
    {
        threadPriority = gClEoThreadPriorityMap[priority];
    }

    rc = CL_EO_RC(CL_ERR_NO_MEMORY);
#if 0
    pQueue = clHeapCalloc(1,sizeof(*pQueue));
    if(pQueue == NULL)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Error allocating memory\n"));
        goto out;
    }
#endif

    CL_JOB_LIST_INIT(&pQueue->queue);
    rc = clOsalMutexInit(&pQueue->mutex);
    CL_ASSERT(rc == CL_OK);
    rc = clOsalCondInit(&pQueue->cond);
    CL_ASSERT(rc == CL_OK);

    if(pJobHandler == NULL)
    {
        /*Default handler for jobs*/
        pJobHandler = clEoJobHandler;
    }

#if 0 /* GAS */
    rc = clThreadPoolCreate(&threadPool,(ClEoQueueHandleT)pQueue,
                            mode,maxThreads,threadPriority,pJobHandler,
                            pUserData);
#endif

    rc = clJobQueueInit(&gEoJobQueue, 0, maxThreads);

    if(rc != CL_OK)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Error in thread pool create.rc=0x%x\n",rc));
        goto out_free;
    }

#if 0
    pQueue->pThreadPool = (ClThreadPoolT*)threadPool;
    pQueue->priority = priority;
    CL_EO_QUEUE_LOCK(&gClEoQueueMutex);
    if(gpClEoQueues[priority])
    {
        /*Someone beat us. So back out*/
        CL_EO_QUEUE_UNLOCK(&gClEoQueueMutex);
        rc = CL_EO_RC(CL_ERR_OP_NOT_PERMITTED);
        clThreadPoolDelete((ClThreadPoolHandleT) threadPool);
        goto out_free;
    }
    pQueue->state = CL_EO_QUEUE_STATE_ACTIVE;
    gpClEoQueues[priority] = pQueue;
    CL_EO_QUEUE_UNLOCK(&gClEoQueueMutex);
    *pHandle = (ClEoQueueHandleT)pQueue;
#endif

    rc = CL_OK;
    goto out;

    out_free:
#if 0
    clOsalMutexDestroy(&pQueue->mutex);
    clOsalCondDestroy(&pQueue->cond);
    clHeapFree(pQueue);
#endif

    out:
    return rc;
}