00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <stdlib.h>
00032 #include "MsgQInternal.h"
00033
00034
00035
00036 MSGQ_INFO_PTR MsgQInfo[MSGQ_TBL_SZ];
00037 MSGQ_INFO_LIST_PTR MsgQListHead = NULL;
00038
00039 inline unsigned int HashIndex(ULONG qName);
00040
00041
00042
00043
00044
00045
00046
00047
00048 int InstallMsqQTable(ULONG qName, int qId, int semId, int* err) {
00049
00050 MSGQ_INFO_PTR pMsgQInfo = NULL;
00051 unsigned int index;
00052
00053 if ((pMsgQInfo = MsgQTableLookup(qName)) == NULL) {
00054 pMsgQInfo = (MSGQ_INFO_PTR)malloc(sizeof(*pMsgQInfo));
00055
00056 if(pMsgQInfo != NULL) {
00057 index = HashIndex(qName);
00058
00059 pMsgQInfo->next = MsgQInfo[index];
00060 MsgQInfo[index] = pMsgQInfo;
00061 pMsgQInfo->qName = qName;
00062 pMsgQInfo->qId = qId;
00063 pMsgQInfo->semId = semId;
00064 pMsgQInfo->sendState = MSG_Q_READY;
00065 pMsgQInfo->numMsgs = 0;
00066
00067 *err = OK;
00068 return (OK);
00069 }
00070 else
00071 *err = KMsgQLibNoMemoryErr;
00072 }
00073 else
00074 *err = KMsgQLibQIdErr;
00075
00076 return(ERROR);
00077
00078 }
00079
00080
00081
00082
00083
00084
00085
00086 inline unsigned int HashIndex(ULONG qName) {
00087 return(qName % MSGQ_TBL_SZ);
00088 }
00089
00090
00091
00092
00093
00094
00095
00096 MSGQ_INFO* MsgQTableLookup(ULONG qName) {
00097 MSGQ_INFO_PTR pMsgQInfo = NULL;
00098
00099 for (pMsgQInfo = MsgQInfo[HashIndex(qName)]; pMsgQInfo != NULL; pMsgQInfo = pMsgQInfo->next) {
00100 if (qName == pMsgQInfo->qName)
00101 return(pMsgQInfo);
00102 }
00103
00104 return(NULL);
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114 int RemoveFromMsqQTable(ULONG qName, int* err) {
00115 unsigned int index = 0;
00116 MSGQ_INFO_PTR prev = NULL;
00117 MSGQ_INFO_PTR pMsgQInfo = NULL;
00118
00119 index = HashIndex(qName);
00120 for (pMsgQInfo = MsgQInfo[index]; pMsgQInfo != NULL; pMsgQInfo = pMsgQInfo->next) {
00121 if (qName == pMsgQInfo->qName)
00122 break;
00123 prev = pMsgQInfo;
00124 }
00125
00126 if (pMsgQInfo != NULL) {
00127 if (prev == NULL)
00128 MsgQInfo[index] = pMsgQInfo->next;
00129 else
00130 prev->next = pMsgQInfo->next;
00131
00132 free((void*)pMsgQInfo);
00133 *err = OK;
00134 return (OK);
00135 }
00136 else
00137 *err = KMsgQLibQIdErr;
00138
00139 return(ERROR);
00140 }
00141
00142
00143
00144
00145
00146
00147
00148 void AddToMsgQTable(ULONG qName) {
00149 MSGQ_INFO_LIST_PTR tempNext;
00150
00151 if (MsgQListHead != NULL) {
00152
00153 tempNext = MsgQListHead->next;
00154
00155 if ((MsgQListHead->next = (MSGQ_INFO_LIST*)malloc(sizeof(MSGQ_INFO_LIST))) != NULL) {
00156 MsgQListHead->next->next = tempNext;
00157 MsgQListHead->next->qName = qName;
00158 }
00159 else
00160 MsgQListHead->next = tempNext;
00161 }
00162 else {
00163 if ((MsgQListHead = (MSGQ_INFO_LIST*)malloc(sizeof(MSGQ_INFO_LIST))) != NULL) {
00164 MsgQListHead->next = NULL;
00165 MsgQListHead->qName = qName;
00166 }
00167 }
00168 }
00169
00170
00171
00172
00173
00174
00175 void DeleteFromMsgQTable(ULONG qName) {
00176 MSGQ_INFO_LIST_PTR prev = NULL;
00177 MSGQ_INFO_LIST_PTR pMsgQInfo = NULL;
00178
00179 for (pMsgQInfo = MsgQListHead; pMsgQInfo != NULL; pMsgQInfo = pMsgQInfo->next) {
00180 if (qName == pMsgQInfo->qName)
00181 break;
00182 prev = pMsgQInfo;
00183 }
00184
00185 if (pMsgQInfo != NULL) {
00186
00187 if( prev == NULL )
00188 MsgQListHead = MsgQListHead->next ;
00189
00190
00191 else
00192 prev->next = pMsgQInfo->next;
00193
00194
00195 free((void*) pMsgQInfo);
00196 }
00197 }