Commit 2bef73d0 authored by Éric Thiébaut's avatar Éric Thiébaut
Browse files

Normalize API names for r/w locks and semaphores

parent 8a8dc1d4
......@@ -375,7 +375,7 @@ tao_status tao_condition_timed_wait(
//-----------------------------------------------------------------------------
// R/W LOCKS
tao_status tao_initialize_rwlock(
tao_status tao_rwlock_initialize(
tao_rwlock* lock,
bool shared)
{
......@@ -412,37 +412,37 @@ tao_status tao_initialize_rwlock(
return TAO_OK;
}
tao_status tao_destroy_rwlock(
tao_status tao_rwlock_destroy(
tao_rwlock* lock)
{
CALL_PTHREAD_FUNC(pthread_rwlock_destroy, lock);
}
tao_status tao_rdlock_rwlock(
tao_status tao_rwlock_rdlock(
tao_rwlock* lock)
{
CALL_PTHREAD_FUNC(pthread_rwlock_rdlock, lock);
}
tao_status tao_wrlock_rwlock(
tao_status tao_rwlock_wrlock(
tao_rwlock* lock)
{
CALL_PTHREAD_FUNC(pthread_rwlock_wrlock, lock);
}
tao_status tao_try_rdlock_rwlock(
tao_status tao_rwlock_try_rdlock(
tao_rwlock* lock)
{
CALL_PTHREAD_TIMED_FUNC(EBUSY, pthread_rwlock_tryrdlock, lock);
}
tao_status tao_try_wrlock_rwlock(
tao_status tao_rwlock_try_wrlock(
tao_rwlock* lock)
{
CALL_PTHREAD_TIMED_FUNC(EBUSY, pthread_rwlock_trywrlock, lock);
}
tao_status tao_abstimed_rdlock_rwlock(
tao_status tao_rwlock_abstimed_rdlock(
tao_rwlock* lock,
const tao_time* abstime)
{
......@@ -453,7 +453,7 @@ tao_status tao_abstimed_rdlock_rwlock(
CALL_PTHREAD_TIMED_FUNC(ETIMEDOUT, pthread_rwlock_timedrdlock, lock, &ts);
}
tao_status tao_abstimed_wrlock_rwlock(
tao_status tao_rwlock_abstimed_wrlock(
tao_rwlock* lock,
const tao_time* abstime)
{
......@@ -470,7 +470,7 @@ tao_status tao_unlock_rwlock(
CALL_PTHREAD_FUNC(pthread_rwlock_unlock, lock);
}
tao_status tao_timed_rdlock_rwlock(
tao_status tao_rwlock_timed_rdlock(
tao_rwlock* lock,
double secs)
{
......@@ -480,20 +480,20 @@ tao_status tao_timed_rdlock_rwlock(
return TAO_TIMEOUT;
case TAO_TIMEOUT_NOW:
return tao_try_rdlock_rwlock(lock);
return tao_rwlock_try_rdlock(lock);
case TAO_TIMEOUT_FUTURE:
return tao_abstimed_rdlock_rwlock(lock, &abstime);
return tao_rwlock_abstimed_rdlock(lock, &abstime);
case TAO_TIMEOUT_NEVER:
return tao_rdlock_rwlock(lock);
return tao_rwlock_rdlock(lock);
default:
return TAO_ERROR;
}
}
tao_status tao_timed_wrlock_rwlock(
tao_status tao_rwlock_timed_wrlock(
tao_rwlock* lock,
double secs)
{
......@@ -503,13 +503,13 @@ tao_status tao_timed_wrlock_rwlock(
return TAO_TIMEOUT;
case TAO_TIMEOUT_NOW:
return tao_try_wrlock_rwlock(lock);
return tao_rwlock_try_wrlock(lock);
case TAO_TIMEOUT_FUTURE:
return tao_abstimed_wrlock_rwlock(lock, &abstime);
return tao_rwlock_abstimed_wrlock(lock, &abstime);
case TAO_TIMEOUT_NEVER:
return tao_wrlock_rwlock(lock);
return tao_rwlock_wrlock(lock);
default:
return TAO_ERROR;
......
......@@ -17,7 +17,7 @@
#include <fcntl.h>
#include <sys/stat.h>
tao_status tao_initialize_semaphore(
tao_status tao_semaphore_initialize(
sem_t* sem,
bool shared,
unsigned int value)
......@@ -29,7 +29,7 @@ tao_status tao_initialize_semaphore(
return TAO_OK;
}
tao_status tao_destroy_semaphore(
tao_status tao_semaphore_destroy(
sem_t* sem)
{
if (sem_destroy(sem) != 0) {
......@@ -39,7 +39,7 @@ tao_status tao_destroy_semaphore(
return TAO_OK;
}
tao_status tao_get_semaphore_value(
tao_status tao_semaphore_get_value(
sem_t* sem,
int* val)
{
......@@ -50,7 +50,7 @@ tao_status tao_get_semaphore_value(
return TAO_OK;
}
tao_status tao_post_semaphore(
tao_status tao_semaphore_post(
sem_t* sem)
{
if (sem_post(sem) != 0) {
......@@ -60,7 +60,7 @@ tao_status tao_post_semaphore(
return TAO_OK;
}
tao_status tao_wait_semaphore(
tao_status tao_semaphore_wait(
sem_t* sem)
{
if (sem_wait(sem) != 0) {
......@@ -70,7 +70,7 @@ tao_status tao_wait_semaphore(
return TAO_OK;
}
tao_status tao_try_wait_semaphore(
tao_status tao_semaphore_try_wait(
sem_t* sem)
{
if (sem_trywait(sem) != 0) {
......@@ -85,7 +85,7 @@ tao_status tao_try_wait_semaphore(
return TAO_OK;
}
tao_status tao_abstimed_wait_semaphore(
tao_status tao_semaphore_abstimed_wait(
sem_t* sem,
const tao_time* abstime)
{
......@@ -105,7 +105,7 @@ tao_status tao_abstimed_wait_semaphore(
return TAO_OK;
}
tao_status tao_timed_wait_semaphore(
tao_status tao_semaphore_timed_wait(
sem_t* sem,
double secs)
{
......@@ -115,20 +115,20 @@ tao_status tao_timed_wait_semaphore(
return TAO_TIMEOUT;
case TAO_TIMEOUT_NOW:
return tao_try_wait_semaphore(sem);
return tao_semaphore_try_wait(sem);
case TAO_TIMEOUT_FUTURE:
return tao_abstimed_wait_semaphore(sem, &abstime);
return tao_semaphore_abstimed_wait(sem, &abstime);
case TAO_TIMEOUT_NEVER:
return tao_wait_semaphore(sem);
return tao_semaphore_wait(sem);
default:
return TAO_ERROR;
}
}
sem_t* tao_create_semaphore(
sem_t* tao_semaphore_create(
const char* name,
int perms,
unsigned int value)
......@@ -142,7 +142,7 @@ sem_t* tao_create_semaphore(
return sem;
}
sem_t* tao_open_semaphore(
sem_t* tao_semaphore_open(
const char* name)
{
sem_t* sem = sem_open(name, 0);
......@@ -152,7 +152,7 @@ sem_t* tao_open_semaphore(
return sem;
}
tao_status tao_close_semaphore(
tao_status tao_semaphore_close(
sem_t* sem)
{
if (sem_close(sem) != 0) {
......@@ -162,7 +162,7 @@ tao_status tao_close_semaphore(
return TAO_OK;
}
tao_status tao_unlink_semaphore(
tao_status tao_semaphore_unlink(
const char* name,
bool force)
{
......
......@@ -70,6 +70,7 @@ typedef pthread_mutex_t tao_mutex;
* tao_mutex_destroy() must be called when the mutex is no longer needed.
*
* @param mutex Pointer to the mutex to initialize.
*
* @param shared If true, require that the mutex be accessible between
* processes; otherwise, the mutex will be *private* (that is,
* only accessible by threads in the same process as the caller).
......@@ -380,7 +381,7 @@ typedef pthread_rwlock_t tao_rwlock;
* Initialize a read/write lock.
*
* This function initializes a non-static read/write lock. The caller is
* responsible of calling tao_destroy_rwlock() to free the resources that may
* responsible of calling tao_rwlock_destroy() to free the resources that may
* be associated with the read/write lock.
*
* @param lock Pointer to the read/write lock to initialize.
......@@ -391,7 +392,7 @@ typedef pthread_rwlock_t tao_rwlock;
*
* @return @ref TAO_OK if successful; @ref TAO_ERROR in case of failure.
*/
extern tao_status tao_initialize_rwlock(
extern tao_status tao_rwlock_initialize(
tao_rwlock* lock,
bool shared);
......@@ -399,13 +400,13 @@ extern tao_status tao_initialize_rwlock(
* Destroy a read/write lock.
*
* This function destroys a read/write lock that has been initialized by
* tao_initialize_rwlock().
* tao_rwlock_initialize().
*
* @param lock Pointer to the read/write lock to destroy.
*
* @return @ref TAO_OK if successful; @ref TAO_ERROR in case of failure.
*/
extern tao_status tao_destroy_rwlock(
extern tao_status tao_rwlock_destroy(
tao_rwlock* lock);
/**
......@@ -419,7 +420,7 @@ extern tao_status tao_destroy_rwlock(
*
* @return @ref TAO_OK if successful; @ref TAO_ERROR in case of failure.
*/
extern tao_status tao_rdlock_rwlock(
extern tao_status tao_rwlock_rdlock(
tao_rwlock* lock);
/**
......@@ -433,7 +434,7 @@ extern tao_status tao_rdlock_rwlock(
*
* @return @ref TAO_OK if successful; @ref TAO_ERROR in case of failure.
*/
extern tao_status tao_wrlock_rwlock(
extern tao_status tao_rwlock_wrlock(
tao_rwlock* lock);
/**
......@@ -449,7 +450,7 @@ extern tao_status tao_wrlock_rwlock(
* @return @ref TAO_OK if successful; @ref TAO_TIMEOUT if the lock cannot
* be acquired immediately; @ref TAO_ERROR in case of failure.
*/
extern tao_status tao_try_rdlock_rwlock(
extern tao_status tao_rwlock_try_rdlock(
tao_rwlock* lock);
/**
......@@ -465,7 +466,7 @@ extern tao_status tao_try_rdlock_rwlock(
* @return @ref TAO_OK if successful; @ref TAO_TIMEOUT if the lock cannot
* be acquired immediately; @ref TAO_ERROR in case of failure.
*/
extern tao_status tao_try_wrlock_rwlock(
extern tao_status tao_rwlock_try_wrlock(
tao_rwlock* lock);
/**
......@@ -479,7 +480,7 @@ extern tao_status tao_try_wrlock_rwlock(
* be acquirred before the time limit; @ref TAO_ERROR in case of
* error.
*/
extern tao_status tao_abstimed_rdlock_rwlock(
extern tao_status tao_rwlock_abstimed_rdlock(
tao_rwlock* lock,
const tao_time* abstime);
......@@ -494,7 +495,7 @@ extern tao_status tao_abstimed_rdlock_rwlock(
* be acquired before the time limit; @ref TAO_ERROR in case of
* error.
*/
extern tao_status tao_abstimed_wrlock_rwlock(
extern tao_status tao_rwlock_abstimed_wrlock(
tao_rwlock* lock,
const tao_time* abstime);
......@@ -506,15 +507,15 @@ extern tao_status tao_abstimed_wrlock_rwlock(
*
* @param secs Maximum duration to wait (in seconds). If this amount is
* very large, e.g. more than @ref TAO_MAX_TIME_SECONDS, the
* effect is the same as calling tao_rdlock_rwlock(). If this
* effect is the same as calling tao_rwlock_rdlock(). If this
* amount is very short, the effect is the same as calling
* tao_try_rdlock_rwlock().
* tao_rwlock_try_rdlock().
*
* @return @ref TAO_OK if successful; @ref TAO_TIMEOUT if the lock cannot
* be acquired before the time limit; @ref TAO_ERROR in case of
* error.
*/
extern tao_status tao_timed_rdlock_rwlock(
extern tao_status tao_rwlock_timed_rdlock(
tao_rwlock* lock,
double secs);
......@@ -526,15 +527,15 @@ extern tao_status tao_timed_rdlock_rwlock(
*
* @param secs Maximum duration to wait (in seconds). If this amount is
* very large, e.g. more than @ref TAO_MAX_TIME_SECONDS, the
* effect is the same as calling tao_wrlock_rwlock(). If this
* effect is the same as calling tao_rwlock_wrlock(). If this
* amount is very short, the effect is the same as calling
* tao_try_wrlock_rwlock().
* tao_rwlock_try_wrlock().
*
* @return @ref TAO_OK if successful; @ref TAO_TIMEOUT if the lock cannot
* be acquired before the time limit; @ref TAO_ERROR in case of
* error.
*/
extern tao_status tao_timed_wrlock_rwlock(
extern tao_status tao_rwlock_timed_wrlock(
tao_rwlock* lock,
double secs);
......@@ -575,17 +576,19 @@ extern tao_status tao_unlock_rwlock(
*
* This function must be called to initialize an anonymous semaphore (stored in
* shared memory). The caller is responsible of eventually calling
* tao_destroy_semaphore() when the semaphore is no longer needed.
* tao_semaphore_destroy() when the semaphore is no longer needed.
*
* @param sem Address of an anonymous semaphore to initialize.
*
* @param shared Boolean indicating whether the semaphore is to be shared
* between processes. Otherwise, the semaphore can only be used
* by threads belonging to the same process as the caller.
*
* @param value Initial value of the anonymous semaphore.
*
* @return @ref TAO_OK on success, @ref TAO_ERROR in case of failure.
*/
extern tao_status tao_initialize_semaphore(
extern tao_status tao_semaphore_initialize(
sem_t* sem,
bool shared,
unsigned int value);
......@@ -594,13 +597,13 @@ extern tao_status tao_initialize_semaphore(
* Destroy an anonymous semaphore.
*
* This function must be called to release the resources associated with an
* anonymous semaphore initialized by tao_initialize_semaphore().
* anonymous semaphore initialized by tao_semaphore_initialize().
*
* @param sem Address of anonymous semaphore to destroy.
*
* @return @ref TAO_OK on success, @ref TAO_ERROR in case of failure.
*/
extern tao_status tao_destroy_semaphore(
extern tao_status tao_semaphore_destroy(
sem_t* sem);
/**
......@@ -608,17 +611,19 @@ extern tao_status tao_destroy_semaphore(
*
* This function is called by the owner of a named semaphore to create it. A
* named semaphore with the same name must not already exists. Call
* tao_open_semaphore() to open an existing named semaphore. Call
* tao_close_semaphore() to close the access to the named semaphore for the
* caller. Call tao_unlink_semaphore() to remove the named semaphore.
* tao_semaphore_open() to open an existing named semaphore. Call
* tao_semaphore_close() to close the access to the named semaphore for the
* caller. Call tao_semaphore_unlink() to remove the named semaphore.
*
* @param name The name of the named semaphore.
*
* @param perms Access permissions.
*
* @param value Initial value of the named semaphore.
*
* @return The address of a new named semaphore; `NULL` in case of failure.
*/
extern sem_t* tao_create_semaphore(
extern sem_t* tao_semaphore_create(
const char* name,
int perms,
unsigned int value);
......@@ -627,13 +632,13 @@ extern sem_t* tao_create_semaphore(
* Open an existing named semaphore.
*
* This function is open an existing named semaphore. The caller must call
* tao_close_semaphore() to close the access to the named semaphore.
* tao_semaphore_close() to close the access to the named semaphore.
*
* @param name The name of the named semaphore.
*
* @return The address of a new named semaphore; `NULL` in case of failure.
*/
extern sem_t* tao_open_semaphore(
extern sem_t* tao_semaphore_open(
const char* name);
/**
......@@ -643,18 +648,19 @@ extern sem_t* tao_open_semaphore(
*
* @return @ref TAO_OK on success, @ref TAO_ERROR in case of failure.
*/
extern tao_status tao_close_semaphore(
extern tao_status tao_semaphore_close(
sem_t* sem);
/**
* Remove a named semaphore.
*
* @param name Name of named semaphore to remove.
*
* @param force Indicate whether the named semaphore may not exist.
*
* @return @ref TAO_OK on success, @ref TAO_ERROR in case of failure.
*/
extern tao_status tao_unlink_semaphore(
extern tao_status tao_semaphore_unlink(
const char* name,
bool force);
......@@ -662,11 +668,12 @@ extern tao_status tao_unlink_semaphore(
* Get the current value of a semaphore.
*
* @param sem Address of semaphore.
*
* @param val Address of variable to store the semaphore value.
*
* @return @ref TAO_OK on success, @ref TAO_ERROR in case of failure.
*/
extern tao_status tao_get_semaphore_value(
extern tao_status tao_semaphore_get_value(
sem_t* sem,
int* val);
......@@ -681,7 +688,7 @@ extern tao_status tao_get_semaphore_value(
*
* @return @ref TAO_OK on success, @ref TAO_ERROR in case of failure.
*/
extern tao_status tao_post_semaphore(
extern tao_status tao_semaphore_post(
sem_t* sem);
/**
......@@ -694,13 +701,13 @@ extern tao_status tao_post_semaphore(
*
* @return @ref TAO_OK on success, @ref TAO_ERROR in case of failure.
*/
extern tao_status tao_wait_semaphore(
extern tao_status tao_semaphore_wait(
sem_t* sem);
/**
* Attempt to decrement the value of a semaphore immediately.
*
* This function is similar to tao_wait_semaphore() but it returns immediately
* This function is similar to tao_semaphore_wait() but it returns immediately
* and reports whether the value of the semaphore was decremented.
*
* @param sem Address of semaphore.
......@@ -709,44 +716,46 @@ extern tao_status tao_wait_semaphore(
* decremented; @ref TAO_TIMEOUT if the value of a semaphore was zero;
* @ref TAO_ERROR in case of another failure.
*/
extern tao_status tao_try_wait_semaphore(
extern tao_status tao_semaphore_try_wait(
sem_t* sem);
/**
* Attempt to decrement the value of a semaphore with a time limit.
*
* This function is similar to tao_wait_semaphore() but it waits no longer than
* This function is similar to tao_semaphore_wait() but it waits no longer than
* a given absolute time limit.
*
* @param sem Address of semaphore.
*
* @param abstime Absolute time limit for waiting.
*
* @return @ref TAO_OK if the was successfully decremented before the specified
* number of seconds; @ref TAO_TIMEOUT if timeout occured before; @ref
* TAO_ERROR in case of another failure.
*/
extern tao_status tao_abstimed_wait_semaphore(
extern tao_status tao_semaphore_abstimed_wait(
sem_t* sem,
const tao_time* abstime);
/**
* Attempt to decrement the value of a semaphore with a time limit.
*
* This function is similar to tao_wait_semaphore() but it waits no longer than
* This function is similar to tao_semaphore_wait() but it waits no longer than
* a given number of seconds from now.
*
* @param sem Address of semaphore.
*
* @param secs Maximum time to wait (in seconds). If this amount of time is
* very large, e.g. more than @ref TAO_MAX_TIME_SECONDS, the
* effect is the same as calling tao_wait_semaphore(). If this
* effect is the same as calling tao_semaphore_wait(). If this
* amount of time is very small, the effect is the same as
* calling tao_try_wait_semaphore().
* calling tao_semaphore_try_wait().
*
* @return @ref TAO_OK if the was successfully decremented before the specified
* number of seconds; @ref TAO_TIMEOUT if timeout occured before; @ref
* TAO_ERROR in case of another failure.
*/
extern tao_status tao_timed_wait_semaphore(
extern tao_status tao_semaphore_timed_wait(
sem_t* sem,
double secs);
......
......@@ -97,9 +97,9 @@ static void notify_readers(shared_data* data)
{
for (int i = 0; i < NREADERS; ++i) {
int val;
tao_get_semaphore_value(&data->sem[i], &val);
tao_semaphore_get_value(&data->sem[i], &val);
if (val == 0) {
tao_post_semaphore(&data->sem[i]);
tao_semaphore_post(&data->sem[i]);
}
}
}
......@@ -200,7 +200,7 @@ static void run_reader(int shmid, int semidx)
unlock_resources(data);
// Wait for a new frame and get its index.
tao_wait_semaphore(&data->sem[semidx]);
tao_semaphore_wait(&data->sem[semidx]);
lock_resources_for_reading(data);
if (data->quitting) {
goto quit;
......@@ -301,7 +301,7 @@ int main(int argc, char* argv[])
data->frame[index].number = 0;
}
for (int i = 0; i < NREADERS; ++i) {
tao_initialize_semaphore(&data->sem[i], true, 0);
tao_semaphore_initialize(&data->sem[i], true, 0);
}
data->fps = fps;
data->last_number = 0;
......
......@@ -96,7 +96,7 @@ static inline void initialize_rwlock(
tao_rwlock* rwlock,
bool shared)
{
if (tao_initialize_rwlock(rwlock, shared) != TAO_OK) {
if (tao_rwlock_initialize(rwlock, shared) != TAO_OK) {
tao_panic();
}
}
......@@ -104,7 +104,7 @@ static inline void initialize_rwlock(
static inline void lock_rwlock_for_reading(
tao_rwlock* rwlock)
{
if (tao_rdlock_rwlock(rwlock) != TAO_OK) {
if (tao_rwlock_rdlock(rwlock) != TAO_OK) {
tao_panic();
}
}
......@@ -113,7 +113,7 @@ static inline void lock_rwlock_for_reading(
static inline void lock_rwlock_for_writing(
tao_rwlock* rwlock)
{
if (tao_wrlock_rwlock(rwlock) != TAO_OK) {
if (tao_rwlock_wrlock(rwlock) != TAO_OK) {
tao_panic();
}
}
......@@ -202,7 +202,7 @@ static void run_writer(
long i0 = number - offset;
for (long k = 0; k < data->buffers; ++k) {
long i = (i0 + k)%(long)data->buffers;
tao_status status = tao_try_wrlock_rwlock(&data->frame[i].lock);
tao_status status = tao_rwlock_try_wrlock(&data->frame[i].lock);
if (status == TAO_OK) {
// Lock for writing was successful.
index = i;
......@@ -444,13 +444,13 @@ int main(
// Exercise all r/w locks.
for (long index = 0; index < buffers; ++index) {
status = tao_try_rdlock_rwlock(&data->frame[index].lock);
status = tao_rwlock_try_rdlock(&data->frame[index].lock);
if (status != TAO_OK) {
fprintf(stderr, "Unable to lock frame %ld for reading\n", index);
} else {
unlock_rwlock(&data->frame[index].lock);
}
status = tao_try_wrlock_rwlock(&data->frame[index].lock);
status = tao_rwlock_try_wrlock(&data->frame[index].lock);
if (status != TAO_OK) {
fprintf(stderr, "Unable to lock frame %ld for writing\n", index);
} else {
......@@ -460,7 +460,7 @@ int main(
// Pre-lock the first frame. So that readers automatically wait for the
// writer to be ready.
status = tao_try_wrlock_rwlock(&data->frame[0].lock);
status = tao_rwlock_try_wrlock(&data->frame[0].lock);
if (status != TAO_OK) {
fprintf(stderr, "Unable to lock frame %ld for writing\n", (long)0);
return EXIT_FAILURE;
......
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