8230424: Use platform independent code for Thread.interrupt support
8231094: os::sleep in assert message should be changed to JavaThread::sleep
Reviewed-by: rehn, dcubed
/*
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
// no precompiled headers
#include "runtime/orderAccess.hpp"
#include "runtime/os.hpp"
#include "runtime/osThread.hpp"
void OSThread::pd_initialize() {
set_thread_handle(NULL);
set_thread_id(NULL);
set_interrupt_event(NULL);
}
void OSThread::pd_destroy() {
if (_interrupt_event != NULL) {
CloseHandle(_interrupt_event);
}
}
// We need to specialize these to interact with the _interrupt_event.
volatile bool OSThread::interrupted() {
return _interrupted != 0 &&
(WaitForSingleObject(_interrupt_event, 0) == WAIT_OBJECT_0);
}
void OSThread::set_interrupted(bool z) {
if (z) {
_interrupted = 1;
// More than one thread can get here with the same value of osthread,
// resulting in multiple notifications. We do, however, want the store
// to interrupted() to be visible to other threads before we post
// the interrupt event.
OrderAccess::release();
SetEvent(_interrupt_event);
}
else {
// We should only ever clear the interrupt if we are in fact interrupted,
// and this can only be done by the current thread on itself.
assert(_interrupted == 1, "invariant for clearing interrupt state");
_interrupted = 0;
ResetEvent(_interrupt_event);
}
}