1 /*
2 * Copyright (c) 2001, 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 *
52 // its buffer in the destructor (since that obtains a lock which may not
53 // be legally locked by then.
54 const bool _permanent;
55
56 protected:
57 // The buffer.
58 void** _buf;
59 // The (byte) index at which an object was last enqueued. Starts at "_sz"
60 // (indicating an empty buffer) and goes towards zero.
61 size_t _index;
62
63 // The (byte) size of the buffer.
64 size_t _sz;
65
66 // If there is a lock associated with this buffer, this is that lock.
67 Mutex* _lock;
68
69 PtrQueueSet* qset() { return _qset; }
70 bool is_permanent() const { return _permanent; }
71
72 // Process queue entries and release resources, if not permanent.
73 void flush_impl();
74
75 // Initialize this queue to contain a null buffer, and be part of the
76 // given PtrQueueSet.
77 PtrQueue(PtrQueueSet* qset, bool permanent = false, bool active = false);
78
79 // Requires queue flushed or permanent.
80 ~PtrQueue();
81
82 public:
83
84 // Associate a lock with a ptr queue.
85 void set_lock(Mutex* lock) { _lock = lock; }
86
87 void reset() { if (_buf != NULL) _index = _sz; }
88
89 void enqueue(volatile void* ptr) {
90 enqueue((void*)(ptr));
91 }
92
|
1 /*
2 * Copyright (c) 2001, 2017, 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 *
52 // its buffer in the destructor (since that obtains a lock which may not
53 // be legally locked by then.
54 const bool _permanent;
55
56 protected:
57 // The buffer.
58 void** _buf;
59 // The (byte) index at which an object was last enqueued. Starts at "_sz"
60 // (indicating an empty buffer) and goes towards zero.
61 size_t _index;
62
63 // The (byte) size of the buffer.
64 size_t _sz;
65
66 // If there is a lock associated with this buffer, this is that lock.
67 Mutex* _lock;
68
69 PtrQueueSet* qset() { return _qset; }
70 bool is_permanent() const { return _permanent; }
71
72 // Process queue entries and release resources.
73 void flush_impl();
74
75 // Initialize this queue to contain a null buffer, and be part of the
76 // given PtrQueueSet.
77 PtrQueue(PtrQueueSet* qset, bool permanent = false, bool active = false);
78
79 // Requires queue flushed or permanent.
80 ~PtrQueue();
81
82 public:
83
84 // Associate a lock with a ptr queue.
85 void set_lock(Mutex* lock) { _lock = lock; }
86
87 void reset() { if (_buf != NULL) _index = _sz; }
88
89 void enqueue(volatile void* ptr) {
90 enqueue((void*)(ptr));
91 }
92
|