37 //
38 // Gang/Group class hierarchy:
39 // AbstractWorkGang
40 // WorkGang
41 // YieldingFlexibleWorkGang (defined in another file)
42 //
43 // Worker class hierarchy:
44 // AbstractGangWorker (subclass of WorkerThread)
45 // GangWorker
46 // YieldingFlexibleGangWorker (defined in another file)
47
48 // Forward declarations of classes defined here
49
50 class AbstractGangWorker;
51 class Semaphore;
52 class WorkGang;
53
54 // An abstract task to be worked on by a gang.
55 // You subclass this to supply your own work() method
56 class AbstractGangTask {
57 const char* _name;
58 const uint _gc_id;
59
60 public:
61 explicit AbstractGangTask(const char* name) :
62 _name(name),
63 _gc_id(GCId::current_or_undefined())
64 {}
65
66 // The abstract work method.
67 // The argument tells you which member of the gang you are.
68 virtual void work(uint worker_id) = 0;
69
70 // Debugging accessor for the name.
71 const char* name() const { return _name; }
72 const uint gc_id() const { return _gc_id; }
73 };
74
75 struct WorkData {
76 AbstractGangTask* _task;
77 uint _worker_id;
78 WorkData(AbstractGangTask* task, uint worker_id) : _task(task), _worker_id(worker_id) {}
79 };
80
81 // Interface to handle the synchronization between the coordinator thread and the worker threads,
82 // when a task is dispatched out to the worker threads.
83 class GangTaskDispatcher : public CHeapObj<mtGC> {
84 public:
85 virtual ~GangTaskDispatcher() {}
86
87 // Coordinator API.
88
89 // Distributes the task out to num_workers workers.
90 // Returns when the task has been completed by all workers.
91 virtual void coordinator_execute_on_workers(AbstractGangTask* task, uint num_workers) = 0;
92
93 // Worker API.
94
95 // Waits for a task to become available to the worker.
96 // Returns when the worker has been assigned a task.
97 virtual WorkData worker_wait_for_task() = 0;
|
37 //
38 // Gang/Group class hierarchy:
39 // AbstractWorkGang
40 // WorkGang
41 // YieldingFlexibleWorkGang (defined in another file)
42 //
43 // Worker class hierarchy:
44 // AbstractGangWorker (subclass of WorkerThread)
45 // GangWorker
46 // YieldingFlexibleGangWorker (defined in another file)
47
48 // Forward declarations of classes defined here
49
50 class AbstractGangWorker;
51 class Semaphore;
52 class WorkGang;
53
54 // An abstract task to be worked on by a gang.
55 // You subclass this to supply your own work() method
56 class AbstractGangTask {
57 BehaviourProvider* _provider;
58 const char* _name;
59 const uint _gc_id;
60
61 public:
62 explicit AbstractGangTask(const char* name) :
63 _provider(NULL),
64 _name(name),
65 _gc_id(GCId::current_or_undefined())
66 {}
67
68 // The abstract work method.
69 // The argument tells you which member of the gang you are.
70 virtual void work(uint worker_id) = 0;
71
72 // Debugging accessor for the name.
73 const char* name() const { return _name; }
74 const uint gc_id() const { return _gc_id; }
75 BehaviourProvider& provider() const {
76 assert(_provider != NULL, "no provider set");
77 return *_provider;
78 }
79 void set_provider(BehaviourProvider& provider) { _provider = &provider; }
80 };
81
82 struct WorkData {
83 AbstractGangTask* _task;
84 uint _worker_id;
85 WorkData(AbstractGangTask* task, uint worker_id)
86 : _task(task), _worker_id(worker_id) {}
87 };
88
89 // Interface to handle the synchronization between the coordinator thread and the worker threads,
90 // when a task is dispatched out to the worker threads.
91 class GangTaskDispatcher : public CHeapObj<mtGC> {
92 public:
93 virtual ~GangTaskDispatcher() {}
94
95 // Coordinator API.
96
97 // Distributes the task out to num_workers workers.
98 // Returns when the task has been completed by all workers.
99 virtual void coordinator_execute_on_workers(AbstractGangTask* task, uint num_workers) = 0;
100
101 // Worker API.
102
103 // Waits for a task to become available to the worker.
104 // Returns when the worker has been assigned a task.
105 virtual WorkData worker_wait_for_task() = 0;
|