📄 msgqdistgrplib.c
字号:
* message queues option, VxFusion.** RETURNS: N/A** NOTE: Call with <distGrpDbSemaphore> taken.** NOMANUAL*/void msgQDistGrpLclSetId ( DIST_GRP_DB_NODE * pGrpDbNode, /* the node to change */ DIST_MSG_Q_GRP_ID grpId /* the new ID */ ) { DIST_OBJ_NODE * pObjNode; DIST_MSG_Q_ID dMsgQId; int ix = pGrpDbNode->ixNode; hashTblRemove (distGrpDbIdId, (HASH_NODE *) &(distGrpDbId[ix])); pGrpDbNode->grpDbId = grpId; pObjNode = MSG_Q_ID_TO_DIST_OBJ_NODE (pGrpDbNode->grpDbMsgQId); dMsgQId = DIST_MSG_Q_GRP_ID_TO_DIST_MSG_Q_ID (grpId); pObjNode->objNodeId = DIST_MSG_Q_ID_TO_DIST_OBJ_ID (dMsgQId); hashTblPut (distGrpDbIdId, (HASH_NODE *) &(distGrpDbId[ix])); }/***************************************************************************** msgQDistGrpLclCreate - create a new group in local database (VxFusion option)** This routine creates a new group in the local database.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: A ptr to the group node.** NOTE: Call with <distGrpDbSemaphore> taken.** NOMANUAL*/DIST_GRP_DB_NODE * msgQDistGrpLclCreate ( char * grpName, /* group name */ DIST_MSG_Q_GRP_ID grpId, /* group ID */ DIST_GRP_STATE grpState /* initial state */ ) { DIST_GRP_DB_NODE * pDbNode; DIST_OBJ_NODE * pObjNode; /* get a free database node */ if (! (pDbNode = (DIST_GRP_DB_NODE *) sllGet (&msgQDistGrpFreeList))) { return (NULL); /* database is full */ } /* init database node */ bcopy (grpName, (char *) &(pDbNode->grpDbName), strlen (grpName) + 1); sllInit (&(pDbNode->grpDbMsgQIdLst)); pDbNode->grpDbState = grpState; pDbNode->grpDbId = grpId; pDbNode->pGrpDbGapNode = NULL; /* Create message queue id. */ pObjNode = distObjNodeGet(); pObjNode->objNodeType = DIST_OBJ_TYPE_MSG_Q; pObjNode->objNodeId = DIST_MSG_Q_GRP_ID_TO_DIST_OBJ_ID (grpId); pDbNode->grpDbMsgQId = DIST_OBJ_NODE_TO_MSG_Q_ID (pObjNode); /* Link group name hash node in name hash table. */ hashTblPut (distGrpDbNmId, (HASH_NODE *) &(distGrpDbNm[pDbNode->ixNode])); /* Link group id hash node in id hash table. */ hashTblPut (distGrpDbIdId, (HASH_NODE *) &(distGrpDbId[pDbNode->ixNode]));#ifdef DIST_MSG_Q_GRP_REPORT printf ("msgQDistGrpLclCreate: `%s' (id 0x%lx, state %d) created\n", grpName, grpId, grpState);#endif return (pDbNode); }/***************************************************************************** msgQDistGrpLclAddMember - add a member to a group in the local database (VxFusion option)** This routine adds a member to a group in the local database.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: OK, if the member was added; ERROR, if not.** NOMANUAL*/STATUS msgQDistGrpLclAddMember ( DIST_GRP_DB_NODE * pDbNode, /* ptr to node of group */ MSG_Q_ID msgQId /* msgQ ID to add to group */ ) { DIST_GRP_MSG_Q_NODE * distGrpMsgQNode; distGrpMsgQNode = (DIST_GRP_MSG_Q_NODE *) malloc (sizeof (DIST_GRP_MSG_Q_NODE)); if (distGrpMsgQNode == NULL) return (ERROR); /* out of memory */ distGrpMsgQNode->msgQId = msgQId; msgQDistGrpDbLock(); sllPutAtHead (&(pDbNode->grpDbMsgQIdLst), (SL_NODE *) distGrpMsgQNode); msgQDistGrpDbUnlock(); return (OK); }/***************************************************************************** msgQDistGrpLclFindById - Find a group's node given in group ID (VxFusion option)** This routine looks up a group node when given the group ID.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: A pointer to a group node, or NULL.** NOTE: Take <distGrpDbSemaphore> before calling.** NOMANUAL*/DIST_GRP_DB_NODE * msgQDistGrpLclFindById ( DIST_MSG_Q_GRP_ID distGrpId /* the group ID to look for */ ) { DIST_GRP_HASH_NODE hMatchNode; DIST_GRP_HASH_NODE * pHNode; DIST_GRP_DB_NODE dbMatchNode; hMatchNode.pDbNode = &dbMatchNode; dbMatchNode.grpDbId = distGrpId; pHNode = (DIST_GRP_HASH_NODE *) hashTblFind (distGrpDbIdId, (HASH_NODE *) &hMatchNode, KEY_CMP_ARG_ID); if (pHNode == NULL) return (NULL); /* not found */ return (pHNode->pDbNode); }/***************************************************************************** msgQDistGrpLclFindByName - Find a group node given a group name (VxFusion option)** This routine looks up a group node when given the name of the group.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: A pointer to a group node, or NULL.** NOTE: Call with <distGrpDbSemaphore> taken.** NOMANUAL*/DIST_GRP_DB_NODE * msgQDistGrpLclFindByName ( char * grpName /* group name to find */ ) { DIST_GRP_HASH_NODE hMatchNode, *pHNode; DIST_GRP_DB_NODE dbMatchNode; hMatchNode.pDbNode = &dbMatchNode; bcopy (grpName, (char *) &(dbMatchNode.grpDbName), strlen (grpName) + 1); pHNode = (DIST_GRP_HASH_NODE *) hashTblFind (distGrpDbNmId, (HASH_NODE *) &hMatchNode, KEY_CMP_ARG_STR); if (pHNode == NULL) return (NULL); /* not found */ return (pHNode->pDbNode); }/***************************************************************************** msgQDistGrpLclEach - Step through nodes in the database (VxFusion option)** This routine steps through all nodes in the database, calling <routine>* with argument <routineArg> for each node.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: N/A** NOTE: Takes <distGrpDbSemaphore>.** NOMANUAL*/void msgQDistGrpLclEach ( FUNCPTR routine, /* routine to call for each node */ int routineArg /* argument to pass to routine */ ) { msgQDistGrpDbLock(); hashTblEach (distGrpDbNmId, routine, routineArg); msgQDistGrpDbUnlock(); }/***************************************************************************** msgQDistGrpBurst - burst out group database (VxFusion option)** This routine is used by INCO to update the remote group database on* node <nodeId>. All entries in the database are transmitted.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: STATUS of remote operation.** NOMANUAL*/STATUS msgQDistGrpBurst ( DIST_NODE_ID nodeId /* node to update */ ) { DIST_GRP_BURST burst; burst.burstNodeId = nodeId; burst.burstStatus = OK; msgQDistGrpLclEach ((FUNCPTR) msgQDistGrpBurstOne, (int) &burst); return (burst.burstStatus); }/***************************************************************************** msgQDistGrpBurstOne - burst out single group database entry (VxFusion option)** This routine bursts out a database entry to a node.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: TRUE, if successfully; FALSE, if not.** NOMANUAL*/BOOL msgQDistGrpBurstOne ( DIST_GRP_HASH_NODE * pGrpHashNode, /* specifies node to send */ DIST_GRP_BURST * pBurst /* target node */ ) { DIST_PKT_DGDB_ADD pktAdd; DIST_GRP_DB_NODE * pNode = pGrpHashNode->pDbNode; DIST_IOVEC distIOVec[2]; STATUS status; pktAdd.pktDgdbAddHdr.pktType = DIST_PKT_TYPE_DGDB; pktAdd.pktDgdbAddHdr.pktSubType = DIST_PKT_TYPE_DGDB_ADD; pktAdd.pktDgdbAddId = htons (pNode->grpDbId); pktAdd.pktDgdbAddCreator = htonl (pNode->grpDbNodeId); /* use IOV stuff here, since we do not want to copy data */ distIOVec[0].pIOBuffer = &pktAdd; distIOVec[0].IOLen = DIST_PKT_HDR_SIZEOF (DIST_PKT_DGDB_ADD); distIOVec[1].pIOBuffer = (char *) &pNode->grpDbName; distIOVec[1].IOLen = strlen ((char *) &pNode->grpDbName) + 1; status = distNetIOVSend (pBurst->burstNodeId, &distIOVec[0], 2, WAIT_FOREVER, DIST_DGDB_PRIO); if ((pBurst->burstStatus = status) == ERROR) return (FALSE); return (TRUE); }/***************************************************************************** msgQDistGrpHCmpStr - determine if two nodes have the same name (VxFusion option)** This routine is the hash compare function for group names.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: TRUE, if the nodes have the same name; FALSE, otherwise.** NOMANUAL*/LOCAL BOOL msgQDistGrpHCmpStr ( DIST_GRP_HASH_NODE * pMatchHNode, /* first node */ DIST_GRP_HASH_NODE * pHNode, /* second node */ int keyCmpArg /* not used */ ) { UNUSED_ARG(keyCmpArg); if (strcmp ((char *) &pMatchHNode->pDbNode->grpDbName, (char *) &pHNode->pDbNode->grpDbName) == 0) return (TRUE); else return (FALSE); }/***************************************************************************** msgQDistGrpHFuncStr - hash function for strings (VxFusion option)** This routine computes the hash value for a node's group name.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: The hash value.** NOMANUAL*/LOCAL INT32 msgQDistGrpHFuncStr ( int elements, /* elements in hash table */ DIST_GRP_HASH_NODE * pHNode, /* node whose name to hash */ int seed /* seed for hashing */ ) { char * tkey; int hash = 0; for (tkey = (char *) &pHNode->pDbNode->grpDbName; *tkey != '\0'; tkey++) hash = hash * seed + (unsigned int) *tkey; return (hash & (elements - 1)); }/***************************************************************************** msgQDistGrpHCmpId - compare two group ID's (VxFusion option)** This routine is the hash compare function for group ID's.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: TRUE, if ID's match; FALSE, otherwise.** NOMANUAL*/LOCAL BOOL msgQDistGrpHCmpId ( DIST_GRP_HASH_NODE * pMatchNode, /* first node */ DIST_GRP_HASH_NODE * pHNode, /* second node */ int keyArg /* unused */ ) { DIST_MSG_Q_GRP_ID distGrpId1 = pMatchNode->pDbNode->grpDbId; DIST_MSG_Q_GRP_ID distGrpId2 = pHNode->pDbNode->grpDbId; UNUSED_ARG(keyArg); if (distGrpId1 == distGrpId2) return (TRUE); else return (FALSE); }/***************************************************************************** msgQDistGrpHFuncId - hash function for group ID's (VxFusion option)** This routine computes a hash value for a group's ID.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: The hash value.** NOMANUAL*/LOCAL INT32 msgQDistGrpHFuncId ( int elements, /* elements in hash table */ DIST_GRP_HASH_NODE * pHNode, /* node whose ID to hash */ int divisor /* used by hash computation */ ) { return ((pHNode->pDbNode->grpDbId % divisor) & (elements - 1)); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -