Defines | Enumerations | Functions

thread wrapper
[LIM utility library]

Defines

#define lthread_t   pthread_t
#define lthread_mutex_t   pthread_mutex_t
#define lthread_cond_t   pthread_cond_t
#define LTHREAD_MUTEX_INITIALIZER   PTHREAD_MUTEX_INITIALIZER
#define LTHREAD_COND_INITIALIZER   PTHREAD_COND_INITIALIZER
#define lthread_mutex_init(m)   pthread_mutex_init(m, NULL)
#define lthread_mutex_destroy(m)   pthread_mutex_destroy(m)
#define lthread_mutex_lock(m)   pthread_mutex_lock(m)
#define lthread_mutex_unlock(m)   pthread_mutex_unlock(m)
#define lthread_cond_init(c)   pthread_cond_init(c, NULL)
#define lthread_cond_destroy(c)   pthread_cond_destroy(c)
#define lthread_cond_wait(c, m)   pthread_cond_wait(c, m)
#define lthread_cond_broadcast(c)   pthread_cond_broadcast(c)
#define lthread_cond_signal(c)   pthread_cond_signal(c)
#define lthread_join(t)   pthread_join(t, NULL)
#define lthread_self()   pthread_self()
#define lthread_sem_t   sem_t
#define lthread_sem_init(s, v)   sem_init(s, 0, v)
#define lthread_sem_destroy(s)   sem_destroy(s)
#define lthread_sem_up(s)   sem_post(s)
#define lthread_sem_down(s)   sem_wait(s)
#define lthread_event_timedwait(c, m, t, e, ret)
#define lthread_event_broadcast(c, m, e)

Enumerations

enum  lthread_type_t { LTHREAD_MUTEX_TIMED, LTHREAD_MUTEX_RECURSIVE, LTHREAD_MUTEX_DEFAULT = LTHREAD_MUTEX_TIMED }
enum  LTHREAD_RUN_COUNT_ID_t { LIM_RUN_COUNT_DEBUG, LIM_RUN_COUNT_end }

Functions

int lthread_mutex_init2 (lthread_mutex_t *m, lthread_type_t type)
int lthread_mutex_timedlock (lthread_mutex_t *mutex, int miliseconds)
int lthread_cond_timedwait (lthread_cond_t *cond, lthread_mutex_t *mutex, int miliseconds)
int lthread_create (lthread_t *lthread, void *(*func)(void *), void *arg, int detached)
int lthread_sem_timeddown (lthread_sem_t *sem, int miliseconds)
int lthread_run_upto_count (void(*exe)(void *arg, lthread_mutex_t *mutex, int count), void *arg, LTHREAD_RUN_COUNT_ID_t id, int count)

Define Documentation

#define lthread_cond_broadcast (   c  )     pthread_cond_broadcast(c)
#define lthread_cond_destroy (   c  )     pthread_cond_destroy(c)
#define lthread_cond_init (   c  )     pthread_cond_init(c, NULL)
#define LTHREAD_COND_INITIALIZER   PTHREAD_COND_INITIALIZER
#define lthread_cond_signal (   c  )     pthread_cond_signal(c)
#define lthread_cond_t   pthread_cond_t
#define lthread_cond_wait (   c,
  m 
)    pthread_cond_wait(c, m)
#define lthread_event_broadcast (   c,
  m,
  e 
)
Value:
do {      \
        lthread_mutex_lock(m);                     \
        e;                                         \
        lthread_cond_broadcast(c);                 \
        lthread_mutex_unlock(m);                   \
    } while(0)
#define lthread_event_timedwait (   c,
  m,
  t,
  e,
  ret 
)
Value:
do {  \
        ret = 0;                                       \
        lthread_mutex_lock(m);                         \
        while (!(e)) {                                 \
            if (lthread_cond_timedwait(c, m, t)) {     \
                ret = -1; break;                       \
            }                                          \
        }                                              \
        lthread_mutex_unlock(m);                       \
    } while(0)
#define lthread_join (   t  )     pthread_join(t, NULL)
#define lthread_mutex_destroy (   m  )     pthread_mutex_destroy(m)
#define lthread_mutex_init (   m  )     pthread_mutex_init(m, NULL)
#define LTHREAD_MUTEX_INITIALIZER   PTHREAD_MUTEX_INITIALIZER
#define lthread_mutex_lock (   m  )     pthread_mutex_lock(m)
#define lthread_mutex_t   pthread_mutex_t
#define lthread_mutex_unlock (   m  )     pthread_mutex_unlock(m)
#define lthread_self (  )     pthread_self()
#define lthread_sem_destroy (   s  )     sem_destroy(s)
#define lthread_sem_down (   s  )     sem_wait(s)
#define lthread_sem_init (   s,
  v 
)    sem_init(s, 0, v)
#define lthread_sem_t   sem_t
#define lthread_sem_up (   s  )     sem_post(s)
#define lthread_t   pthread_t

Enumeration Type Documentation

LIM run count object ID definitions.

Enumerator:
LIM_RUN_COUNT_DEBUG 
LIM_RUN_COUNT_end 
Enumerator:
LTHREAD_MUTEX_TIMED 
LTHREAD_MUTEX_RECURSIVE 
LTHREAD_MUTEX_DEFAULT 

Function Documentation

int lthread_cond_timedwait ( lthread_cond_t *  cond,
lthread_mutex_t *  mutex,
int  miliseconds 
)
int lthread_create ( lthread_t *  lthread,
void *(*)(void *)  func,
void *  arg,
int  detached 
)
int lthread_mutex_init2 ( lthread_mutex_t *  m,
lthread_type_t  type 
)
int lthread_mutex_timedlock ( lthread_mutex_t *  mutex,
int  miliseconds 
)
int lthread_run_upto_count ( void(*)(void *arg, lthread_mutex_t *mutex, int count)  exe,
void *  arg,
LTHREAD_RUN_COUNT_ID_t  id,
int  count 
)

interface to run 'exe' function upto 'count' times. run 'exe' 'count' times within caller's thread context, through the entire life of the process, when requested from within multiple threads.

if 'count' is greater than 1, each run of 'exe' is not serialized, if required to be, caller shall protect it either with the returned mutex, or custom implementation.

'count' is relative to 'id', not 'exe', in other words, if different 'exe's are requested with the same 'id', only 'count' number of the 'exe's will be run and there is no guarantee of which one runs.

for similar reason, if requested 'count' varies, there is no guarantee exactly how many time 'exe' runs.

use case #1: particularly useful for the case where multiple component plugins reference the same library that has some initialization code to run once, yet the order of component access can not be determined at compile time.

use case #2: run certain debug code up to 'count' times.

Parameters:
exe the executable callback.
arg executable context.
id run count object ID, LTHREAD_RUN_COUNT_ID_t
count maximum allowed run count.
Returns:
0 success, non-zero for error.
int lthread_sem_timeddown ( lthread_sem_t *  sem,
int  miliseconds 
)
LIMOpenMAX Implementation API Reference - Generated by doxygen