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 }
|
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 this to interact with the _interrupt_event.
43
44 void OSThread::set_interrupted(bool z) {
45 if (z) {
46 SetEvent(_interrupt_event);
47 }
48 else {
49 // We should only ever clear the interrupt if we are in fact interrupted,
50 // and this can only be done by the current thread on itself.
51 ResetEvent(_interrupt_event);
52 }
53 }
|