24 |
24 |
25 #ifndef SHARE_SERVICES_ATTACHLISTENER_HPP |
25 #ifndef SHARE_SERVICES_ATTACHLISTENER_HPP |
26 #define SHARE_SERVICES_ATTACHLISTENER_HPP |
26 #define SHARE_SERVICES_ATTACHLISTENER_HPP |
27 |
27 |
28 #include "memory/allocation.hpp" |
28 #include "memory/allocation.hpp" |
|
29 #include "metaprogramming/isRegisteredEnum.hpp" |
|
30 #include "runtime/atomic.hpp" |
29 #include "utilities/debug.hpp" |
31 #include "utilities/debug.hpp" |
30 #include "utilities/globalDefinitions.hpp" |
32 #include "utilities/globalDefinitions.hpp" |
31 #include "utilities/macros.hpp" |
33 #include "utilities/macros.hpp" |
32 #include "utilities/ostream.hpp" |
34 #include "utilities/ostream.hpp" |
33 |
35 |
47 struct AttachOperationFunctionInfo { |
49 struct AttachOperationFunctionInfo { |
48 const char* name; |
50 const char* name; |
49 AttachOperationFunction func; |
51 AttachOperationFunction func; |
50 }; |
52 }; |
51 |
53 |
|
54 enum AttachListenerState { |
|
55 AL_NOT_INITIALIZED, |
|
56 AL_INITIALIZING, |
|
57 AL_INITIALIZED |
|
58 }; |
|
59 |
|
60 template<> struct IsRegisteredEnum<AttachListenerState> : public TrueType {}; |
|
61 |
52 class AttachListener: AllStatic { |
62 class AttachListener: AllStatic { |
53 public: |
63 public: |
54 static void vm_start() NOT_SERVICES_RETURN; |
64 static void vm_start() NOT_SERVICES_RETURN; |
55 static void init() NOT_SERVICES_RETURN; |
65 static void init() NOT_SERVICES_RETURN; |
56 static void abort() NOT_SERVICES_RETURN; |
66 static void abort() NOT_SERVICES_RETURN; |
57 |
67 |
58 // invoke to perform clean-up tasks when all clients detach |
68 // invoke to perform clean-up tasks when all clients detach |
59 static void detachall() NOT_SERVICES_RETURN; |
69 static void detachall() NOT_SERVICES_RETURN; |
|
70 |
|
71 // check unix domain socket file on filesystem |
|
72 static bool check_socket_file() NOT_SERVICES_RETURN_(false); |
60 |
73 |
61 // indicates if the Attach Listener needs to be created at startup |
74 // indicates if the Attach Listener needs to be created at startup |
62 static bool init_at_startup() NOT_SERVICES_RETURN_(false); |
75 static bool init_at_startup() NOT_SERVICES_RETURN_(false); |
63 |
76 |
64 // indicates if we have a trigger to start the Attach Listener |
77 // indicates if we have a trigger to start the Attach Listener |
65 static bool is_init_trigger() NOT_SERVICES_RETURN_(false); |
78 static bool is_init_trigger() NOT_SERVICES_RETURN_(false); |
66 |
79 |
67 #if !INCLUDE_SERVICES |
80 #if !INCLUDE_SERVICES |
68 static bool is_attach_supported() { return false; } |
81 static bool is_attach_supported() { return false; } |
69 #else |
82 #else |
|
83 |
70 private: |
84 private: |
71 static volatile bool _initialized; |
85 static volatile AttachListenerState _state; |
72 |
86 |
73 public: |
87 public: |
74 static bool is_initialized() { return _initialized; } |
88 static void set_state(AttachListenerState new_state) { |
75 static void set_initialized() { _initialized = true; } |
89 Atomic::store(new_state, &_state); |
|
90 } |
|
91 |
|
92 static AttachListenerState get_state() { |
|
93 return Atomic::load(&_state); |
|
94 } |
|
95 |
|
96 static AttachListenerState transit_state(AttachListenerState new_state, |
|
97 AttachListenerState cmp_state) { |
|
98 return Atomic::cmpxchg(new_state, &_state, cmp_state); |
|
99 } |
|
100 |
|
101 static bool is_initialized() { |
|
102 return Atomic::load(&_state) == AL_INITIALIZED; |
|
103 } |
|
104 |
|
105 static void set_initialized() { |
|
106 Atomic::store(AL_INITIALIZED, &_state); |
|
107 } |
76 |
108 |
77 // indicates if this VM supports attach-on-demand |
109 // indicates if this VM supports attach-on-demand |
78 static bool is_attach_supported() { return !DisableAttachMechanism; } |
110 static bool is_attach_supported() { return !DisableAttachMechanism; } |
79 |
111 |
80 // platform specific initialization |
112 // platform specific initialization |