Changeset 50701 in vbox
- Timestamp:
- Mar 5, 2014 11:55:54 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-darwin.cpp
r50699 r50701 124 124 bool isVmmDev(IOPCIDevice *pIOPCIDevice); 125 125 126 protected: 127 IOWorkLoop *m_pWorkLoop; 128 126 129 public: 127 130 virtual bool start(IOService *pProvider); 128 131 virtual void stop(IOService *pProvider); 129 132 virtual bool terminate(IOOptionBits fOptions); 133 IOWorkLoop * getWorkLoop(); 130 134 }; 131 135 … … 223 227 static IONotifier *g_pSleepNotifier = NULL; 224 228 229 /* States of atimic variable aimed to protect dynamic object allocation in SMP environment. */ 230 #define VBOXGUEST_OBJECT_UNINITIALIZED (0) 231 #define VBOXGUEST_OBJECT_INITIALIZING (1) 232 #define VBOXGUEST_OBJECT_INITIALIZED (2) 233 #define VBOXGUEST_OBJECT_INVALID (3) 234 /** Atomic variable used to protect work loop allocation when multiple threads attempt to obtain it. */ 235 static uint8_t volatile g_fWorkLoopCreated = VBOXGUEST_OBJECT_UNINITIALIZED; 225 236 226 237 … … 660 671 */ 661 672 673 674 IOWorkLoop * 675 org_virtualbox_VBoxGuest::getWorkLoop() 676 { 677 /* Handle the case when work loop was not created yet */ 678 if(ASMAtomicCmpXchgU8(&g_fWorkLoopCreated, VBOXGUEST_OBJECT_INITIALIZING, VBOXGUEST_OBJECT_UNINITIALIZED)) 679 { 680 m_pWorkLoop = IOWorkLoop::workLoop(); 681 if (m_pWorkLoop) 682 { 683 /* Notify the rest of threads about the fact that work 684 * loop was successully allocated and can be safely used */ 685 PDEBUG("created new work loop\n"); 686 ASMAtomicWriteU8(&g_fWorkLoopCreated, VBOXGUEST_OBJECT_INITIALIZED); 687 } 688 else 689 { 690 /* Notify the rest of threads about the fact that there was 691 * an error during allocation of a work loop */ 692 PDEBUG("unable new work loop\n"); 693 ASMAtomicWriteU8(&g_fWorkLoopCreated, VBOXGUEST_OBJECT_UNINITIALIZED); 694 } 695 } 696 else 697 { 698 /* Handle the case when work loop is currently being 699 * created or it was previously failed to create */ 700 uint8_t fWorkLoopCreated = VBOXGUEST_OBJECT_INVALID; 701 while (fWorkLoopCreated != VBOXGUEST_OBJECT_INITIALIZED 702 && fWorkLoopCreated != VBOXGUEST_OBJECT_UNINITIALIZED) 703 { 704 fWorkLoopCreated = ASMAtomicReadU8(&g_fWorkLoopCreated); 705 thread_block(0); 706 } 707 if (fWorkLoopCreated == VBOXGUEST_OBJECT_INITIALIZED) 708 PDEBUG("returned existing work loop"); 709 else 710 PDEBUG("work loop was not allocated correctly"); 711 } 712 713 return m_pWorkLoop; 714 } 715 716 662 717 /** 663 718 * Perform pending wake ups in work loop context. … … 690 745 org_virtualbox_VBoxGuest::setupVmmDevInterrupts(IOService *pProvider) 691 746 { 692 IOWorkLoop *pWorkLoop = (IOWorkLoop *)getWorkLoop();747 IOWorkLoop *pWorkLoop = getWorkLoop(); 693 748 694 749 if (!pWorkLoop)
Note:
See TracChangeset
for help on using the changeset viewer.