- Timestamp:
- Mar 8, 2007 6:13:39 PM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 19321
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/hgcm/HGCMThread.cpp
r1301 r1344 69 69 #define HGCMMSG_TF_TERMINATED (0x00000004) 70 70 71 /** @todo consider use of RTReq */ 71 72 72 73 static DECLCALLBACK(int) hgcmWorkerThreadFunc (RTTHREAD ThreadSelf, void *pvUser); … … 100 101 uint32_t m_fu32ThreadFlags; 101 102 102 /* Typical message size for this thread, messages with103 * this size will be put in the Free list and reused,104 * instead of reallocating. Should speed up processing105 * in cases when the message size is fixed.106 */107 uint32_t m_cbMsg;108 109 103 /* Message queue variables. Messages are inserted at tail of message 110 104 * queue. They are consumed by worker thread sequently. If a message was … … 146 140 int MsgPost (HGCMMsgCore *pMsg, PHGCMMSGCALLBACK pfnCallback, bool bWait); 147 141 void MsgComplete (HGCMMsgCore *pMsg, int32_t result); 148 149 bool MsgReuse (HGCMMsgCore *pMsg);150 142 }; 151 143 … … 161 153 void HGCMMsgCore::InitializeCore (uint32_t cbMsg, uint32_t u32MsgId, HGCMThread *pThread) 162 154 { 163 m_cbMsg = cbMsg;164 155 m_u32Version = HGCMMSG_VERSION; 165 156 m_u32Msg = u32MsgId; … … 171 162 172 163 m_pThread = pThread; 173 }174 175 bool HGCMMsgCore::Reuse (void)176 {177 return m_pThread->MsgReuse (this);178 164 } 179 165 … … 218 204 m_eventSend (0), 219 205 m_fu32ThreadFlags (0), 220 m_cbMsg (0),221 206 m_pMsgInputQueueHead (NULL), 222 207 m_pMsgInputQueueTail (NULL), … … 281 266 m_pfnThread = pfnThread; 282 267 m_pvUser = pvUser; 283 m_cbMsg = cbMsg;284 268 285 269 m_fu32ThreadFlags = HGCMMSG_TF_INITIALIZING; … … 352 336 bool fFromFreeList = false; 353 337 354 #if 0 /* @todo to be replaced with RTReq */355 if (cbMsg == m_cbMsg)356 {357 rc = Enter ();358 359 if (VBOX_SUCCESS(rc))360 {361 /* May be we can reuse a previously allocated message memory block. */362 363 if (m_pFreeHead)364 {365 /* Take existing message object from the head of the free list. */366 pmsg = m_pFreeHead;367 368 m_pFreeHead = m_pFreeHead->m_pNext;369 370 if (m_pFreeHead == NULL)371 {372 m_pFreeTail = NULL;373 }374 375 fFromFreeList = true;376 }377 378 Leave ();379 }380 }381 #endif382 383 338 if (!pmsg && VBOX_SUCCESS(rc)) 384 339 { … … 397 352 Reference (); 398 353 399 /* Initialize just allocated or reusedmessage core */354 /* Initialize just allocated message core */ 400 355 pmsg->InitializeCore (cbMsg, u32MsgId, this); 401 356 … … 632 587 } 633 588 634 635 bool HGCMThread::MsgReuse (HGCMMsgCore *pMsg)636 {637 if (pMsg->m_cbMsg != m_cbMsg)638 {639 /* Message no longer belong to the thread. */640 Dereference ();641 642 return false;643 }644 645 int rc = Enter ();646 647 if (VBOX_SUCCESS (rc))648 {649 /* Put the message to the tail of free list. */650 651 /* Reference message because it will still be in free list. */652 pMsg->Reference ();653 654 pMsg->Uninitialize ();655 656 if (m_pFreeTail)657 {658 m_pFreeTail->m_pNext = pMsg;659 }660 else661 {662 m_pFreeHead = pMsg;663 }664 665 m_pFreeTail = pMsg;666 667 Leave ();668 669 /* Dereference the thread. */670 Dereference ();671 }672 673 return true;674 }675 676 677 678 589 /* 679 590 * Thread API. Public interface. -
trunk/src/VBox/Main/include/hgcm/HGCMObjects.h
r1080 r1344 22 22 #ifndef __HGCMOBJECTS__H 23 23 #define __HGCMOBJECTS__H 24 25 #define LOG_GROUP_MAIN_OVERRIDE LOG_GROUP_HGCM 26 #include "Logging.h" 24 27 25 28 #include <iprt/assert.h> … … 54 57 ObjectAVLCore Core; 55 58 56 virtual bool Reuse (void) { return false; };57 58 59 protected: 59 60 virtual ~HGCMObject (void) {}; … … 67 68 void Reference (void) 68 69 { 69 ASMAtomicIncS32 (&cRef); 70 int32_t refCnt = ASMAtomicIncS32 (&cRef); 71 72 Log(("Reference: refCnt = %d\n", refCnt)); 70 73 } 71 74 … … 74 77 int32_t refCnt = ASMAtomicDecS32 (&cRef); 75 78 79 Log(("Dereference: refCnt = %d\n", refCnt)); 80 76 81 AssertRelease(refCnt >= 0); 77 82 … … 81 86 } 82 87 83 if (!Reuse ()) 84 { 85 delete this; 86 } 88 delete this; 87 89 } 88 90 -
trunk/src/VBox/Main/include/hgcm/HGCMThread.h
r1080 r1344 61 61 friend class HGCMThread; 62 62 63 /** Size of entire message block. */64 uint32_t m_cbMsg;65 66 63 /** Version of message header. */ 67 64 uint32_t m_u32Version; … … 89 86 void InitializeCore (uint32_t cbMsg, uint32_t u32MsgId, HGCMThread *pThread); 90 87 91 virtual bool Reuse (void);92 93 88 protected: 94 89 virtual ~HGCMMsgCore () {}; … … 101 96 HGCMThread *Thread (void) { return m_pThread; }; 102 97 103 /** Initialize message after it was allocated or reused. */98 /** Initialize message after it was allocated. */ 104 99 virtual void Initialize (void) {}; 105 100 106 /** Uninitialize message, message will then be freed or put to 107 * a list, from where it can be reused. 108 */ 101 /** Uninitialize message. */ 109 102 virtual void Uninitialize (void) {}; 110 103
Note:
See TracChangeset
for help on using the changeset viewer.