Commit 374e3859 authored by Éric Thiébaut's avatar Éric Thiébaut
Browse files

Correctly lock/unlock camera and fix doc

parent 509ab072
......@@ -23,7 +23,6 @@ static double elapsed_seconds(
tao_time dt;
return tao_time_to_seconds(tao_subtract_times(&dt, t1, t0));
}
int main(
int argc,
char* argv[])
......@@ -62,8 +61,11 @@ int main(
andor_print_supported_encodings(stdout, andor_get_device(cam));
// Measure time taken for updating all the configuration and compare to
// time taken to just retrieve the configuration.
// time taken to just retrieve the configuration. Locking the camera may
// be unecessary at this stage (there is only one thread aware of the
// camera) but is good practice.
tao_get_monotonic_time(&t0);
tao_camera_lock(cam);
tao_camera_update_configuration(cam);
tao_camera_get_configuration(cam, &cfg);
tao_get_monotonic_time(&t1);
......@@ -107,11 +109,13 @@ int main(
tao_report_error();
return EXIT_FAILURE;
}
tao_camera_unlock(cam);
tao_get_monotonic_time(&t1);
fprintf(stdout, "Time to start acquisition: %.3f ms\n",
1E3*elapsed_seconds(&t1, &t0));
// Acquire some images.
tao_camera_lock(cam);
int j = 0;
for (int k = 0; k < 100; ++k) {
const tao_acquisition_buffer* buf;
......@@ -122,6 +126,9 @@ int main(
fprintf(stdout, "%3d: %10.3f ms\n", k+1,
1E3*elapsed_seconds(&t1, &t0));
if (j < nimgs) {
// Convert pixel values. This takes some time, so we unlock
// the camera during this operation.
tao_camera_unlock(cam);
andor_convert_buffer(imgptr + j*imgsiz,
ANDOR_ENCODING_MONO16,
buf->data,
......@@ -129,6 +136,7 @@ int main(
cfg.roi.width,
cfg.roi.height,
buf->stride);
tao_camera_lock(cam);
++j;
}
if (tao_camera_release_acquisition_buffer(cam) != TAO_OK) {
......@@ -149,6 +157,7 @@ int main(
tao_report_error();
return EXIT_FAILURE;
}
tao_camera_unlock(cam);
tao_save_array_to_fits_file(arr, "/tmp/test-andor5.fits", true);
tao_unreference_array(arr);
......
......@@ -257,6 +257,9 @@ tao_status tao_camera_destroy(
tao_camera* cam)
{
if (cam != NULL) {
// Lock the camera.
tao_camera_lock(cam);
// Stop acquisition if acquiring (ignoring errors).
if (cam->runlevel == 2) {
cam->info.state = TAO_STATE_STOPPING;
......@@ -274,7 +277,9 @@ tao_status tao_camera_destroy(
// method to make sure that these buffers are not in use somewhere.
manage_buffers(cam, 0);
// Destroy condition variable and mutex.
// Unlock the camera and immediately destroy condition variable and
// mutex.
tao_camera_unlock(cam);
pthread_cond_destroy(&cam->notify);
pthread_mutex_destroy(&cam->mutex);
......@@ -334,6 +339,7 @@ void tao_camera_unlock(
void tao_camera_notify(
tao_camera* cam)
{
// FIXME: broadcast?
// Manual pages say that pthread_cond_signal never returns an error code.
(void)pthread_cond_signal(&cam->notify);
}
......@@ -544,7 +550,7 @@ tao_status tao_camera_release_acquisition_buffer(
return cam->ops->release_buffer(cam);
}
long tao_number_of_pending_acquisition_buffers(
long tao_camera_get_pending_acquisition_buffers(
const tao_camera* cam)
{
return (cam != NULL && cam->runlevel == 2 ? cam->pending : 0);
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment