2034N/A * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. 342N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 342N/A * This code is free software; you can redistribute it and/or modify it 342N/A * under the terms of the GNU General Public License version 2 only, as 342N/A * published by the Free Software Foundation. 342N/A * This code is distributed in the hope that it will be useful, but WITHOUT 342N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 342N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 342N/A * version 2 for more details (a copy is included in the LICENSE file that 342N/A * accompanied this code). 342N/A * You should have received a copy of the GNU General Public License version 342N/A * 2 along with this work; if not, write to the Free Software Foundation, 342N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 342N/A // We must NULL out the unused entries, then enqueue. 1169N/A // We have to unlock _lock (which may be Shared_DirtyCardQ_lock) before 1169N/A // we acquire DirtyCardQ_CBL_mon inside enqeue_complete_buffer as they 1169N/A // have the same rank and we may get the "possible deadlock" message 342N/A // We must relock only because the caller will unlock, for the normal 1111N/A // Allocate space for the BufferNode in front of the buffer. 342N/A // For now we'll adopt the strategy of deleting half. 1111N/A // This thread records the full buffer and allocates a new one (while 1111N/A // holding the lock if there is one). 1169N/A // The current PtrQ may be the shared dirty card queue and 1169N/A // may be being manipulated by more than one worker thread 1169N/A // during a pause. Since the enqueuing of the completed 1169N/A // buffer unlocks the Shared_DirtyCardQ_lock more than one 1169N/A // worker thread can 'race' on reading the shared queue attributes 1169N/A // (_buf and _index) and multiple threads can call into this 1169N/A // routine for the same buffer. This will cause the completed 1169N/A // buffer to be added to the CBL multiple times. 1169N/A // We "claim" the current buffer by caching value of _buf in 1169N/A // a local and clearing the field while holding _lock. When 1169N/A // _lock is released (while enqueueing the completed buffer) 1169N/A // the thread that acquires _lock will skip this code, 1169N/A // preventing the subsequent the multiple enqueue, and 1169N/A // install a newly allocated buffer below. 1169N/A // While the current thread was enqueuing the buffer another thread 1169N/A // may have a allocated a new buffer and inserted it into this pointer 1169N/A // queue. If that happens then we just return so that the current 1169N/A // thread doesn't overwrite the buffer allocated by the other thread 1169N/A // and potentially losing some dirtied cards. 1111N/A // Recycle the buffer. No allocation. 1111N/A // We don't lock. It is fine to be epsilon-precise here. 1111N/A // True here means that the buffer hasn't been deallocated and the caller may reuse it. 1111N/A // The buffer will be enqueued. The caller will have to get a new one. 342N/A "Completed buffer length is wrong.");
1111N/A// Merge lists of buffers. Notify the processing threads. 1111N/A// The source queue is emptied as a result. The queues 616N/A// must share the monitor.