--- old/src/hotspot/os/windows/osThread_windows.cpp 2019-09-13 03:22:15.451827907 -0400 +++ new/src/hotspot/os/windows/osThread_windows.cpp 2019-09-13 03:22:14.288815965 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -23,12 +23,9 @@ */ // no precompiled headers -#include "runtime/handles.inline.hpp" -#include "runtime/mutexLocker.hpp" +#include "runtime/orderAccess.hpp" #include "runtime/os.hpp" #include "runtime/osThread.hpp" -#include "runtime/safepoint.hpp" -#include "runtime/vmThread.hpp" void OSThread::pd_initialize() { set_thread_handle(NULL); @@ -36,8 +33,34 @@ set_interrupt_event(NULL); } -// TODO: this is not well encapsulated; creation and deletion of the -// interrupt_event are done in os_win32.cpp, create_thread and -// free_thread. Should follow pattern of Linux/Solaris code here. 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); + } }