VR-Forces 4.8 Class Documentation
 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  : public DtObjectDebugger<DtAsyncJobResult>
45 {
46 public:
47  virtual ~DtAsyncJobResult();
48 };
49 
51 
54 {
55  static size_t hash( const size_t& x )
56  {
57  return x;
58  }
59 
60  static bool equal( const size_t& x, const size_t& y )
61  {
62  return x==y;
63  }
64 };
65 
66 
68 typedef tbb::concurrent_hash_map<size_t, boost::weak_ptr<DtAsyncJobMapEntry>, MyHashCompare> DtAsyncJobMap;
69 
74 {
75 public:
78 
80  virtual ~DtAsyncJobServer();
81 
88  virtual boost::shared_ptr<DtAsyncJobMapEntry> addJob(DtAsyncJob* job);
89 
91  virtual void cancelAllJobs();
92 
94  virtual void cancelAllJobsAndWait();
95 
97  virtual bool empty() const;
98 
100  virtual bool running() const;
101 
103  virtual void printAsyncJobMap();
104 
106  virtual void tick();
107 
108 protected:
109  friend class DtAsyncJobMapEntry;
110  friend class DtAsyncJob;
111 
112  typedef tbb::spin_mutex Mutex;
113 
115  virtual size_t getNextId();
116 
118  virtual void remove(size_t id);
119 
121  virtual void jobDestroyed(DtAsyncJob&);
122 
124 
126  size_t myNextId;
127 
129  size_t myNumTasks;
130 
131  typedef std::list<DtAsyncJob*> JobList;
134 
135  class DT_DLL_vrfutil JobListScopeGuard : boost::noncopyable
136  {
137  public:
140 
141  private:
143  JobList::iterator i;
144  };
145 };
146 
static bool equal(const size_t &x, const size_t &y)
Definition: asyncJobServer.h:60
DtAsyncJobStatus
State of job.
Definition: asyncJobServer.h:33
An asynchronous job that can be added to and executed by a job server.
Definition: asyncJob.h:47
tbb::spin_mutex Mutex
Definition: asyncJobServer.h:112
std::list< DtAsyncJob * > JobList
Definition: asyncJobServer.h:131
size_t myNumTasks
Definition: asyncJobServer.h:129
#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:123
Definition: asyncJobServer.h:37
Mutex myNumTasksMutex
Definition: asyncJobServer.h:128
tbb::concurrent_hash_map< size_t, boost::weak_ptr< DtAsyncJobMapEntry >, MyHashCompare > DtAsyncJobMap
A concurrent hash map.
Definition: asyncJobServer.h:68
Definition: asyncJobServer.h:38
Definition: asyncJobServer.h:135
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:55
Structure that defines hashing and comparison operations for users.
Definition: asyncJobServer.h:53
DtAsyncJobServer & server
Definition: asyncJobServer.h:142
JobList myCurrentJobs
Definition: asyncJobServer.h:133
Mutex myJobListMutex
Definition: asyncJobServer.h:132
#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:73
Mutex myIdGenMutex
Definition: asyncJobServer.h:125
size_t myNextId
Definition: asyncJobServer.h:126
Definition: asyncJobServer.h:35
JobList::iterator i
Definition: asyncJobServer.h:143

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)