iutil/threadmanager.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

iutil/threadmanager.h

    00001 /*
    00002   Copyright (C) 2008 by Michael Gist
    00003
    00004   This library is free software; you can redistribute it and/or
    00005   modify it under the terms of the GNU Lesser General Public
    00006   License as published by the Free Software Foundation; either
    00007   version 2 of the License, or (at your option) any later version.
    00008
    00009   This library is distributed in the hope that it will be useful,
    00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012   Library General Public License for more details.
    00013
    00014   You should have received a copy of the GNU Library General Public
    00015   License along with this library; if not, write to the Free
    00016   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00017 */
    00018
    00019 #ifndef __CS_IUTIL_THREADMANAGER_H__
    00020 #define __CS_IUTIL_THREADMANAGER_H__
    00021
    00022 #include "csutil/refcount.h"
    00023 #include "csutil/refarr.h"
    00024 #include "csutil/threading/condition.h"
    00025 #include "csutil/threading/mutex.h"
    00026
    00027 struct iConfigManager;
    00028 struct iJob;
    00029
    00030 struct iThreadReturn : public virtual iBase
    00031 {
    00032   SCF_INTERFACE(iThreadReturn, 1, 2, 0);
    00033
    00034   virtual bool IsFinished() = 0;
    00035   virtual bool WasSuccessful() = 0;
    00036   virtual void* GetResultPtr() = 0;
    00037   virtual csRef<iBase> GetResultRefPtr() = 0;
    00038
    00039   virtual void MarkFinished() = 0;
    00040   virtual void MarkSuccessful() = 0;
    00041   virtual void SetResult(void* result) = 0;
    00042   virtual void SetResult(csRef<iBase> result) = 0;
    00043
    00044   virtual void Copy(iThreadReturn* other) = 0;
    00045
    00046   virtual void Wait(bool process = true) = 0;
    00047   virtual void SetWaitPtrs(CS::Threading::Condition* c, CS::Threading::Mutex* m) = 0;
    00048
    00049   virtual void SetJob(iJob* job) = 0;
    00050   virtual iJob* GetJob() const = 0;
    00051 };
    00052
    00053 enum QueueType
    00054 {
    00055   THREADED = 0,
    00056   THREADEDL,
    00057   HIGH,
    00058   MED,
    00059   LOW
    00060 };
    00061
    00073 struct iThreadManager : public virtual iBase
    00074 {
    00075   SCF_INTERFACE(iThreadManager, 3, 0, 1);
    00076
    00077   virtual void Init(iConfigManager* config) = 0;
    00078   virtual void Process(uint num = 1) = 0;
    00079   virtual void PushToQueue(QueueType queueType, iJob* job) = 0;
    00080   virtual bool Wait(csRefArray<iThreadReturn>& threadReturns, bool process = true) = 0;
    00081   virtual bool RunNow(QueueType queueType, bool wait, bool forceQueue) = 0;
    00082   virtual int32 GetThreadCount() = 0;
    00083   virtual void SetAlwaysRunNow(bool v) = 0;
    00084   virtual bool GetAlwaysRunNow() = 0;
    00085   virtual bool Exiting() = 0;
    00087   virtual void ProcessAll () = 0;
    00088 };
    00089
    00090 // Interface macros
    00091 #define THREADED_INTERFACE(function) \
    00092   virtual csRef<iThreadReturn> function() = 0; \
    00093   virtual csRef<iThreadReturn> function##Wait() = 0
    00094
    00095 #define THREADED_INTERFACE1(function, arg1) \
    00096   virtual csRef<iThreadReturn> function(arg1) = 0; \
    00097   virtual csRef<iThreadReturn> function##Wait(arg1) = 0
    00098
    00099 #define THREADED_INTERFACE2(function, arg1, arg2) \
    00100   virtual csRef<iThreadReturn> function(arg1, arg2) = 0; \
    00101   virtual csRef<iThreadReturn> function##Wait(arg1, arg2) = 0
    00102
    00103 #define THREADED_INTERFACE3(function, arg1, arg2, arg3) \
    00104   virtual csRef<iThreadReturn> function(arg1, arg2, arg3) = 0; \
    00105   virtual csRef<iThreadReturn> function##Wait(arg1, arg2, arg3) = 0
    00106
    00107 #define THREADED_INTERFACE4(function, arg1, arg2, arg3, arg4) \
    00108   virtual csRef<iThreadReturn> function(arg1, arg2, arg3, arg4) = 0; \
    00109   virtual csRef<iThreadReturn> function##Wait(arg1, arg2, arg3, arg4) = 0
    00110
    00111 #define THREADED_INTERFACE5(function, arg1, arg2, arg3, arg4, arg5) \
    00112   virtual csRef<iThreadReturn> function(arg1, arg2, arg3, arg4, arg5) = 0; \
    00113   virtual csRef<iThreadReturn> function##Wait(arg1, arg2, arg3, arg4, arg5) = 0
    00114
    00115 #define THREADED_INTERFACE6(function, arg1, arg2, arg3, arg4, arg5, arg6) \
    00116   virtual csRef<iThreadReturn> function(arg1, arg2, arg3, arg4, arg5, arg6) = 0; \
    00117   virtual csRef<iThreadReturn> function##Wait(arg1, arg2, arg3, arg4, arg5, arg6) = 0
    00118
    00119 #define THREADED_INTERFACE7(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
    00120   virtual csRef<iThreadReturn> function(arg1, arg2, arg3, arg4, arg5, arg6, arg7) = 0; \
    00121   virtual csRef<iThreadReturn> function##Wait(arg1, arg2, arg3, arg4, arg5, arg6, arg7) = 0
    00122
    00123 #define THREADED_INTERFACE8(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
    00124   virtual csRef<iThreadReturn> function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) = 0; \
    00125   virtual csRef<iThreadReturn> function##Wait(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) = 0
    00126
    00127 #define THREADED_INTERFACE9(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \
    00128   virtual csRef<iThreadReturn> function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) = 0; \
    00129   virtual csRef<iThreadReturn> function##Wait(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) = 0
    00130
    00131 #define THREADED_INTERFACE10(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) \
    00132   virtual csRef<iThreadReturn> function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) = 0; \
    00133   virtual csRef<iThreadReturn> function##Wait(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) = 0
    00134
    00135 #define THREADED_INTERFACE11(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) \
    00136   virtual csRef<iThreadReturn> function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) = 0; \
    00137   virtual csRef<iThreadReturn> function##Wait(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) = 0
    00138
    00139 #define THREADED_INTERFACE12(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) \
    00140   virtual csRef<iThreadReturn> function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) = 0; \
    00141   virtual csRef<iThreadReturn> function##Wait(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) = 0
    00142
    00143 #define THREADED_INTERFACE13(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13) \
    00144   virtual csRef<iThreadReturn> function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13) = 0; \
    00145   virtual csRef<iThreadReturn> function##Wait(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13) = 0
    00146
    00147 #define THREADED_INTERFACE14(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14) \
    00148   virtual csRef<iThreadReturn> function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14) = 0; \
    00149   virtual csRef<iThreadReturn> function##Wait(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14) = 0
    00150
    00151 #define THREADED_INTERFACE15(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15) \
    00152   virtual csRef<iThreadReturn> function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15) = 0; \
    00153   virtual csRef<iThreadReturn> function##Wait(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15) = 0
    00154
    00155 #endif // __CS_IUTIL_THREADMANAGER_H__