Changeset 82527 in vbox for trunk/src/VBox/GuestHost/SharedClipboard/clipboard-common.cpp
- Timestamp:
- Dec 10, 2019 1:46:40 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-common.cpp
r82526 r82527 89 89 } 90 90 91 #if 0 /* currently not used */ 91 92 /** 92 93 * Creates (initializes) an event. … … 94 95 * @returns VBox status code. 95 96 * @param pEvent Event to initialize. 96 * @param uIDEvent ID to use.97 */ 98 int ShClEventCreate(PSHCLEVENT pEvent, SHCLEVENTID uID)97 * @param idEvent Event ID to use. 98 */ 99 static int shClEventInit(PSHCLEVENT pEvent, SHCLEVENTID idEvent) 99 100 { 100 101 AssertPtrReturn(pEvent, VERR_INVALID_POINTER); 101 102 102 LogFlowFunc(("Event %RU32\n", uID));103 104 int rc = RTSemEvent Create(&pEvent->hEventSem);103 LogFlowFunc(("Event %RU32\n", idEvent)); 104 105 int rc = RTSemEventMultiCreate(&pEvent->hEvtMulSem); 105 106 if (RT_SUCCESS(rc)) 106 107 { 107 pEvent-> uID = uID;108 pEvent->idEvent = idEvent; 108 109 pEvent->pPayload = NULL; 109 110 } … … 111 112 return rc; 112 113 } 113 114 /** 115 * Destroys an event. 114 #endif 115 116 /** 117 * Destroys an event, but doesn't free the memory. 116 118 * 117 119 * @param pEvent Event to destroy. 118 120 */ 119 void ShClEventDestroy(PSHCLEVENT pEvent)121 static void shClEventTerm(PSHCLEVENT pEvent) 120 122 { 121 123 if (!pEvent) 122 124 return; 123 125 124 LogFlowFunc(("Event %RU32\n", pEvent-> uID));125 126 if (pEvent->hEv entSem != NIL_RTSEMEVENT)127 { 128 RTSemEvent Destroy(pEvent->hEventSem);129 pEvent->hEv entSem = NIL_RTSEMEVENT;126 LogFlowFunc(("Event %RU32\n", pEvent->idEvent)); 127 128 if (pEvent->hEvtMulSem != NIL_RTSEMEVENT) 129 { 130 RTSemEventMultiDestroy(pEvent->hEvtMulSem); 131 pEvent->hEvtMulSem = NIL_RTSEMEVENT; 130 132 } 131 133 132 134 ShClPayloadFree(pEvent->pPayload); 133 135 134 pEvent-> uID= 0;136 pEvent->idEvent = 0; 135 137 } 136 138 … … 151 153 pSource->uID = uID; 152 154 /* Choose a random event ID starting point. */ 153 pSource-> uEventIDNext = RTRandU32() % VBOX_SHCL_MAX_EVENTS;155 pSource->idNextEvent = RTRandU32Ex(1, VBOX_SHCL_MAX_EVENTS - 1); 154 156 155 157 LogFlowFuncLeaveRC(VINF_SUCCESS); … … 172 174 173 175 pSource->uID = UINT16_MAX; 174 pSource-> uEventIDNext= UINT32_MAX;176 pSource->idNextEvent = UINT32_MAX; 175 177 } 176 178 … … 190 192 RTListNodeRemove(&pEvIt->Node); 191 193 192 ShClEventDestroy(pEvIt);194 shClEventTerm(pEvIt); 193 195 194 196 RTMemFree(pEvIt); 195 197 pEvIt = NULL; 196 198 } 197 }198 199 /**200 * Generates a new event ID for a specific event source.201 *202 * @returns New event ID generated, or 0 on error.203 * @param pSource Event source to generate event for.204 */205 SHCLEVENTID ShClEventIDGenerate(PSHCLEVENTSOURCE pSource)206 {207 AssertPtrReturn(pSource, 0);208 209 LogFlowFunc(("uSource=%RU16: New event: %RU32\n", pSource->uID, pSource->uEventIDNext));210 211 pSource->uEventIDNext++;212 if (pSource->uEventIDNext == VBOX_SHCL_MAX_EVENTS)213 pSource->uEventIDNext = 0;214 215 return pSource->uEventIDNext;216 199 } 217 200 … … 223 206 * @param uID Event ID to get. 224 207 */ 225 inline PSHCLEVENT shclEventGet(PSHCLEVENTSOURCE pSource, SHCLEVENTID uID)226 { 227 PSHCLEVENT pEv It;228 RTListForEach(&pSource->lstEvents, pEv It, SHCLEVENT, Node)229 { 230 if (pEv It->uID == uID)231 return pEv It;208 DECLINLINE(PSHCLEVENT) shclEventGet(PSHCLEVENTSOURCE pSource, SHCLEVENTID idEvent) 209 { 210 PSHCLEVENT pEvent; 211 RTListForEach(&pSource->lstEvents, pEvent, SHCLEVENT, Node) 212 { 213 if (pEvent->idEvent == idEvent) 214 return pEvent; 232 215 } 233 216 234 217 return NULL; 218 } 219 220 /** 221 * Generates a new event ID for a specific event source. 222 * 223 * @returns New event ID generated, or 0 on error. 224 * @param pSource Event source to generate event for. 225 * @deprecated as this does not deal with duplicates. 226 */ 227 SHCLEVENTID ShClEventIDGenerate(PSHCLEVENTSOURCE pSource) 228 { 229 AssertPtrReturn(pSource, 0); 230 231 SHCLEVENTID idEvent = ++pSource->idNextEvent; 232 if (idEvent >= VBOX_SHCL_MAX_EVENTS) 233 pSource->idNextEvent = idEvent = 1; /* zero == error, remember! */ 234 235 LogFlowFunc(("uSource=%RU16: New event: %RU32\n", pSource->uID, idEvent)); 236 return idEvent; 237 } 238 239 /** 240 * Generates a new event ID for a specific event source and registers it. 241 * 242 * @returns New event ID generated, or 0 on error. 243 * @param pSource Event source to generate event for. 244 */ 245 SHCLEVENTID ShClEventIdGenerateAndRegister(PSHCLEVENTSOURCE pSource) 246 { 247 AssertPtrReturn(pSource, 0); 248 249 /* 250 * Allocate an event. 251 */ 252 PSHCLEVENT pEvent = (PSHCLEVENT)RTMemAllocZ(sizeof(SHCLEVENT)); 253 AssertReturn(pEvent, 0); 254 int rc = RTSemEventMultiCreate(&pEvent->hEvtMulSem); 255 AssertRCReturnStmt(rc, RTMemFree(pEvent), 0); 256 257 /* 258 * Allocate an unique event ID. 259 */ 260 for (uint32_t cTries = 0;; cTries++) 261 { 262 SHCLEVENTID idEvent = ++pSource->idNextEvent; 263 if (idEvent < VBOX_SHCL_MAX_EVENTS) 264 { /* likely */ } 265 else 266 pSource->idNextEvent = idEvent = 1; /* zero == error, remember! */ 267 268 if (shclEventGet(pSource, idEvent) == NULL) 269 { 270 271 pEvent->idEvent = idEvent; 272 RTListAppend(&pSource->lstEvents, &pEvent->Node); 273 274 LogFlowFunc(("uSource=%RU16: New event: %#x\n", pSource->uID, idEvent)); 275 return idEvent; 276 } 277 278 AssertBreak(cTries < 4096); 279 } 280 281 RTMemFree(pEvent); 282 return 0; 235 283 } 236 284 … … 246 294 PSHCLEVENT pEvent = RTListGetLast(&pSource->lstEvents, SHCLEVENT, Node); 247 295 if (pEvent) 248 return pEvent-> uID;296 return pEvent->idEvent; 249 297 250 298 return 0; … … 266 314 } 267 315 316 #if 0 /** @todo fix later */ 268 317 /** 269 318 * Registers an event. … … 283 332 if (shclEventGet(pSource, uID) == NULL) 284 333 { 285 PSHCLEVENT pEvent 286 = (PSHCLEVENT)RTMemAllocZ(sizeof(SHCLEVENT)); 334 PSHCLEVENT pEvent = (PSHCLEVENT)RTMemAllocZ(sizeof(SHCLEVENT)); 287 335 if (pEvent) 288 336 { 289 rc = ShClEventCreate(pEvent, uID);337 rc = shClEventInit(pEvent, uID); 290 338 if (RT_SUCCESS(rc)) 291 339 { … … 308 356 return rc; 309 357 } 358 #endif /* later */ 310 359 311 360 /** … … 327 376 if (pEvent) 328 377 { 329 LogFlowFunc(("Event %RU32\n", pEvent-> uID));378 LogFlowFunc(("Event %RU32\n", pEvent->idEvent)); 330 379 331 380 RTListNodeRemove(&pEvent->Node); 332 381 333 ShClEventDestroy(pEvent);382 shClEventTerm(pEvent); 334 383 335 384 RTMemFree(pEvent); … … 368 417 if (pEvent) 369 418 { 370 rc = RTSemEvent Wait(pEvent->hEventSem, uTimeoutMs);419 rc = RTSemEventMultiWait(pEvent->hEvtMulSem, uTimeoutMs); 371 420 if (RT_SUCCESS(rc)) 372 421 { … … 411 460 pEvent->pPayload = pPayload; 412 461 413 rc = RTSemEvent Signal(pEvent->hEventSem);462 rc = RTSemEventMultiSignal(pEvent->hEvtMulSem); 414 463 } 415 464 else
Note:
See TracChangeset
for help on using the changeset viewer.