1 /* 2 * Copyright (c) 1998, 2019, 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 * 23 */ 24 25 // no precompiled headers 26 #include "runtime/orderAccess.hpp" 27 #include "runtime/os.hpp" 28 #include "runtime/osThread.hpp" 29 30 void OSThread::pd_initialize() { 31 set_thread_handle(NULL); 32 set_thread_id(NULL); 33 set_interrupt_event(NULL); 34 } 35 36 void OSThread::pd_destroy() { 37 if (_interrupt_event != NULL) { 38 CloseHandle(_interrupt_event); 39 } 40 } 41 42 // We need to specialize these to interact with the _interrupt_event. 43 44 volatile bool OSThread::interrupted() { 45 return _interrupted != 0 && 46 (WaitForSingleObject(_interrupt_event, 0) == WAIT_OBJECT_0); 47 } 48 49 void OSThread::set_interrupted(bool z) { 50 if (z) { 51 _interrupted = 1; 52 // More than one thread can get here with the same value of osthread, 53 // resulting in multiple notifications. We do, however, want the store 54 // to interrupted() to be visible to other threads before we post 55 // the interrupt event. 56 OrderAccess::release(); 57 SetEvent(_interrupt_event); 58 } 59 else { 60 // We should only ever clear the interrupt if we are in fact interrupted, 61 // and this can only be done by the current thread on itself. 62 assert(_interrupted == 1, "invariant for clearing interrupt state"); 63 _interrupted = 0; 64 ResetEvent(_interrupt_event); 65 } 66 }