csutil/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 "csutil/fifo.h" 00029 #include "csutil/scf_implementation.h" 00030 #include "csutil/thread.h" 00031 #include "iutil/job.h" 00032 00036 class CS_CRYSTALSPACE_EXPORT csThreadJobQueue : 00037 public scfImplementation1<csThreadJobQueue, iJobQueue> 00038 { 00039 typedef csFIFO<csRef<iJob> > JobFifo; 00040 struct QueueAndRunnableShared 00041 { 00042 JobFifo* jobFifo; 00043 csRef<csMutex> fifoXS; 00044 csRef<csCondition> queueWake; 00045 csRef<iJob>* currentJob; 00046 csRef<csMutex> jobXS; 00047 csRef<csCondition> jobFinish; 00048 }; 00049 class CS_CRYSTALSPACE_EXPORT QueueRunnable : public csRunnable 00050 { 00051 int refCount; 00052 QueueAndRunnableShared sharedData; 00053 public: 00054 QueueRunnable (const QueueAndRunnableShared& sharedData); 00055 virtual ~QueueRunnable(); 00056 00057 virtual void Run (); 00058 virtual void IncRef(); 00059 virtual void DecRef(); 00060 virtual int GetRefCount(); 00061 }; 00062 csRef<csThread> queueThread; 00063 QueueAndRunnableShared sharedData; 00064 csRef<iJob> currentJob; 00065 csRef<csMutex> jobFinishMutex; 00066 // stats 00067 uint jobsAdded, jobsPulled, jobsWaited, jobsUnqueued; 00068 public: 00069 00070 csThreadJobQueue(); 00071 virtual ~csThreadJobQueue(); 00072 00073 virtual void Enqueue (iJob* job); 00074 virtual void PullAndRun (iJob* job); 00075 virtual void Unqueue (iJob* job, bool waitIfCurrent = true); 00076 }; 00077 00078 #endif // __CS_CSUTIL_THREADJOBQUEUE_H__
Generated for Crystal Space by doxygen 1.4.7