Commit 5700736a authored by Éric Thiébaut's avatar Éric Thiébaut
Browse files

Add tao_camera_broadcast and rename tao_camera_notify as tao_camera_signal

parent 374e3859
......@@ -228,7 +228,7 @@ tao_camera* tao_camera_create(
if (tao_mutex_initialize(&cam->mutex, false) != TAO_OK) {
goto error1;
}
if (tao_condition_initialize(&cam->notify, false) != TAO_OK) {
if (tao_condition_initialize(&cam->cond, false) != TAO_OK) {
goto error2;
}
cam->ops = ops;
......@@ -245,7 +245,7 @@ tao_camera* tao_camera_create(
// Branch here in case of errors.
error3:
pthread_cond_destroy(&cam->notify);
pthread_cond_destroy(&cam->cond);
error2:
pthread_mutex_destroy(&cam->mutex);
error1:
......@@ -277,10 +277,11 @@ tao_status tao_camera_destroy(
// method to make sure that these buffers are not in use somewhere.
manage_buffers(cam, 0);
// Unlock the camera and immediately destroy condition variable and
// mutex.
// Destroy condition variable.
pthread_cond_destroy(&cam->cond);
// Unlock the camera and immediately destroy its mutex.
tao_camera_unlock(cam);
pthread_cond_destroy(&cam->notify);
pthread_mutex_destroy(&cam->mutex);
// Eventually release memory storing the instance.
......@@ -336,32 +337,44 @@ void tao_camera_unlock(
}
}
void tao_camera_notify(
void tao_camera_signal(
tao_camera* cam)
{
// FIXME: broadcast?
// Manual pages say that pthread_cond_signal never returns an error code.
(void)pthread_cond_signal(&cam->notify);
int code = pthread_cond_signal(&cam->cond);
if (code != 0) {
// This is a fatal error. FIXME: Really?
fatal_error("pthread_cond_signal", code);
}
}
void tao_camera_broadcast(
tao_camera* cam)
{
int code = pthread_cond_broadcast(&cam->cond);
if (code != 0) {
// This is a fatal error. FIXME: Really?
fatal_error("pthread_cond_broadcast", code);
}
}
tao_status tao_camera_wait(
tao_camera* cam)
{
return tao_condition_wait(&cam->notify, &cam->mutex);
return tao_condition_wait(&cam->cond, &cam->mutex);
}
tao_status tao_camera_abstimed_wait(
tao_camera* cam,
const tao_time* abstime)
{
return tao_condition_abstimed_wait(&cam->notify, &cam->mutex, abstime);
return tao_condition_abstimed_wait(&cam->cond, &cam->mutex, abstime);
}
tao_status tao_camera_timed_wait(
tao_camera* cam,
double secs)
{
return tao_condition_timed_wait(&cam->notify, &cam->mutex, secs);
return tao_condition_timed_wait(&cam->cond, &cam->mutex, secs);
}
// This function may be called after an unsuccessful command to set the camera
......
......@@ -211,7 +211,7 @@ struct tao_camera_ops_ {
*/
struct tao_camera_ {
tao_mutex mutex;///< Lock to protect this structure.
tao_cond notify;///< Condition variable to signal events.
tao_cond cond;///< Condition variable to signal events.
tao_event events;///< Pending events.
const tao_camera_ops* ops;///< Table of virtual methods for the
/// camera.
......
......@@ -258,8 +258,8 @@ extern void tao_camera_info_initialize(
*
* - tao_camera_unlock() unlocks a camera instance.
*
* - tao_camera_notify() notifies other threads that something may have changed
* in the camera instance.
* - tao_camera_signal() and tao_camera_boeadcast() notify other threads that
* something may have changed in the camera instance.
*
* - tao_camera_wait(), tao_camera_abstimed_wait(), and tao_camera_timed_wait()
* wait for some changes(s) to occur in the camera instance.
......@@ -437,7 +437,7 @@ extern void tao_camera_unlock(
tao_camera* cam);
/**
* @brief Signal a change for a camera.
* @brief Signal a change for a camera to one waiting threads.
*
* This function restarts one of the threads that are waiting on the condition
* variable of the camera @b cam. Nothing happens, if no threads are waiting
......@@ -449,9 +449,29 @@ extern void tao_camera_unlock(
*
* @param cam Address of camera instance (must be non-`NULL`).
*
* @see tao_camera_wait(), tao_camera_timed_wait(), tao_camera_abstimed_wait().
* @see tao_camera_wait(), tao_camera_timed_wait(), tao_camera_abstimed_wait(),
* tao_camera_broadcast().
*/
extern void tao_camera_notify(
extern void tao_camera_signal(
tao_camera* cam);
/**
* @brief Signal a change for a camera to all waiting threads.
*
* This function restarts all the threads that are waiting on the condition
* variable of the camera @b cam. Nothing happens, if no threads are waiting
* on the condition variable of @b cam. The caller is assumed to have locked
* the camera before calling this function and to unlock the camera soon after
* calling this function to effectively trigger the notification to others.
*
* @warning The caller must own the lock on the camera.
*
* @param cam Address of camera instance (must be non-`NULL`).
*
* @see tao_camera_wait(), tao_camera_timed_wait(), tao_camera_abstimed_wait(),
* tao_camera_signal().
*/
extern void tao_camera_broadcast(
tao_camera* cam);
/**
......
......@@ -1540,7 +1540,7 @@ static tao_status recv_command(
tao_camera_lock(cam);
{
cam->events |= EVENT_COMMAND;
tao_camera_notify(cam);
tao_camera_broadcast(cam);
}
tao_camera_unlock(cam);
......
......@@ -425,7 +425,9 @@ static tao_status on_start(
assert(cam->nbufs >= 2);
phnx_device* dev = (phnx_device*)cam;
int nbufs = cam->nbufs;
const char* func = "tao_camera_start_acquisition"; // name of the caller
// Name of the caller for reporting errors.
const char* func = "tao_camera_start_acquisition";
// Check the compatibility of images and device regions of interest.
const tao_camera_config* cfg = &cam->info.config;
......@@ -708,12 +710,12 @@ static tao_status on_wait_buffer(
// other members are updated by the acquisition callback.
while (cam->pending < 1) {
if (forever) {
if (tao_condition_wait(&cam->notify, &cam->mutex) != TAO_OK) {
if (tao_condition_wait(&cam->cond, &cam->mutex) != TAO_OK) {
return TAO_ERROR;
}
} else {
tao_status status = tao_condition_abstimed_wait(
&cam->notify, &cam->mutex, &abstime);
&cam->cond, &cam->mutex, &abstime);
if (status != TAO_OK) {
if (status == TAO_TIMEOUT) {
++cam->info.timeouts;
......@@ -829,7 +831,7 @@ static void acquisition_callback(
// Get timestamp immediately (before locking because this may block for
// some time) aborting on error.
tao_time now;
if (tao_get_monotonic_time(&now) != 0) {
if (tao_get_monotonic_time(&now) != TAO_OK) {
tao_panic();
}
......@@ -899,7 +901,7 @@ static void acquisition_callback(
}
if (cam->events != 0) {
// Signal condition for waiting thread.
tao_camera_notify(cam);
tao_camera_broadcast(cam);
}
}
tao_camera_unlock(cam);
......
......@@ -243,8 +243,8 @@ extern tao_status phnx_print_camera_info(
/**
* Get "Phoenix" camera device structure.
*
* This function check whether @a cam is a "Phoenix" camera and returns
* its specific device component.
* This function check whether @a cam is a "Phoenix" camera and returns its
* specific device component.
*
* @param cam Address of unified camera structure.
*
......@@ -542,7 +542,7 @@ extern void* phnx_get_buffer(
/**
* Start a program using a camera connected to Phoenix frame grabber.
*
* This function parses command line options, open a camera connected to
* This function parses command line options, open a camera connected to a
* Phoenix frame grabber and configure it according to the command line
* options.
*
......@@ -559,7 +559,7 @@ extern void* phnx_get_buffer(
* @param descr A description of the program purpose.
* @param args Positionnal arguments (for the syntax line).
*
* @return The number of remaing arguments.
* @return The number of remaining arguments.
*/
extern int phnx_start_program(
tao_camera** cam,
......
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