Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
threadjobqueue.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2005 by Jorrit Tyberghein 00003 (C) 2005 by Frank Richter 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_CSUTIL_THREADJOBQUEUE_H__ 00021 #define __CS_CSUTIL_THREADJOBQUEUE_H__ 00022 00027 #include "csextern.h" 00028 #include "iutil/job.h" 00029 #include "fifo.h" 00030 #include "thread.h" 00031 00035 class CS_CSUTIL_EXPORT csThreadJobQueue : public iJobQueue 00036 { 00037 typedef csFIFO<csRef<iJob> > JobFifo; 00038 struct QueueAndRunnableShared 00039 { 00040 JobFifo* jobFifo; 00041 csRef<csMutex> fifoXS; 00042 csRef<csCondition> queueWake; 00043 csRef<iJob>* currentJob; 00044 csRef<csMutex> jobXS; 00045 csRef<csCondition> jobFinish; 00046 }; 00047 class CS_CSUTIL_EXPORT QueueRunnable : public csRunnable 00048 { 00049 int refCount; 00050 QueueAndRunnableShared sharedData; 00051 public: 00052 QueueRunnable (const QueueAndRunnableShared& sharedData); 00053 virtual ~QueueRunnable(); 00054 00055 virtual void Run (); 00056 virtual void IncRef(); 00057 virtual void DecRef(); 00058 virtual int GetRefCount(); 00059 }; 00060 csRef<csThread> queueThread; 00061 QueueAndRunnableShared sharedData; 00062 csRef<iJob> currentJob; 00063 csRef<csMutex> jobFinishMutex; 00064 // stats 00065 uint jobsAdded, jobsPulled, jobsWaited, jobsUnqueued; 00066 public: 00067 SCF_DECLARE_IBASE; 00068 00069 csThreadJobQueue(); 00070 virtual ~csThreadJobQueue(); 00071 00072 virtual void Enqueue (iJob* job); 00073 virtual void PullAndRun (iJob* job); 00074 virtual void Unqueue (iJob* job, bool waitIfCurrent = true); 00075 }; 00076 00077 #endif // __CS_CSUTIL_THREADJOBQUEUE_H__
Generated for Crystal Space by doxygen 1.3.9.1