⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smnamelib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	return (ERROR);		}    /* get first name in database */    CACHE_PIPE_FLUSH ();                        /* CACHE FLUSH   [SPR 68334] */    smName = (SM_OBJ_NAME volatile *) SM_DL_FIRST (&pSmNameDb->nameList);    /* scan name list until name is found or end of list is reached */    while (smName != LOC_NULL) 	{	if (strcmp((char *)smName->name, name) == 0)	/* name found */	   {	   *pValue = (void *) ntohl ((int) smName->value);/* return value */	   *pType  = ntohl (smName->type);	/* return object type */    	   if (semSmGive ((SM_SEM_ID)&pSmNameDb->sem) != OK)       		{				/* release access */		TASK_UNSAFE ();		return (ERROR);		}	   TASK_UNSAFE ();	   return (OK);	   }        /* get next name in list */	        CACHE_PIPE_FLUSH ();                    /* CACHE FLUSH   [SPR 68334] */	smName = (SM_OBJ_NAME volatile *) SM_DL_NEXT (smName);	}    if (semSmGive ((SM_SEM_ID)&pSmNameDb->sem) != OK) 	/* release access */	{	TASK_UNSAFE ();	return (ERROR);	}    TASK_UNSAFE ();    errno = S_smNameLib_NAME_NOT_FOUND;    return (ERROR);    }/******************************************************************************** smNameFind - look up a shared memory object by name (VxMP Option)** This routine searches the shared memory objects name database for an object* matching a specified <name>.  If the object is found, its value and type* are copied to the addresses pointed to by <pValue> and <pType>.  The value of * <waitType> can be one of the following:* \is* \i `NO_WAIT (0)'* The call returns immediately, even if <name> is not in the database.* \i `WAIT_FOREVER (-1)'* The call returns only when <name> is available in the database.  If <name>* is not already in, the database is scanned periodically as the routine* waits for <name> to be entered.* \ie** AVAILABILITY* This routine is distributed as a component of the unbundled shared memory* objects support option, VxMP.* * RETURNS: OK, or ERROR if the object is not found, if <name> is too long, or* the wait type is invalid.** ERRNO: *  S_smNameLib_NOT_INITIALIZED  *  S_smNameLib_NAME_TOO_LONG *  S_smNameLib_NAME_NOT_FOUND *  S_smNameLib_INVALID_WAIT_TYPE *  S_smObjLib_LOCK_TIMEOUT** SEE ALSO: smNameShow*/STATUS smNameFind     (    char *	name,		/* name to search for */     void **	pValue,		/* pointer where to return value */    int  *	pType,		/* pointer where to return object type */    int		waitType	/* NO_WAIT or WAIT_FOREVER */    )    {    BOOL        found;    if (pSmNameDb == NULL)		/* name facility initialized ? */        {        errno = S_smNameLib_NOT_INITIALIZED;        return (ERROR);        }    if (strlen (name) > MAX_NAME_LENGTH)	/* name too long */        {        errno = S_smNameLib_NAME_TOO_LONG;        return (ERROR);        }     /*      * Now if waitType is NO_WAIT, look for name in database once     * an return OK if name is found or ERROR if not found.     * if waitType is WAIT_FOREVER, do a loop until name is entered     * in the database by another task.     * In order to avoid CPU and BUS over use we use taskDelay (1) to     * delay and reschedule between each loop.     */    switch (waitType)	{	case NO_WAIT : 	    {	    return (smNameFindOnce (name, pValue, pType));	    }	case WAIT_FOREVER :	    {    	    do       	        {                found = smNameFindOnce (name, pValue, pType);                                            /* look for name in database */                /* ERROR not because name is not in database */	        if ((found == ERROR) && (errno != S_smNameLib_NAME_NOT_FOUND)) 		    {		    return (ERROR);		    }                taskDelay (1);              /* force reschedule */                } while (found != OK);            return (found);    	    }	default : 	    {	    errno = S_smNameLib_INVALID_WAIT_TYPE;	    return (ERROR);            }	}    }/******************************************************************************** smNameFindByValueOnce - look up a shared symbol by value one time** This routine searches the shared name database for an object matching a* specified identifier.  If the object is found, its name and type are copied* to <name> and <pType>. ** RETURNS: OK, or ERROR if the object is not found.** ERRNO: *  S_smNameLib_VALUE_NOT_FOUND  *  S_smObjLib_LOCK_TIMEOUT** NOMANUAL*/LOCAL STATUS smNameFindByValueOnce     (    void *	value,		/* value to search for */    char *	name,		/* pointer where to return name */     int  *	pType		/* pointer where to return object type */    )    {    SM_OBJ_NAME volatile * smName;    TASK_SAFE ();    if (semSmTake ((SM_SEM_ID)&pSmNameDb->sem, WAIT_FOREVER) != OK)	{				/* get exclusive access */	TASK_UNSAFE ();	return (ERROR);		}    /* get first name in list */    CACHE_PIPE_FLUSH ();                        /* CACHE FLUSH   [SPR 68334] */    smName = (SM_OBJ_NAME volatile *) SM_DL_FIRST (&pSmNameDb->nameList);    /* scan name list until id is found or end of list reached */    while (smName != LOC_NULL) 	{	if ((void *) ntohl ((int) smName->value) == value)/* value found */	   {	   /* copy name and type */	   strcpy (name, (char *) smName->name);	   *pType = ntohl (smName->type);    	   if (semSmGive ((SM_SEM_ID)&pSmNameDb->sem) != OK)        		{					/* release access */		TASK_UNSAFE ();		return (ERROR);		}	   TASK_UNSAFE ();	   return (OK);	   }	/* get next name in list */        CACHE_PIPE_FLUSH ();                    /* CACHE FLUSH   [SPR 68334] */	smName = (SM_OBJ_NAME volatile *) SM_DL_NEXT (smName);	}    if (semSmGive ((SM_SEM_ID)&pSmNameDb->sem) != OK) 	/* release access */	{	TASK_UNSAFE ();	return (ERROR);	}    TASK_UNSAFE ();    errno = S_smNameLib_VALUE_NOT_FOUND;    return (ERROR);    }/******************************************************************************** smNameFindByValue - look up a shared memory object by value (VxMP Option)** This routine searches the shared memory name database for an object matching* a specified value.  If the object is found, its name and type are copied* to the addresses pointed to by <name> and <pType>.  The value of <waitType> * can be one of the following:** \is* \i `NO_WAIT (0)'* The call returns immediately, even if the object value is not in the database.* \i `WAIT_FOREVER (-1)'* The call returns only when the object value is available in the database.* \ie** AVAILABILITY* This routine is distributed as a component of the unbundled shared memory* objects support option, VxMP.* * RETURNS: OK, or ERROR if <value> is not found or if the wait type is invalid.** ERRNO: *  S_smNameLib_NOT_INITIALIZED *  S_smNameLib_VALUE_NOT_FOUND *  S_smNameLib_INVALID_WAIT_TYPE  *  S_smObjLib_LOCK_TIMEOUT** SEE ALSO: smNameShow*/STATUS smNameFindByValue     (    void *	value,		/* value to search for */    char *	name,		/* pointer where to return name */     int  *	pType,		/* pointer where to return object type */    int		waitType	/* NO_WAIT or WAIT_FOREVER */    )    {    BOOL	found;    if (pSmNameDb == NULL)		/* name facility initialized ? */	{	errno = S_smNameLib_NOT_INITIALIZED;	return (ERROR);	}    /*      * Now if waitType is NO_WAIT, look for id in database once     * an return OK if id is found or ERROR if not found.     * if waitType is WAIT_FOREVER, do a loop until id is entered     * in the database by another task.     * In order to avoid CPU and BUS over use we use taskDelay (1) to     * delay and reschedule between each loop.     */    switch (waitType)	{	case NO_WAIT : 	    {	    return (smNameFindByValueOnce (value, name, pType));	    }	case WAIT_FOREVER :	    {    	    do       	        {                found = smNameFindByValueOnce (value, name, pType);                                            /* look for name in database */                /* ERROR not because id is not in database */	        if ((found == ERROR) && (errno != S_smNameLib_VALUE_NOT_FOUND)) 		    {		    return (ERROR);		    }                taskDelay (1);              /* force reschedule */                }while (found != OK);            return (found);    	    }	default : 	    {	    errno = S_smNameLib_INVALID_WAIT_TYPE;	    return (ERROR);            }	}    }/******************************************************************************** smNameRemove - remove an object from the shared memory objects name database (VxMP Option)** This routine removes an object called <name> from the shared memory objects* name database. * * AVAILABILITY* This routine is distributed as a component of the unbundled shared memory* objects support option, VxMP.* * RETURNS: OK, or ERROR if the object name is not in the database or if* <name> is too long.** ERRNO: *  S_smNameLib_NOT_INITIALIZED  *  S_smNameLib_NAME_TOO_LONG *  S_smNameLib_NAME_NOT_FOUND *  S_smObjLib_LOCK_TIMEOUT** SEE ALSO: smNameShow*/STATUS smNameRemove    (    char *	name	/* name of object to remove */    )    {    SM_OBJ_NAME volatile * smName;    int			   temp;	/* value for bus bridge flush */    if (pSmNameDb == NULL)		/* name facility initialized ? */	{	errno = S_smNameLib_NOT_INITIALIZED;	return (ERROR);	}    if (strlen (name) > MAX_NAME_LENGTH)	/* name too long */	{	errno = S_smNameLib_NAME_TOO_LONG;	return (ERROR);	}    TASK_SAFE ();				/* get exclusive access */    if (semSmTake ((SM_SEM_ID)&pSmNameDb->sem, WAIT_FOREVER) != OK)	{					TASK_UNSAFE ();	return (ERROR);		}    /* get first name in list */    CACHE_PIPE_FLUSH ();                        /* CACHE FLUSH   [SPR 68334] */    smName = (SM_OBJ_NAME volatile *) SM_DL_FIRST (&pSmNameDb->nameList);    /* loop until name is found or end of list */    while (smName != LOC_NULL) 	{	if (strcmp((char *)smName->name, name) == 0)	/* name found */	    {	    smDllRemove ((SM_DL_LIST *)&pSmNameDb->nameList,	                 (SM_DL_NODE *)smName);	    smMemPartFree ((SM_PART_ID)smNamePartId, (char *) smName);    	   					/* update element number */    	    pSmNameDb->curNumName = htonl (ntohl (pSmNameDb->curNumName) - 1);           					/* update shared infos data */            pSmObjHdr->curNumName = htonl (ntohl (pSmObjHdr->curNumName) - 1);            CACHE_PIPE_FLUSH ();                /* CACHE FLUSH   [SPR 68334] */            temp = pSmNameDb->curNumName;	/* BRIDGE FLUSH  [SPR 68334] */    	    if (semSmGive ((SM_SEM_ID)&pSmNameDb->sem) != OK)       		{				/* release access */		TASK_UNSAFE ();		return (ERROR);		}	    TASK_UNSAFE ();	    return (OK);	    }		/* get next name in list */        CACHE_PIPE_FLUSH ();                    /* CACHE FLUSH   [SPR 68334] */	smName = (SM_OBJ_NAME volatile *) SM_DL_NEXT (smName);	}        if (semSmGive ((SM_SEM_ID)&pSmNameDb->sem) != OK) 	/* release access */	{	TASK_UNSAFE ();	return (ERROR);	}    TASK_UNSAFE ();    errno = S_smNameLib_NAME_NOT_FOUND;    return (ERROR);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -