VR-Forces 5.0.1 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 
17 #include <tbb/concurrent_hash_map.h>
18 #include <tbb/spin_mutex.h>
19 #ifdef WIN32
20  #include <WinSock2.h>
21 #endif
22 
23 #include <boost/shared_ptr.hpp>
24 #include <boost/weak_ptr.hpp>
25 #include <boost/noncopyable.hpp>
26 
27 #include <vrfutil/objectCounter.h>
28 
29 class DtAsyncJob;
30 class DtAsyncJobMapEntry;
31 
34 {
40 };
41 
44 #ifdef DtObjectDebugger_Enable
45  : public DtObjectDebugger<DtAsyncJobResult>
46 #endif
47 {
48 public:
49  virtual ~DtAsyncJobResult();
50 };
51 
53 
56 {
57  static size_t hash( const size_t& x )
58  {
59  return x;
60  }
61 
62  static bool equal( const size_t& x, const size_t& y )
63  {
64  return x==y;
65  }
66 };
67 
68 
70 typedef tbb::concurrent_hash_map<size_t, boost::weak_ptr<DtAsyncJobMapEntry>, MyHashCompare> DtAsyncJobMap;
71 
76 {
77 public:
80 
82  virtual ~DtAsyncJobServer();
83 
90  virtual boost::shared_ptr<DtAsyncJobMapEntry> addJob(DtAsyncJob* job);
91 
93  virtual void cancelAllJobs();
94 
96  virtual void cancelAllJobsAndWait();
97 
99  virtual bool empty() const;
100 
102  virtual bool running() const;
103 
105  virtual void printAsyncJobMap();
106 
108  virtual void tick();
109 
110 protected:
111  friend class DtAsyncJobMapEntry;
112  friend class DtAsyncJob;
113 
114  typedef tbb::spin_mutex Mutex;
115 
117  virtual size_t getNextId();
118 
120  virtual void remove(size_t id);
121 
123  virtual void jobDestroyed(DtAsyncJob&);
124 
126 
128  size_t myNextId;
129 
131  size_t myNumTasks;
132 
133  typedef std::list<DtAsyncJob*> JobList;
136 
137  class DT_DLL_vrfutil JobListScopeGuard : boost::noncopyable
138  {
139  public:
142 
143  private:
145  JobList::iterator i;
146  };
147 };
148 
static bool equal(const size_t &x, const size_t &y)
Definition: asyncJobServer.h:62
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:48
tbb::spin_mutex Mutex
Definition: asyncJobServer.h:114
std::list< DtAsyncJob * > JobList
Definition: asyncJobServer.h:133
size_t myNumTasks
Definition: asyncJobServer.h:131
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:265
Default on in debug, off in release.
Definition: objectCounter.h:31
DtAsyncJobMap myAsyncJobMap
Definition: asyncJobServer.h:125
Definition: asyncJobServer.h:37
Mutex myNumTasksMutex
Definition: asyncJobServer.h:130
tbb::concurrent_hash_map< size_t, boost::weak_ptr< DtAsyncJobMapEntry >, MyHashCompare > DtAsyncJobMap
A concurrent hash map.
Definition: asyncJobServer.h:70
Definition: asyncJobServer.h:38
Definition: asyncJobServer.h:137
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
static size_t hash(const size_t &x)
Definition: asyncJobServer.h:57
Structure that defines hashing and comparison operations for users.
Definition: asyncJobServer.h:55
DtAsyncJobServer & server
Definition: asyncJobServer.h:144
JobList myCurrentJobs
Definition: asyncJobServer.h:135
Mutex myJobListMutex
Definition: asyncJobServer.h:134
#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:75
Mutex myIdGenMutex
Definition: asyncJobServer.h:127
size_t myNextId
Definition: asyncJobServer.h:128
Definition: asyncJobServer.h:35
JobList::iterator i
Definition: asyncJobServer.h:145

Document ID: Generated on Mon Jun 20 00:38:30 EDT 2022 from SVN revision 244029
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)