Changeset 39713 in vbox
- Timestamp:
- Jan 7, 2012 2:03:17 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-all/EventImpl.cpp
r39710 r39713 430 430 class EventMapList 431 431 { 432 EventMapRecord *mHead;432 EventMapRecord *mHead; 433 433 uint32_t mSize; 434 434 public: … … 440 440 ~EventMapList() 441 441 { 442 EventMapRecord * aCur = mHead;443 while ( aCur)444 { 445 EventMapRecord * aNext = aCur->mNext;446 aCur->release();447 aCur = aNext;442 EventMapRecord *pCur = mHead; 443 while (pCur) 444 { 445 EventMapRecord *pNext = pCur->mNext; 446 pCur->release(); 447 pCur = pNext; 448 448 } 449 449 } … … 454 454 * will always complete. 455 455 */ 456 void add(ListenerRecord *aRec)457 { 458 EventMapRecord * aNew = new EventMapRecord(aRec);459 aNew->mNext = mHead;456 void add(ListenerRecord *aRec) 457 { 458 EventMapRecord *pNew = new EventMapRecord(aRec); 459 pNew->mNext = mHead; 460 460 if (mHead) 461 mHead->mPrev = aNew;462 mHead = aNew;461 mHead->mPrev = pNew; 462 mHead = pNew; 463 463 mSize++; 464 464 } … … 469 469 * enough for iterators to allow long and probably intrusive callbacks. 470 470 */ 471 void remove(ListenerRecord *aRec)472 { 473 EventMapRecord * aCur = mHead;474 while ( aCur)475 { 476 EventMapRecord* aNext = aCur->mNext;477 if ( aCur->ref() == aRec)471 void remove(ListenerRecord *aRec) 472 { 473 EventMapRecord *pCur = mHead; 474 while (pCur) 475 { 476 EventMapRecord* aNext = pCur->mNext; 477 if (pCur->ref() == aRec) 478 478 { 479 if ( aCur == mHead)479 if (pCur == mHead) 480 480 mHead = aNext; 481 aCur->kill();481 pCur->kill(); 482 482 mSize--; 483 483 // break? 484 484 } 485 aCur = aNext;485 pCur = aNext; 486 486 } 487 487 } … … 494 494 struct iterator 495 495 { 496 EventMapRecord*mCur;497 498 iterator()499 : mCur(0)500 {}501 502 explicit503 iterator(EventMapRecord*aCur)504 : mCur(aCur)505 {506 // Prevent element removal, till we're at it507 if (mCur)508 mCur->addRef();509 }510 511 ~iterator()512 {513 if (mCur)514 mCur->release();515 }516 517 ListenerRecord*518 operator*() const519 {520 return mCur->ref();521 }522 523 EventMapList::iterator&524 operator++()525 {526 EventMapRecord* aPrev = mCur;527 do {528 mCur = mCur->mNext;529 } while (mCur && !mCur->mAlive);530 531 // now we can safely release previous element532 aPrev->release();533 534 // And grab the new current535 if (mCur)536 mCur->addRef();537 538 return *this;539 }540 541 bool542 operator==(const EventMapList::iterator& aOther) const543 {544 return mCur == aOther.mCur;545 }546 547 bool548 operator!=(const EventMapList::iterator& aOther) const549 {550 return mCur != aOther.mCur;551 }496 EventMapRecord *mCur; 497 498 iterator() 499 : mCur(0) 500 {} 501 502 explicit 503 iterator(EventMapRecord *aCur) 504 : mCur(aCur) 505 { 506 // Prevent element removal, till we're at it 507 if (mCur) 508 mCur->addRef(); 509 } 510 511 ~iterator() 512 { 513 if (mCur) 514 mCur->release(); 515 } 516 517 ListenerRecord * 518 operator*() const 519 { 520 return mCur->ref(); 521 } 522 523 EventMapList::iterator & 524 operator++() 525 { 526 EventMapRecord *pPrev = mCur; 527 do { 528 mCur = mCur->mNext; 529 } while (mCur && !mCur->mAlive); 530 531 // now we can safely release previous element 532 pPrev->release(); 533 534 // And grab the new current 535 if (mCur) 536 mCur->addRef(); 537 538 return *this; 539 } 540 541 bool 542 operator==(const EventMapList::iterator& aOther) const 543 { 544 return mCur == aOther.mCur; 545 } 546 547 bool 548 operator!=(const EventMapList::iterator& aOther) const 549 { 550 return mCur != aOther.mCur; 551 } 552 552 }; 553 553 … … 803 803 { 804 804 aAlock.release(); 805 rc = 805 rc = mListener->HandleEvent(aEvent); 806 806 #ifdef RT_OS_WINDOWS 807 807 Assert(rc != RPC_E_WRONG_THREAD); … … 813 813 return rc; 814 814 } 815 else 816 return enqueue(aEvent); 815 return enqueue(aEvent); 817 816 } 818 817 … … 1032 1031 AssertComRCReturn(hrc, hrc); 1033 1032 1034 EventMapList & listeners = m->mEvMap[(int)evType-FirstEvent];1033 EventMapList &listeners = m->mEvMap[(int)evType - FirstEvent]; 1035 1034 1036 1035 /* Anyone interested in this event? */ … … 1051 1050 pit = m->mPendingMap.find(aEvent); 1052 1051 } 1053 for(EventMapList::iterator it = listeners.begin(); 1054 it != listeners.end(); ++it) 1052 for (EventMapList::iterator it = listeners.begin(); 1053 it != listeners.end(); 1054 ++it) 1055 1055 { 1056 1056 HRESULT cbRc;
Note:
See TracChangeset
for help on using the changeset viewer.