applicationConstraints.c 1.31 KB
Newer Older
1 2 3
#include <malloc.h>
#include "../util/common.h"
#include "../util/dbg.h"
4
#include "applicationConstraints.h"
5

6
PrrtApplicationConstraints *PrrtApplicationConstraints_create()
7 8 9
{
    PrrtApplicationConstraints *constraints = calloc(1, sizeof(PrrtApplicationConstraints));
    check_mem(constraints);
10 11 12

    pthread_mutex_init(&constraints->lock, NULL);

13 14
    constraints->targetDelay_us = 1000*1000;

15 16 17 18 19 20 21
    return constraints;

    error:
    PERROR("Not enough memory%s.","");
    return NULL;
}

22
bool PrrtApplicationConstraints_destroy(PrrtApplicationConstraints *applicationConstraints)
23
{
24
    pthread_mutex_destroy(&applicationConstraints->lock);
25 26 27 28
    free(applicationConstraints);
    return true;
}

29
prrtTimedelta_t PrrtApplicationConstraints_get_target_delay(PrrtApplicationConstraints *applicationConstraints)
30
{
31
    pthread_mutex_lock(&applicationConstraints->lock);
32
    prrtTimedelta_t targetDelay = applicationConstraints->targetDelay_us;
33 34 35 36 37 38 39
    pthread_mutex_unlock(&applicationConstraints->lock);
    return targetDelay;
}

bool PrrtApplicationConstraints_set_target_delay(PrrtApplicationConstraints *applicationConstraints, prrtTimedelta_t targetDelay)
{
    pthread_mutex_lock(&applicationConstraints->lock);
40
    applicationConstraints->targetDelay_us = targetDelay;
41 42
    pthread_mutex_unlock(&applicationConstraints->lock);
    return true;
43
}