1 /*
2 * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
42 // YieldingFlexibleWorkGang (defined in another file)
43 //
44 // Worker class hierarchy:
45 // AbstractGangWorker (subclass of WorkerThread)
46 // GangWorker
47 // YieldingFlexibleGangWorker (defined in another file)
48
49 // Forward declarations of classes defined here
50
51 class AbstractGangWorker;
52 class Semaphore;
53 class WorkGang;
54
55 // An abstract task to be worked on by a gang.
56 // You subclass this to supply your own work() method
57 class AbstractGangTask VALUE_OBJ_CLASS_SPEC {
58 const char* _name;
59 const uint _gc_id;
60
61 public:
62 AbstractGangTask(const char* name) :
63 _name(name),
64 _gc_id(GCId::current_raw())
65 {}
66
67 AbstractGangTask(const char* name, const uint gc_id) :
68 _name(name),
69 _gc_id(gc_id)
70 {}
71
72 // The abstract work method.
73 // The argument tells you which member of the gang you are.
74 virtual void work(uint worker_id) = 0;
75
76 // Debugging accessor for the name.
77 const char* name() const { return _name; }
78 const uint gc_id() const { return _gc_id; }
79 };
80
81 struct WorkData {
82 AbstractGangTask* _task;
83 uint _worker_id;
84 WorkData(AbstractGangTask* task, uint worker_id) : _task(task), _worker_id(worker_id) {}
85 };
86
87 // Interface to handle the synchronization between the coordinator thread and the worker threads,
88 // when a task is dispatched out to the worker threads.
89 class GangTaskDispatcher : public CHeapObj<mtGC> {
|
1 /*
2 * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
42 // YieldingFlexibleWorkGang (defined in another file)
43 //
44 // Worker class hierarchy:
45 // AbstractGangWorker (subclass of WorkerThread)
46 // GangWorker
47 // YieldingFlexibleGangWorker (defined in another file)
48
49 // Forward declarations of classes defined here
50
51 class AbstractGangWorker;
52 class Semaphore;
53 class WorkGang;
54
55 // An abstract task to be worked on by a gang.
56 // You subclass this to supply your own work() method
57 class AbstractGangTask VALUE_OBJ_CLASS_SPEC {
58 const char* _name;
59 const uint _gc_id;
60
61 public:
62 explicit AbstractGangTask(const char* name) :
63 _name(name),
64 _gc_id(GCId::current_or_undefined())
65 {}
66
67 // The abstract work method.
68 // The argument tells you which member of the gang you are.
69 virtual void work(uint worker_id) = 0;
70
71 // Debugging accessor for the name.
72 const char* name() const { return _name; }
73 const uint gc_id() const { return _gc_id; }
74 };
75
76 struct WorkData {
77 AbstractGangTask* _task;
78 uint _worker_id;
79 WorkData(AbstractGangTask* task, uint worker_id) : _task(task), _worker_id(worker_id) {}
80 };
81
82 // Interface to handle the synchronization between the coordinator thread and the worker threads,
83 // when a task is dispatched out to the worker threads.
84 class GangTaskDispatcher : public CHeapObj<mtGC> {
|