Skip to content

Commit

Permalink
all: use atomic ops for cancel boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelP committed Mar 22, 2017
1 parent 81d5e52 commit 05dcc45
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/arvfakestream.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ arv_fake_stream_thread (void *data)
if (thread_data->callback != NULL)
thread_data->callback (thread_data->user_data, ARV_STREAM_CALLBACK_TYPE_INIT, NULL);

while (!thread_data->cancel) {
while (!g_atomic_int_get (&thread_data->cancel)) {
arv_fake_camera_wait_for_next_frame (thread_data->camera);
buffer = arv_stream_pop_input_buffer (thread_data->stream);
if (buffer != NULL) {
Expand Down Expand Up @@ -173,7 +173,7 @@ arv_fake_stream_finalize (GObject *object)

thread_data = fake_stream->priv->thread_data;

thread_data->cancel = TRUE;
g_atomic_int_set (&thread_data->cancel, TRUE);
g_thread_join (fake_stream->priv->thread);
g_free (thread_data);

Expand Down
8 changes: 4 additions & 4 deletions src/arvgvdevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,12 @@ arv_gv_device_heartbeat_thread (void *data)

while (!_read_register (io_data, ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_OFFSET, &value, NULL) &&
g_timer_elapsed (timer, NULL) < ARV_GV_DEVICE_HEARTBEAT_RETRY_TIMEOUT_S &&
!thread_data->cancel) {
!g_atomic_int_get (&thread_data->cancel)) {
g_usleep (ARV_GV_DEVICE_HEARTBEAT_RETRY_DELAY_US);
counter++;
}

if (!thread_data->cancel) {
if (!g_atomic_int_get (&thread_data->cancel)) {
arv_log_device ("[GvDevice::Heartbeat] Ack value = %d", value);

if (counter > 1)
Expand All @@ -483,7 +483,7 @@ arv_gv_device_heartbeat_thread (void *data)
} else
io_data->is_controller = FALSE;
}
} while (!thread_data->cancel);
} while (!g_atomic_int_get (&thread_data->cancel));

g_timer_destroy (timer);

Expand Down Expand Up @@ -1258,7 +1258,7 @@ arv_gv_device_finalize (GObject *object)

heartbeat_data = gv_device->priv->heartbeat_data;

heartbeat_data->cancel = TRUE;
g_atomic_int_set (&heartbeat_data->cancel, TRUE);
g_thread_join (gv_device->priv->heartbeat_thread);
g_free (heartbeat_data);

Expand Down
7 changes: 3 additions & 4 deletions src/arvgvfakecamera.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ _thread (void *user_data)
g_clear_object (&remote_address);
}
}
} while (!gv_fake_camera->priv->cancel && g_get_real_time () < next_timestamp_us);
} while (!g_atomic_int_get (&gv_fake_camera->priv->cancel) && g_get_real_time () < next_timestamp_us);

if (arv_fake_camera_get_control_channel_privilege (gv_fake_camera->priv->camera) == 0 ||
arv_fake_camera_get_acquisition_status (gv_fake_camera->priv->camera) == 0) {
Expand Down Expand Up @@ -398,7 +398,7 @@ _thread (void *user_data)
is_streaming = TRUE;
}

} while (!gv_fake_camera->priv->cancel);
} while (!g_atomic_int_get (&gv_fake_camera->priv->cancel));

if (stream_address != NULL)
g_object_unref (stream_address);
Expand Down Expand Up @@ -528,8 +528,7 @@ arv_gv_fake_camera_stop (ArvGvFakeCamera *gv_fake_camera)
if (gv_fake_camera->priv->thread == NULL)
return;

gv_fake_camera->priv->cancel = TRUE;

g_atomic_int_set (&gv_fake_camera->priv->cancel, TRUE);
g_thread_join (gv_fake_camera->priv->thread);
gv_fake_camera->priv->thread = NULL;

Expand Down
6 changes: 3 additions & 3 deletions src/arvgvstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ _loop (ArvGvStreamThreadData *thread_data)
frame = NULL;

_check_frame_completion (thread_data, time_us, frame);
} while (!thread_data->cancel);
} while (!g_atomic_int_get (&thread_data->cancel));

g_free (packet);

Expand Down Expand Up @@ -905,7 +905,7 @@ _ring_buffer_loop (ArvGvStreamThreadData *thread_data)
descriptor->h1.block_status = TP_STATUS_KERNEL;
block_id = (block_id + 1) % req.tp_block_nr;
}
} while (!thread_data->cancel);
} while (!g_atomic_int_get (&thread_data->cancel));

bind_error:
munmap (buffer, req.tp_block_size * req.tp_block_nr);
Expand Down Expand Up @@ -1192,7 +1192,7 @@ arv_gv_stream_finalize (GObject *object)

thread_data = gv_stream->priv->thread_data;

thread_data->cancel = TRUE;
g_atomic_int_set (&thread_data->cancel, TRUE);
g_thread_join (gv_stream->priv->thread);

statistic_string = arv_statistic_to_string (thread_data->statistic);
Expand Down
4 changes: 2 additions & 2 deletions src/arvuvstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ arv_uv_stream_thread (void *data)

offset = 0;

while (!thread_data->cancel) {
while (!g_atomic_int_get (&thread_data->cancel)) {
size_t size;
transferred = 0;

Expand Down Expand Up @@ -319,7 +319,7 @@ arv_uv_stream_finalize (GObject *object)

thread_data = uv_stream->priv->thread_data;

thread_data->cancel = TRUE;
g_atomic_int_set (&thread_data->cancel, TRUE);
g_thread_join (uv_stream->priv->thread);

si_control = 0x0;
Expand Down

0 comments on commit 05dcc45

Please sign in to comment.