ClRcT clJobQueueCreate(ClJobQueueT** hdl, ClUint32T maxJobs, ClUint32T maxTasks)
{
    ClRcT rc;
    *hdl = (ClJobQueueT*) clHeapCalloc(1, sizeof(ClJobQueueT));
    if (*hdl == NULL) return CL_JOBQUEUE_RC(CL_ERR_NO_MEMORY);

    rc = clJobQueueInit(*hdl, maxJobs, maxTasks);
    if (rc != CL_OK)
    {
        clHeapFree(*hdl);
        *hdl = NULL;
    }
    else (*hdl)->flags |= CreatedJobQueue;

    return rc;  
}
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;
}