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

📄 smnamelib.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 2 页
字号:
    if (semSmTake (&pSmNameDb->sem, WAIT_FOREVER) != OK)	{				/* get exclusive access */	TASK_UNSAFE ();	return (ERROR);		}    /* get first name in database */    smName = (SM_OBJ_NAME *) SM_DL_FIRST (&pSmNameDb->nameList);    /* scan name list until name is found or end of list is reached */    while (smName != LOC_NULL) 	{	if (strcmp(smName->name, name) == 0)	/* name found */	   {	   *pValue = (void *) ntohl ((int) smName->value);/* return value */	   *pType  = ntohl (smName->type);	/* return object type */    	   if (semSmGive (&pSmNameDb->sem) != OK)        		{				/* release access */		TASK_UNSAFE ();		return (ERROR);		}	   TASK_UNSAFE ();	   return (OK);	   }        /* get next name in list */		smName = (SM_OBJ_NAME *) SM_DL_NEXT (smName);	}    if (semSmGive (&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:* .iP "NO_WAIT (0)"* The call returns immediately, even if <name> is not in the database.* .iP "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.* .LP** 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 */    )    {    int              nameLen;    BOOL             found;    if (pSmNameDb == NULL)		/* name facility initialized ? */        {        errno = S_smNameLib_NOT_INITIALIZED;        return (ERROR);        }    if ((nameLen = 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    * smName;    TASK_SAFE ();    if (semSmTake (&pSmNameDb->sem, WAIT_FOREVER) != OK)	{				/* get exclusive access */	TASK_UNSAFE ();	return (ERROR);		}    /* get first name in list */    smName = (SM_OBJ_NAME *) 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, smName->name);	   *pType = ntohl (smName->type);    	   if (semSmGive (&pSmNameDb->sem) != OK)        		{					/* release access */		TASK_UNSAFE ();		return (ERROR);		}	   TASK_UNSAFE ();	   return (OK);	   }	/* get next name in list */	smName = (SM_OBJ_NAME *) SM_DL_NEXT (smName);	}    if (semSmGive (&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:* .iP "NO_WAIT (0)"* The call returns immediately, even if the object value is not in the database.* .iP "WAIT_FOREVER (-1)"* The call returns only when the object value is available in the database.* .LP** 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    * smName;    int              nameLen;    if (pSmNameDb == NULL)		/* name facility initialized ? */	{	errno = S_smNameLib_NOT_INITIALIZED;	return (ERROR);	}    if ((nameLen = strlen(name)) > MAX_NAME_LENGTH)	/* name too long */	{	errno = S_smNameLib_NAME_TOO_LONG;	return (ERROR);	}    TASK_SAFE ();				/* get exclusive access */    if (semSmTake (&pSmNameDb->sem, WAIT_FOREVER) != OK)	{					TASK_UNSAFE ();	return (ERROR);		}    /* get first name in list */    smName = (SM_OBJ_NAME *) SM_DL_FIRST (&pSmNameDb->nameList);    /* loop until name is found or end of list */    while (smName != LOC_NULL) 	{	if (strcmp(smName->name, name) == 0)	/* name found */	   {	   smDllRemove (&pSmNameDb->nameList, (SM_DL_NODE *) smName);	   smMemPartFree (smNamePartId, (char *) smName);    	   					/* update element number */    	   pSmNameDb->curNumName = htonl (ntohl (pSmNameDb->curNumName) - 1);           					/* update shared infos data */           pSmObjHdr->curNumName = htonl (ntohl (pSmObjHdr->curNumName) - 1);    	   if (semSmGive (&pSmNameDb->sem) != OK)        		{				/* release access */		TASK_UNSAFE ();		return (ERROR);		}	   TASK_UNSAFE ();	   return (OK);	   }		/* get next name in list */	smName = (SM_OBJ_NAME *) SM_DL_NEXT (smName);	}        if (semSmGive (&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 + -