21
21
typedef enum { ACTION_WAIT , ACTION_RUN , ACTION_STOP } action ;
22
22
23
23
// Contains state for a single CpuAndWallTimeWorker instance
24
- struct idle_sampling_loop_state {
24
+ typedef struct {
25
25
pthread_mutex_t wakeup_mutex ;
26
26
pthread_cond_t wakeup ;
27
27
action requested_action ;
28
28
void (* run_action_function )(void );
29
- };
29
+ } idle_sampling_loop_state ;
30
30
31
31
static VALUE _native_new (VALUE klass );
32
- static void reset_state (struct idle_sampling_loop_state * state );
32
+ static void reset_state (idle_sampling_loop_state * state );
33
33
static VALUE _native_idle_sampling_loop (DDTRACE_UNUSED VALUE self , VALUE self_instance );
34
34
static VALUE _native_stop (DDTRACE_UNUSED VALUE self , VALUE self_instance );
35
35
static void * run_idle_sampling_loop (void * state_ptr );
@@ -62,7 +62,7 @@ void collectors_idle_sampling_helper_init(VALUE profiling_module) {
62
62
rb_define_singleton_method (testing_module , "_native_idle_sampling_helper_request_action" , _native_idle_sampling_helper_request_action , 1 );
63
63
}
64
64
65
- // This structure is used to define a Ruby object that stores a pointer to a struct idle_sampling_loop_state
65
+ // This structure is used to define a Ruby object that stores a pointer to a idle_sampling_loop_state
66
66
// See also https://github.com/ruby/ruby/blob/master/doc/extension.rdoc for how this works
67
67
static const rb_data_type_t idle_sampling_helper_typed_data = {
68
68
.wrap_struct_name = "Datadog::Profiling::Collectors::IdleSamplingHelper" ,
@@ -76,7 +76,7 @@ static const rb_data_type_t idle_sampling_helper_typed_data = {
76
76
};
77
77
78
78
static VALUE _native_new (VALUE klass ) {
79
- struct idle_sampling_loop_state * state = ruby_xcalloc (1 , sizeof (struct idle_sampling_loop_state ));
79
+ idle_sampling_loop_state * state = ruby_xcalloc (1 , sizeof (idle_sampling_loop_state ));
80
80
81
81
// Note: Any exceptions raised from this note until the TypedData_Wrap_Struct call will lead to the state memory
82
82
// being leaked.
@@ -90,7 +90,7 @@ static VALUE _native_new(VALUE klass) {
90
90
return TypedData_Wrap_Struct (klass , & idle_sampling_helper_typed_data , state );
91
91
}
92
92
93
- static void reset_state (struct idle_sampling_loop_state * state ) {
93
+ static void reset_state (idle_sampling_loop_state * state ) {
94
94
state -> wakeup_mutex = (pthread_mutex_t ) PTHREAD_MUTEX_INITIALIZER ;
95
95
state -> wakeup = (pthread_cond_t ) PTHREAD_COND_INITIALIZER ;
96
96
state -> requested_action = ACTION_WAIT ;
@@ -101,17 +101,17 @@ static void reset_state(struct idle_sampling_loop_state *state) {
101
101
// a pristine state before recreating the worker thread (this includes resetting the mutex in case it was left
102
102
// locked halfway through the VM forking)
103
103
static VALUE _native_reset (DDTRACE_UNUSED VALUE self , VALUE self_instance ) {
104
- struct idle_sampling_loop_state * state ;
105
- TypedData_Get_Struct (self_instance , struct idle_sampling_loop_state , & idle_sampling_helper_typed_data , state );
104
+ idle_sampling_loop_state * state ;
105
+ TypedData_Get_Struct (self_instance , idle_sampling_loop_state , & idle_sampling_helper_typed_data , state );
106
106
107
107
reset_state (state );
108
108
109
109
return Qtrue ;
110
110
}
111
111
112
112
static VALUE _native_idle_sampling_loop (DDTRACE_UNUSED VALUE self , VALUE self_instance ) {
113
- struct idle_sampling_loop_state * state ;
114
- TypedData_Get_Struct (self_instance , struct idle_sampling_loop_state , & idle_sampling_helper_typed_data , state );
113
+ idle_sampling_loop_state * state ;
114
+ TypedData_Get_Struct (self_instance , idle_sampling_loop_state , & idle_sampling_helper_typed_data , state );
115
115
116
116
// Release GVL and run the loop waiting for requests
117
117
rb_thread_call_without_gvl (run_idle_sampling_loop , state , interrupt_idle_sampling_loop , state );
@@ -120,7 +120,7 @@ static VALUE _native_idle_sampling_loop(DDTRACE_UNUSED VALUE self, VALUE self_in
120
120
}
121
121
122
122
static void * run_idle_sampling_loop (void * state_ptr ) {
123
- struct idle_sampling_loop_state * state = (struct idle_sampling_loop_state * ) state_ptr ;
123
+ idle_sampling_loop_state * state = (idle_sampling_loop_state * ) state_ptr ;
124
124
int error = 0 ;
125
125
126
126
while (true) {
@@ -164,7 +164,7 @@ static void *run_idle_sampling_loop(void *state_ptr) {
164
164
}
165
165
166
166
static void interrupt_idle_sampling_loop (void * state_ptr ) {
167
- struct idle_sampling_loop_state * state = (struct idle_sampling_loop_state * ) state_ptr ;
167
+ idle_sampling_loop_state * state = (idle_sampling_loop_state * ) state_ptr ;
168
168
int error = 0 ;
169
169
170
170
// Note about the error handling in this situation: Something bad happening at this stage is really really awkward to
@@ -189,8 +189,8 @@ static void interrupt_idle_sampling_loop(void *state_ptr) {
189
189
}
190
190
191
191
static VALUE _native_stop (DDTRACE_UNUSED VALUE self , VALUE self_instance ) {
192
- struct idle_sampling_loop_state * state ;
193
- TypedData_Get_Struct (self_instance , struct idle_sampling_loop_state , & idle_sampling_helper_typed_data , state );
192
+ idle_sampling_loop_state * state ;
193
+ TypedData_Get_Struct (self_instance , idle_sampling_loop_state , & idle_sampling_helper_typed_data , state );
194
194
195
195
ENFORCE_SUCCESS_GVL (pthread_mutex_lock (& state -> wakeup_mutex ));
196
196
state -> requested_action = ACTION_STOP ;
@@ -204,12 +204,12 @@ static VALUE _native_stop(DDTRACE_UNUSED VALUE self, VALUE self_instance) {
204
204
205
205
// Assumption: Function gets called without the global VM lock
206
206
void idle_sampling_helper_request_action (VALUE self_instance , void (* run_action_function )(void )) {
207
- struct idle_sampling_loop_state * state ;
207
+ idle_sampling_loop_state * state ;
208
208
if (!rb_typeddata_is_kind_of (self_instance , & idle_sampling_helper_typed_data )) {
209
209
grab_gvl_and_raise (rb_eTypeError , "Wrong argument for idle_sampling_helper_request_action" );
210
210
}
211
211
// This should never fail the the above check passes
212
- TypedData_Get_Struct (self_instance , struct idle_sampling_loop_state , & idle_sampling_helper_typed_data , state );
212
+ TypedData_Get_Struct (self_instance , idle_sampling_loop_state , & idle_sampling_helper_typed_data , state );
213
213
214
214
ENFORCE_SUCCESS_NO_GVL (pthread_mutex_lock (& state -> wakeup_mutex ));
215
215
if (state -> requested_action == ACTION_WAIT ) {
0 commit comments