Blame Esm/ib/src/cs/cs_sema.c

Packit Service 3470d1
/* BEGIN_ICS_COPYRIGHT5 ****************************************
Packit Service 3470d1
Packit Service 3470d1
Copyright (c) 2015-2017, Intel Corporation
Packit Service 3470d1
Packit Service 3470d1
Redistribution and use in source and binary forms, with or without
Packit Service 3470d1
modification, are permitted provided that the following conditions are met:
Packit Service 3470d1
Packit Service 3470d1
    * Redistributions of source code must retain the above copyright notice,
Packit Service 3470d1
      this list of conditions and the following disclaimer.
Packit Service 3470d1
    * Redistributions in binary form must reproduce the above copyright
Packit Service 3470d1
      notice, this list of conditions and the following disclaimer in the
Packit Service 3470d1
      documentation and/or other materials provided with the distribution.
Packit Service 3470d1
    * Neither the name of Intel Corporation nor the names of its contributors
Packit Service 3470d1
      may be used to endorse or promote products derived from this software
Packit Service 3470d1
      without specific prior written permission.
Packit Service 3470d1
Packit Service 3470d1
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit Service 3470d1
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit Service 3470d1
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Packit Service 3470d1
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
Packit Service 3470d1
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit Service 3470d1
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Packit Service 3470d1
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Packit Service 3470d1
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Packit Service 3470d1
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit Service 3470d1
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit Service 3470d1
Packit Service 3470d1
 * ** END_ICS_COPYRIGHT5   ****************************************/
Packit Service 3470d1
Packit Service 3470d1
/***********************************************************************
Packit Service 3470d1
* 
Packit Service 3470d1
* FILE NAME
Packit Service 3470d1
*      cs_sema.c
Packit Service 3470d1
*
Packit Service 3470d1
* DESCRIPTION
Packit Service 3470d1
*      This file contains the implementation of the Counting Semaphores
Packit Service 3470d1
*      services.
Packit Service 3470d1
*
Packit Service 3470d1
* DATA STRUCTURES
Packit Service 3470d1
*
Packit Service 3470d1
* FUNCTIONS
Packit Service 3470d1
*      cs_sema_create
Packit Service 3470d1
*      cs_sema_delete
Packit Service 3470d1
*      cs_vsema
Packit Service 3470d1
*      cs_psema
Packit Service 3470d1
*
Packit Service 3470d1
* DEPENDENCIES
Packit Service 3470d1
*      cs_g.h
Packit Service 3470d1
*
Packit Service 3470d1
*
Packit Service 3470d1
* HISTORY
Packit Service 3470d1
*
Packit Service 3470d1
* NAME      DATE        REMARKS
Packit Service 3470d1
* MGR       03/14/02    Initial creation of file.
Packit Service 3470d1
* MGR       03/26/02    Corrected lint errors.
Packit Service 3470d1
* MGR       04/18/02    PR1728.  vs_psema should return VSTATUS_AGAIN
Packit Service 3470d1
*                       error code, if thread has been killed.
Packit Service 3470d1
* MGR       04/23/02    PR1742.  Added fix for blocking of cs_psema;
Packit Service 3470d1
*                       cs_vsema should release lock if count goes to 1.
Packit Service 3470d1
*
Packit Service 3470d1
***********************************************************************/
Packit Service 3470d1
#include "ib_types.h"
Packit Service 3470d1
#include "ib_status.h"
Packit Service 3470d1
#include "cs_g.h"
Packit Service 3470d1
#include "vs_g.h"
Packit Service 3470d1
#include "cs_log.h"
Packit Service 3470d1
#define function __FUNCTION__
Packit Service 3470d1
#ifdef __LINUX__
Packit Service 3470d1
#include <semaphore.h>
Packit Service 3470d1
#elif defined(__VXWORKS__) 
Packit Service 3470d1
#include <drv/timer/timerDev.h>
Packit Service 3470d1
#endif
Packit Service 3470d1
#ifdef LOCAL_MOD_ID
Packit Service 3470d1
#undef LOCAL_MOD_ID
Packit Service 3470d1
#endif
Packit Service 3470d1
#define LOCAL_MOD_ID VIEO_CS_MOD_ID
Packit Service 3470d1
Packit Service 3470d1
Packit Service 3470d1
/**********************************************************************
Packit Service 3470d1
*
Packit Service 3470d1
* FUNCTION
Packit Service 3470d1
*    cs_sema_create
Packit Service 3470d1
*
Packit Service 3470d1
* DESCRIPTION
Packit Service 3470d1
*    Initialize a counting semaphore object for use.
Packit Service 3470d1
*
Packit Service 3470d1
* INPUTS
Packit Service 3470d1
*    handle   - A pointer to a semaphore object to be filled in by
Packit Service 3470d1
*               the routine.
Packit Service 3470d1
*    count    - The initial value for the semaphore.
Packit Service 3470d1
*
Packit Service 3470d1
* OUTPUTS
Packit Service 3470d1
*    Status_t - On success VSTATUS_OK is returned, otherwise
Packit Service 3470d1
*    the cause of the error.
Packit Service 3470d1
*
Packit Service 3470d1
*
Packit Service 3470d1
* HISTORY
Packit Service 3470d1
*
Packit Service 3470d1
*   NAME    DATE        REMARKS
Packit Service 3470d1
*   MGR     03/14/02    Initial creation of function.
Packit Service 3470d1
*
Packit Service 3470d1
**********************************************************************/
Packit Service 3470d1
Status_t
Packit Service 3470d1
cs_sema_create (Sema_t *handle,
Packit Service 3470d1
                    uint32_t count)
Packit Service 3470d1
{
Packit Service 3470d1
  Status_t          rc;
Packit Service 3470d1
Packit Service 3470d1
  IB_ENTER (function,
Packit Service 3470d1
            (unint)handle,
Packit Service 3470d1
            (uint32_t)count,
Packit Service 3470d1
            (uint32_t)0U,
Packit Service 3470d1
	    (uint32_t)0U);
Packit Service 3470d1
Packit Service 3470d1
  /*
Packit Service 3470d1
  ** Validate handle
Packit Service 3470d1
  */
Packit Service 3470d1
  if (handle == (Sema_t *) 0)
Packit Service 3470d1
  {
Packit Service 3470d1
    IB_LOG_ERROR0 ("NULL handle pointer");
Packit Service 3470d1
    IB_EXIT (function, VSTATUS_ILLPARM);
Packit Service 3470d1
    return VSTATUS_ILLPARM;
Packit Service 3470d1
  }
Packit Service 3470d1
Packit Service 3470d1
#ifdef __VXWORKS__
Packit Service 3470d1
  handle->magic = SEMAPHORE_MAGIC;
Packit Service 3470d1
  handle->semId = semCCreate(SEM_Q_FIFO, count);
Packit Service 3470d1
  handle->count = count;
Packit Service 3470d1
  if (!handle->semId)
Packit Service 3470d1
  {
Packit Service 3470d1
      IB_LOG_ERROR0 ("failed to allocate semaphore");
Packit Service 3470d1
      rc = VSTATUS_ILLPARM;
Packit Service 3470d1
      IB_EXIT(function, rc);
Packit Service 3470d1
      return rc;
Packit Service 3470d1
  }
Packit Service 3470d1
#else
Packit Service 3470d1
  // LINUX USER SEMA
Packit Service 3470d1
  handle->magic = SEMAPHORE_MAGIC;
Packit Service 3470d1
  if (sem_init((sem_t *)&handle->osdSema, 0, 0) != 0)
Packit Service 3470d1
  {
Packit Service 3470d1
      IB_LOG_ERROR0 ("failed to allocate semaphore");
Packit Service 3470d1
      rc = VSTATUS_ILLPARM;
Packit Service 3470d1
      IB_EXIT(function, rc);
Packit Service 3470d1
      return rc;
Packit Service 3470d1
  }
Packit Service 3470d1
#endif // vxworks
Packit Service 3470d1
Packit Service 3470d1
  IB_EXIT (function, VSTATUS_OK);
Packit Service 3470d1
  return VSTATUS_OK;
Packit Service 3470d1
}
Packit Service 3470d1
Packit Service 3470d1
/**********************************************************************
Packit Service 3470d1
*
Packit Service 3470d1
* FUNCTION
Packit Service 3470d1
*    cs_sema_delete
Packit Service 3470d1
*
Packit Service 3470d1
* DESCRIPTION
Packit Service 3470d1
*    Delete a counting semaphore object.
Packit Service 3470d1
*
Packit Service 3470d1
* INPUTS
Packit Service 3470d1
*    handle   - A pointer to a semaphore object filled in by the
Packit Service 3470d1
*               cs_sema_create() call.
Packit Service 3470d1
*
Packit Service 3470d1
* OUTPUTS
Packit Service 3470d1
*    Status_t - On success VSTATUS_OK is returned, otherwise
Packit Service 3470d1
*    the cause of the error.
Packit Service 3470d1
*
Packit Service 3470d1
*
Packit Service 3470d1
* HISTORY
Packit Service 3470d1
*
Packit Service 3470d1
*   NAME    DATE        REMARKS
Packit Service 3470d1
*   MGR     03/14/02    Initial creation of function.
Packit Service 3470d1
*
Packit Service 3470d1
**********************************************************************/
Packit Service 3470d1
Status_t
Packit Service 3470d1
cs_sema_delete (Sema_t *handle)
Packit Service 3470d1
{
Packit Service 3470d1
  Status_t          rc;
Packit Service 3470d1
Packit Service 3470d1
  IB_ENTER (function,
Packit Service 3470d1
            (unint)handle,
Packit Service 3470d1
            (uint32_t)0U,
Packit Service 3470d1
            (uint32_t)0U,
Packit Service 3470d1
            (uint32_t)0U);
Packit Service 3470d1
Packit Service 3470d1
  /*
Packit Service 3470d1
  ** Validate handle
Packit Service 3470d1
  */
Packit Service 3470d1
  if (handle == (Sema_t *) 0)
Packit Service 3470d1
  {
Packit Service 3470d1
    IB_LOG_ERROR0 ("NULL handle pointer");
Packit Service 3470d1
    IB_EXIT (function, VSTATUS_ILLPARM);
Packit Service 3470d1
    return VSTATUS_ILLPARM;
Packit Service 3470d1
  }
Packit Service 3470d1
Packit Service 3470d1
  if (handle->magic != SEMAPHORE_MAGIC)
Packit Service 3470d1
  {
Packit Service 3470d1
    IB_LOG_ERRORX ("Invalid semaphore specified:", handle->magic);
Packit Service 3470d1
    IB_EXIT (function, VSTATUS_NXIO);
Packit Service 3470d1
    return VSTATUS_NXIO;
Packit Service 3470d1
  }
Packit Service 3470d1
Packit Service 3470d1
#ifdef __VXWORKS__
Packit Service 3470d1
  if (!handle->semId)
Packit Service 3470d1
  {
Packit Service 3470d1
      IB_LOG_ERROR0 ("NULL semaphore");
Packit Service 3470d1
      rc = VSTATUS_ILLPARM;
Packit Service 3470d1
      IB_EXIT(function, rc);
Packit Service 3470d1
      return rc;
Packit Service 3470d1
  }
Packit Service 3470d1
  if (ERROR == semDelete(handle->semId))
Packit Service 3470d1
  {
Packit Service 3470d1
      IB_LOG_ERROR0 ("failed to delete semaphore");
Packit Service 3470d1
      rc = VSTATUS_ILLPARM;
Packit Service 3470d1
      IB_EXIT(function, rc);
Packit Service 3470d1
      return rc;
Packit Service 3470d1
  }
Packit Service 3470d1
  handle->semId = NULL;
Packit Service 3470d1
  handle->count = 0;
Packit Service 3470d1
#else
Packit Service 3470d1
  // LINUX USER SEMA
Packit Service 3470d1
  if (sem_destroy((sem_t *)&handle->osdSema) != 0) {
Packit Service 3470d1
      IB_LOG_ERROR0 ("failed to delete semaphore");
Packit Service 3470d1
      rc = VSTATUS_ILLPARM;
Packit Service 3470d1
      IB_EXIT(function, rc);
Packit Service 3470d1
      return rc;
Packit Service 3470d1
  }
Packit Service 3470d1
  memset((void *)&handle->osdSema, 0, sizeof(sem_t));
Packit Service 3470d1
#endif
Packit Service 3470d1
Packit Service 3470d1
  IB_LOG_INFO ("semaphore deleted", (unint)handle);
Packit Service 3470d1
Packit Service 3470d1
  IB_EXIT (function, VSTATUS_OK);
Packit Service 3470d1
  return VSTATUS_OK;
Packit Service 3470d1
}
Packit Service 3470d1
Packit Service 3470d1
/**********************************************************************
Packit Service 3470d1
*
Packit Service 3470d1
* FUNCTION
Packit Service 3470d1
*    cs_vsema
Packit Service 3470d1
*
Packit Service 3470d1
* DESCRIPTION
Packit Service 3470d1
*    Increment a semaphore (post or give operation)
Packit Service 3470d1
*
Packit Service 3470d1
* INPUTS
Packit Service 3470d1
*    handle   - A pointer to a semaphore object filled in by the
Packit Service 3470d1
*               cs_sema_create() call.
Packit Service 3470d1
*
Packit Service 3470d1
* OUTPUTS
Packit Service 3470d1
*    Status_t - On success VSTATUS_OK is returned, otherwise
Packit Service 3470d1
*    the cause of the error.
Packit Service 3470d1
*
Packit Service 3470d1
*
Packit Service 3470d1
* HISTORY
Packit Service 3470d1
*
Packit Service 3470d1
*   NAME    DATE        REMARKS
Packit Service 3470d1
*   MGR     03/14/02    Initial creation of function.
Packit Service 3470d1
*   MGR     04/23/02    PR1742.  Added fix for blocking or cs_psema;
Packit Service 3470d1
*                       cs_vsema should release lock if count goes to 1.
Packit Service 3470d1
*
Packit Service 3470d1
**********************************************************************/
Packit Service 3470d1
Status_t
Packit Service 3470d1
cs_vsema (Sema_t *handle)
Packit Service 3470d1
{
Packit Service 3470d1
  Status_t          rc;
Packit Service 3470d1
Packit Service 3470d1
  IB_ENTER (function,
Packit Service 3470d1
            (unint)handle,
Packit Service 3470d1
            (uint32_t)0U,
Packit Service 3470d1
            (uint32_t)0U,
Packit Service 3470d1
            (uint32_t)0U);
Packit Service 3470d1
Packit Service 3470d1
  /*
Packit Service 3470d1
  ** Validate handle
Packit Service 3470d1
  */
Packit Service 3470d1
  if (handle == (Sema_t *) 0)
Packit Service 3470d1
  {
Packit Service 3470d1
    IB_LOG_ERROR0 ("NULL handle pointer");
Packit Service 3470d1
    IB_EXIT (function, VSTATUS_ILLPARM);
Packit Service 3470d1
    return VSTATUS_ILLPARM;
Packit Service 3470d1
  }
Packit Service 3470d1
Packit Service 3470d1
  if (handle->magic != SEMAPHORE_MAGIC)
Packit Service 3470d1
  {
Packit Service 3470d1
    IB_LOG_ERRORX ("Invalid semaphore specified:", handle->magic);
Packit Service 3470d1
    IB_EXIT (function, VSTATUS_NXIO);
Packit Service 3470d1
    return VSTATUS_NXIO;
Packit Service 3470d1
  }
Packit Service 3470d1
Packit Service 3470d1
#ifdef __VXWORKS__
Packit Service 3470d1
  if (ERROR == semGive(handle->semId))
Packit Service 3470d1
  {
Packit Service 3470d1
      IB_LOG_ERROR0 ("Failed to give semaphore");
Packit Service 3470d1
      rc = VSTATUS_NXIO;
Packit Service 3470d1
      IB_EXIT(function, rc);
Packit Service 3470d1
      return rc;
Packit Service 3470d1
  }
Packit Service 3470d1
  handle->count++;
Packit Service 3470d1
#else
Packit Service 3470d1
  // LINUX USER SEMA
Packit Service 3470d1
  if (sem_post((sem_t *)&handle->osdSema) != 0) {
Packit Service 3470d1
      IB_LOG_ERROR0 ("Failed to give/post semaphore");
Packit Service 3470d1
      rc = VSTATUS_NXIO;
Packit Service 3470d1
      IB_EXIT(function, rc);
Packit Service 3470d1
      return rc;
Packit Service 3470d1
  }
Packit Service 3470d1
#endif
Packit Service 3470d1
Packit Service 3470d1
  IB_EXIT (function, VSTATUS_OK);
Packit Service 3470d1
  return VSTATUS_OK;
Packit Service 3470d1
}
Packit Service 3470d1
Packit Service 3470d1
/**********************************************************************
Packit Service 3470d1
*
Packit Service 3470d1
* FUNCTION
Packit Service 3470d1
*    cs_psema
Packit Service 3470d1
*
Packit Service 3470d1
* DESCRIPTION
Packit Service 3470d1
*    Decrement a semaphore (wait or take operation)
Packit Service 3470d1
*
Packit Service 3470d1
* INPUTS
Packit Service 3470d1
*    handle   - A pointer to a semaphore object filled in by the
Packit Service 3470d1
*               cs_sema_create() call.
Packit Service 3470d1
*
Packit Service 3470d1
* OUTPUTS
Packit Service 3470d1
*    Status_t - On success VSTATUS_OK is returned, otherwise
Packit Service 3470d1
*    the cause of the error.
Packit Service 3470d1
*
Packit Service 3470d1
*
Packit Service 3470d1
* HISTORY
Packit Service 3470d1
*
Packit Service 3470d1
*   NAME    DATE        REMARKS
Packit Service 3470d1
*   MGR     03/14/02    Initial creation of function.
Packit Service 3470d1
*   MGR     04/18/02    PR1728.  vs_psema should return VSTATUS_AGAIN
Packit Service 3470d1
*                       error code, if thread has been killed.
Packit Service 3470d1
*
Packit Service 3470d1
**********************************************************************/
Packit Service 3470d1
Status_t
Packit Service 3470d1
cs_psema_wait (Sema_t *handle, int timeout)
Packit Service 3470d1
{
Packit Service 3470d1
	Status_t          rc=VSTATUS_OK;
Packit Service 3470d1
Packit Service 3470d1
	IB_ENTER (function, (unint)handle, 0U, 0U, 0U);
Packit Service 3470d1
Packit Service 3470d1
  	/* Validate handle */
Packit Service 3470d1
  	if (handle == (Sema_t *) 0)
Packit Service 3470d1
  	{
Packit Service 3470d1
    	IB_LOG_ERROR0 ("NULL handle pointer");
Packit Service 3470d1
    	IB_EXIT (function, VSTATUS_ILLPARM);
Packit Service 3470d1
    	return VSTATUS_ILLPARM;
Packit Service 3470d1
  	}
Packit Service 3470d1
Packit Service 3470d1
  	if (handle->magic != SEMAPHORE_MAGIC)
Packit Service 3470d1
  	{
Packit Service 3470d1
    	IB_LOG_ERRORX ("Invalid semaphore specified:", handle->magic);
Packit Service 3470d1
    	IB_EXIT (function, VSTATUS_NXIO);
Packit Service 3470d1
    	return VSTATUS_NXIO;
Packit Service 3470d1
  	}
Packit Service 3470d1
Packit Service 3470d1
  	if (timeout == CS_SEMA_WAIT_FOREVER) {
Packit Service 3470d1
		return(cs_psema(handle));
Packit Service 3470d1
  	} else {
Packit Service 3470d1
#ifdef __VXWORKS__
Packit Service 3470d1
  		if (ERROR == semTake(handle->semId, timeout*sysClkRateGet()))
Packit Service 3470d1
  		{
Packit Service 3470d1
      		IB_LOG_WARN0("Timed out trying to take semaphore");
Packit Service 3470d1
      		rc = VSTATUS_NXIO;
Packit Service 3470d1
  		} else {
Packit Service 3470d1
            handle->count--;
Packit Service 3470d1
        }
Packit Service 3470d1
#elif defined (__LINUX__)
Packit Service 3470d1
  		// LINUX USER SEMA
Packit Service 3470d1
		int i=0, rc=-1;
Packit Service 3470d1
		do {
Packit Service 3470d1
  			rc = sem_trywait((sem_t *)&handle->osdSema);
Packit Service 3470d1
			++i;
Packit Service 3470d1
			(void)vs_thread_sleep(VTIMER_1S);
Packit Service 3470d1
		} while (i
Packit Service 3470d1
  		if (rc != 0) {
Packit Service 3470d1
      		IB_LOG_WARN0("Timed out trying to take semaphore");
Packit Service 3470d1
      		rc = VSTATUS_NXIO;
Packit Service 3470d1
  		}
Packit Service 3470d1
#endif
Packit Service 3470d1
	}
Packit Service 3470d1
  	IB_EXIT (function, rc);
Packit Service 3470d1
    return rc;
Packit Service 3470d1
}
Packit Service 3470d1
Packit Service 3470d1
/**********************************************************************
Packit Service 3470d1
*
Packit Service 3470d1
* FUNCTION
Packit Service 3470d1
*    cs_psema
Packit Service 3470d1
*
Packit Service 3470d1
* DESCRIPTION
Packit Service 3470d1
*    Decrement a semaphore (wait or take operation)
Packit Service 3470d1
*
Packit Service 3470d1
* INPUTS
Packit Service 3470d1
*    handle   - A pointer to a semaphore object filled in by the
Packit Service 3470d1
*               cs_sema_create() call.
Packit Service 3470d1
*
Packit Service 3470d1
* OUTPUTS
Packit Service 3470d1
*    Status_t - On success VSTATUS_OK is returned, otherwise
Packit Service 3470d1
*    the cause of the error.
Packit Service 3470d1
*
Packit Service 3470d1
*
Packit Service 3470d1
* HISTORY
Packit Service 3470d1
*
Packit Service 3470d1
*   NAME    DATE        REMARKS
Packit Service 3470d1
*   MGR     03/14/02    Initial creation of function.
Packit Service 3470d1
*   MGR     04/18/02    PR1728.  vs_psema should return VSTATUS_AGAIN
Packit Service 3470d1
*                       error code, if thread has been killed.
Packit Service 3470d1
*
Packit Service 3470d1
**********************************************************************/
Packit Service 3470d1
Status_t
Packit Service 3470d1
cs_psema (Sema_t *handle)
Packit Service 3470d1
{
Packit Service 3470d1
  Status_t          rc;
Packit Service 3470d1
Packit Service 3470d1
  IB_ENTER (function,
Packit Service 3470d1
            (unint)handle,
Packit Service 3470d1
            (uint32_t)0U,
Packit Service 3470d1
            (uint32_t)0U,
Packit Service 3470d1
            (uint32_t)0U);
Packit Service 3470d1
Packit Service 3470d1
  /*
Packit Service 3470d1
  ** Validate handle
Packit Service 3470d1
  */
Packit Service 3470d1
  if (handle == (Sema_t *) 0)
Packit Service 3470d1
  {
Packit Service 3470d1
    IB_LOG_ERROR0 ("NULL handle pointer");
Packit Service 3470d1
    IB_EXIT (function, VSTATUS_ILLPARM);
Packit Service 3470d1
    return VSTATUS_ILLPARM;
Packit Service 3470d1
  }
Packit Service 3470d1
Packit Service 3470d1
  if (handle->magic != SEMAPHORE_MAGIC)
Packit Service 3470d1
  {
Packit Service 3470d1
    IB_LOG_ERRORX ("Invalid semaphore specified:", handle->magic);
Packit Service 3470d1
    IB_EXIT (function, VSTATUS_NXIO);
Packit Service 3470d1
    return VSTATUS_NXIO;
Packit Service 3470d1
  }
Packit Service 3470d1
Packit Service 3470d1
#ifdef __VXWORKS__
Packit Service 3470d1
  if (ERROR == semTake(handle->semId, WAIT_FOREVER))
Packit Service 3470d1
  {
Packit Service 3470d1
      IB_LOG_ERROR0 ("Failed to take semaphore");
Packit Service 3470d1
      rc = VSTATUS_NXIO;
Packit Service 3470d1
      IB_EXIT(function, rc);
Packit Service 3470d1
      return rc;
Packit Service 3470d1
  }
Packit Service 3470d1
  handle->count--;
Packit Service 3470d1
#else
Packit Service 3470d1
  // LINUX USER SEMA
Packit Service 3470d1
  if (sem_wait((sem_t *)&handle->osdSema) != 0) {
Packit Service 3470d1
      IB_LOG_ERROR0 ("Failed to take semaphore");
Packit Service 3470d1
      rc = VSTATUS_NXIO;
Packit Service 3470d1
      IB_EXIT(function, rc);
Packit Service 3470d1
      return rc;
Packit Service 3470d1
  }
Packit Service 3470d1
#endif
Packit Service 3470d1
Packit Service 3470d1
  IB_EXIT (function, VSTATUS_OK);
Packit Service 3470d1
  return VSTATUS_OK;
Packit Service 3470d1
}
Packit Service 3470d1
Packit Service 3470d1
/**********************************************************************
Packit Service 3470d1
*
Packit Service 3470d1
* FUNCTION
Packit Service 3470d1
*    cs_sema_getcount
Packit Service 3470d1
*
Packit Service 3470d1
* DESCRIPTION
Packit Service 3470d1
*    return counting semaphore count
Packit Service 3470d1
*
Packit Service 3470d1
* INPUTS
Packit Service 3470d1
*    handle   - A pointer to a semaphore object filled in by the
Packit Service 3470d1
*               cs_sema_create() call.
Packit Service 3470d1
*
Packit Service 3470d1
* OUTPUTS
Packit Service 3470d1
*    int - semaphore count
Packit Service 3470d1
*
Packit Service 3470d1
*
Packit Service 3470d1
* HISTORY
Packit Service 3470d1
*
Packit Service 3470d1
*   NAME    DATE        REMARKS
Packit Service 3470d1
*   JMS     02/20/07    Initial creation of function.
Packit Service 3470d1
*
Packit Service 3470d1
**********************************************************************/
Packit Service 3470d1
Status_t cs_sema_getcount(Sema_t *handle, int *semCount)
Packit Service 3470d1
{
Packit Service 3470d1
	Status_t rc = VSTATUS_OK;
Packit Service 3470d1
Packit Service 3470d1
	IB_ENTER (function, (unint)handle, 0U, 0U, 0U);
Packit Service 3470d1
Packit Service 3470d1
  	/* Validate handle */
Packit Service 3470d1
  	if (handle == (Sema_t *) 0) {
Packit Service 3470d1
    	IB_LOG_ERROR0 ("NULL handle pointer");
Packit Service 3470d1
    	rc = VSTATUS_ILLPARM;
Packit Service 3470d1
  	} else if (handle->magic != SEMAPHORE_MAGIC) {
Packit Service 3470d1
    	IB_LOG_ERRORX ("Invalid semaphore specified:", handle->magic);
Packit Service 3470d1
    	rc = VSTATUS_NXIO;
Packit Service 3470d1
  	} else {
Packit Service 3470d1
#ifdef __VXWORKS__
Packit Service 3470d1
        *semCount = handle->count;
Packit Service 3470d1
#elif defined (__LINUX__)
Packit Service 3470d1
        if ((sem_getvalue((sem_t *)&handle->osdSema, semCount)) != 0)
Packit Service 3470d1
        {
Packit Service 3470d1
            IB_LOG_ERROR0 ("Failed to get semaphore count");
Packit Service 3470d1
            rc = VSTATUS_NXIO;
Packit Service 3470d1
        }
Packit Service 3470d1
#endif
Packit Service 3470d1
    }
Packit Service 3470d1
    IB_EXIT (function, rc);
Packit Service 3470d1
    return rc;
Packit Service 3470d1
}