VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
asyncJobServer.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright 2015 VT MAK
3 *******************************************************************************/
4 
7 
8 #pragma once
9 
10 #include <vrfutil/vrfutilDefines.h>
11 
12 #include <stdlib.h>
13 #include <memory>
14 #include <list>
15 #include <map>
16 
18 #include <tbb/concurrent_hash_map.h>
19 #include <tbb/spin_mutex.h>
20 #ifdef WIN32
21  #include <WinSock2.h>
22 #endif
23 
24 #include <boost/noncopyable.hpp>
25 
26 #include <vrfutil/objectCounter.h>
27 
28 #include <tbb/task_arena.h>
29 
30 class DtAsyncJob;
31 class DtAsyncJobMapEntry;
34 {
40 };
41 
44 #ifdef DtObjectDebugger_Enable
45  : public DtObjectDebugger<DtAsyncJobResult>
46 #endif
47 {
48 public:
49  virtual ~DtAsyncJobResult();
50 };
51 
53 
54 
56 typedef std::map<size_t, std::weak_ptr<DtAsyncJobMapEntry> > DtAsyncJobMap;
57 
62 {
63 public:
65  DtAsyncJobServer(unsigned maxThreads = 0);
66 
68  virtual ~DtAsyncJobServer();
69 
76  virtual std::shared_ptr<DtAsyncJobMapEntry> addJob(DtAsyncJob* job);
77 
79  virtual void cancelAllJobs();
80 
82  virtual void cancelAllJobsAndWait();
83 
85  virtual bool empty() const;
86 
88  virtual bool running() const;
89 
91  virtual void printAsyncJobMap();
92 
94  virtual void tick();
95 
96  virtual void waitOnJobs();
97 
98 protected:
99  friend class DtAsyncJobMapEntry;
100  friend class DtAsyncJob;
101 
102  typedef tbb::spin_mutex Mutex;
103 
105  virtual size_t getNextId();
106 
108  virtual void remove(size_t id);
109 
111  virtual void jobDestroyed(DtAsyncJob&);
112 
115 
117  size_t myNextId;
118 
120  size_t myNumTasks;
121 
122  typedef std::list<DtAsyncJob*> JobList;
125 
126  class DT_DLL_vrfutil JobListScopeGuard : boost::noncopyable
127  {
128  public:
131 
132  private:
134  JobList::iterator i;
135  };
136 
137 
138  std::unique_ptr<tbb::task_arena> myTaskArena;
139 
141  static long long theQuittingIoPeriod;
142 };
143 
DtAsyncJobStatus
State of job.
Definition: asyncJobServer.h:33
An asynchronous job that can be added to and executed by a job server. Since this class derives from ...
Definition: asyncJob.h:46
tbb::spin_mutex Mutex
Definition: asyncJobServer.h:102
std::unique_ptr< tbb::task_arena > myTaskArena
Definition: asyncJobServer.h:138
std::list< DtAsyncJob * > JobList
Definition: asyncJobServer.h:122
static long long theQuittingIoPeriod
Io period - milliseconds.
Definition: asyncJobServer.h:141
size_t myNumTasks
Definition: asyncJobServer.h:120
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:31
Default on in debug, off in release.
Definition: objectCounter.h:27
Mutex myAsyncJobMapMutex
Definition: asyncJobServer.h:113
DtAsyncJobMap myAsyncJobMap
Definition: asyncJobServer.h:114
Definition: asyncJobServer.h:37
Mutex myNumTasksMutex
Definition: asyncJobServer.h:119
Definition: asyncJobServer.h:38
Definition: asyncJobServer.h:126
Definition: asyncJobServer.h:36
Base class for result of job.
Definition: asyncJobServer.h:43
Definition: asyncJobServer.h:39
Handle to async job.
Definition: asyncJobMapEntry.h:29
DtAsyncJobServer & server
Definition: asyncJobServer.h:133
JobList myCurrentJobs
Definition: asyncJobServer.h:124
Mutex myJobListMutex
Definition: asyncJobServer.h:123
#define DT_DLL_vrfutil
This file is used to determine how to build Disable inconsistent dll linkage warning Visual Studio 6...
Definition: vrfutilDefines.h:34
Manages async job objects.
Definition: asyncJobServer.h:61
Mutex myIdGenMutex
Definition: asyncJobServer.h:116
std::map< size_t, std::weak_ptr< DtAsyncJobMapEntry > > DtAsyncJobMap
Map of job IDs to job entries.
Definition: asyncJobServer.h:56
size_t myNextId
Definition: asyncJobServer.h:117
Definition: asyncJobServer.h:35
JobList::iterator i
Definition: asyncJobServer.h:134

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)