For terms and conditions, read Terms.dox. Distribution is allowed as GPL as long as these comments remain included verbatim.
You are free to use and modify this file to the extent allowed by the GPL at the exclusive condition that you send me a notification of your intent to use or modify this file. Send such notifications to digitalmastrmind_at_hotmail_dot_com or visit http://pages.infinit.net/moonligh/eMule for other details. I would appreciate it if you would submit modifications to me for implementation instead of implementing changes yourself. Comments and suggestions are welcome as well. All disclosed source code is considered GPL'd unless otherwise noted. All files created specifically for building my Doxygen-based projects web site (.dox) remain my exclusive property. All my own files contain a reference to this text and should be treated as if this was replicated in each of them. If you change my files, add comments below my header telling me who you are, what you changed and why so I know who to give credits to when I update my files. Modification of this file (Terms.txt) is not allowed. Distribution is allowed as GPL as long this file is untouched and accompanies my own source files that refer to it. - Moonlight.
#include "StdAfx.h" #include "WorkQueue.h" CWorkQueue::CWorkQueue(CSyncObject *pextEvent) : m_WorkItem(NULL), m_WorkEvent(FALSE, TRUE), m_PendDelete(false) { m_pThreadEvents[0] = pextEvent; m_pThreadEvents[1] = &m_WorkEvent; m_pWorkerThread = AfxBeginThread((UINT (*)(void*)) CWorkQueue::WorkerThreadStart, this); } CWorkQueue::~CWorkQueue(void) { m_PendDelete = true; m_WorkEvent.SetEvent(); while(m_pWorkerThread) Sleep(0); } bool CWorkQueue::AddItem (CWorkQueueItem *pWork, bool uniqueItem) { if (uniqueItem && CheckItem(pWork)) return false; else { CSingleLock tempLock(&m_WorkQueueMutex, TRUE); m_WorkQueue.AddTail(pWork); m_WorkEvent.SetEvent(); return true; } } bool CWorkQueue::DelItem (CWorkQueueItem *pWork) { CSingleLock tempLock(&m_WorkQueueMutex, TRUE); POSITION tempPOS = m_WorkQueue.Find(pWork); if (tempPOS) { pWork->QueueDelCB(); m_WorkQueue.RemoveAt(tempPOS); return true; } return false; } bool CWorkQueue::CheckItem (CWorkQueueItem *pWork, bool ProcessOnly) { if (!ProcessOnly) { CSingleLock tempLock(&m_WorkQueueMutex, TRUE); POSITION tempPOS = m_WorkQueue.Find(pWork); if (tempPOS) return true; } if (m_WorkItem == pWork) return true; return false; } bool CWorkQueue::WorkerThread (void) { CMultiLock ThreadLock(m_pThreadEvents, 2); CSingleLock QueueLock(&m_WorkQueueMutex); int read; while (read = ThreadLock.Lock(INFINITE, FALSE) != WAIT_OBJECT_0 && !m_PendDelete) { QueueLock.Lock(); if (m_WorkQueue.IsEmpty()) { m_WorkEvent.ResetEvent(); QueueLock.Unlock(); } else { m_WorkItem = m_WorkQueue.RemoveHead(); QueueLock.Unlock(); if (m_WorkItem) m_WorkItem->ThreadWork(); m_WorkItem = NULL; } } m_pWorkerThread = NULL; return true; }
#include "StdAfx.h"
#include "WorkQueue.h"
1.3.4