Commit acc1a9fd authored by Andreas Schmidt's avatar Andreas Schmidt

Application constraints are lock-free.

parent 17d15612
Pipeline #2668 failed with stages
in 20 seconds
......@@ -8,8 +8,6 @@ PrrtApplicationConstraints *PrrtApplicationConstraints_create(prrtTimedelta_t ta
PrrtApplicationConstraints *constraints = calloc(1, sizeof(PrrtApplicationConstraints));
check_mem(constraints);
pthread_mutex_init(&constraints->lock, NULL);
constraints->targetDelay_us = target_delay_us;
constraints->queue_size = 1000;
......@@ -22,30 +20,21 @@ PrrtApplicationConstraints *PrrtApplicationConstraints_create(prrtTimedelta_t ta
bool PrrtApplicationConstraints_destroy(PrrtApplicationConstraints *applicationConstraints)
{
pthread_mutex_destroy(&applicationConstraints->lock);
free(applicationConstraints);
return true;
}
prrtTimedelta_t PrrtApplicationConstraints_get_target_delay(PrrtApplicationConstraints *applicationConstraints)
{
pthread_mutex_lock(&applicationConstraints->lock);
prrtTimedelta_t targetDelay = applicationConstraints->targetDelay_us;
pthread_mutex_unlock(&applicationConstraints->lock);
return targetDelay;
return applicationConstraints->targetDelay_us;
}
uint32_t PrrtApplicationConstraints_get_app_queue_size(PrrtApplicationConstraints *applicationConstraints)
{
pthread_mutex_lock(&applicationConstraints->lock);
uint32_t size = applicationConstraints->queue_size;
pthread_mutex_unlock(&applicationConstraints->lock);
return size;
return (uint32_t) atomic_load_explicit(&applicationConstraints->queue_size, memory_order_acquire);
}
bool PrrtApplicationConstraints_set_app_queue_size(PrrtApplicationConstraints *applicationConstraints, uint32_t size)
{
pthread_mutex_lock(&applicationConstraints->lock);
applicationConstraints->queue_size = size;
pthread_mutex_unlock(&applicationConstraints->lock);
atomic_store_explicit(&applicationConstraints->queue_size, size, memory_order_release);
return true;
}
......@@ -5,8 +5,7 @@
typedef struct applicationConstraints {
prrtTimedelta_t targetDelay_us;
uint32_t queue_size;
pthread_mutex_t lock;
atomic_uint_fast32_t queue_size;
} PrrtApplicationConstraints;
PrrtApplicationConstraints *PrrtApplicationConstraints_create(prrtTimedelta_t target_delay_us);
......
Markdown is supported
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