Module: xenomai-forge Branch: master Commit: 0e70b34a2d95bce15257ee7bf201cf8ab52d2fa8 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=0e70b34a2d95bce15257ee7bf201cf8ab52d2fa8
Author: Philippe Gerum <r...@xenomai.org> Date: Wed Oct 23 15:44:12 2013 +0200 lib/alchemy: use common name generator --- lib/alchemy/alarm.c | 8 +++----- lib/alchemy/buffer.c | 8 +++----- lib/alchemy/cond.c | 8 +++----- lib/alchemy/event.c | 8 +++----- lib/alchemy/heap.c | 8 +++----- lib/alchemy/internal.c | 16 ---------------- lib/alchemy/internal.h | 10 +--------- lib/alchemy/mutex.c | 8 +++----- lib/alchemy/pipe.c | 8 +++----- lib/alchemy/queue.c | 8 +++----- lib/alchemy/sem.c | 8 +++----- lib/alchemy/task.c | 8 +++----- 12 files changed, 31 insertions(+), 75 deletions(-) diff --git a/lib/alchemy/alarm.c b/lib/alchemy/alarm.c index 5c0e869..e622ea4 100644 --- a/lib/alchemy/alarm.c +++ b/lib/alchemy/alarm.c @@ -39,10 +39,8 @@ struct pvcluster alchemy_alarm_table; -static struct alchemy_namegen alarm_namegen = { - .prefix = "alarm", - .length = sizeof ((struct alchemy_alarm *)0)->name, -}; +static DEFINE_NAME_GENERATOR(alarm_namegen, "alarm", + struct alchemy_alarm, name); static struct alchemy_alarm *get_alchemy_alarm(RT_ALARM *alarm, int *err_r) { @@ -138,7 +136,7 @@ int rt_alarm_create(RT_ALARM *alarm, const char *name, if (ret) goto fail; - alchemy_build_name(acb->name, name, &alarm_namegen); + generate_name(acb->name, name, &alarm_namegen); acb->handler = handler; acb->arg = arg; acb->expiries = 0; diff --git a/lib/alchemy/buffer.c b/lib/alchemy/buffer.c index 7aa8882..9a15af8 100644 --- a/lib/alchemy/buffer.c +++ b/lib/alchemy/buffer.c @@ -43,10 +43,8 @@ struct syncluster alchemy_buffer_table; -static struct alchemy_namegen buffer_namegen = { - .prefix = "buffer", - .length = sizeof ((struct alchemy_buffer *)0)->name, -}; +static DEFINE_NAME_GENERATOR(buffer_namegen, "buffer", + struct alchemy_buffer, name); DEFINE_SYNC_LOOKUP(buffer, RT_BUFFER); @@ -140,7 +138,7 @@ int rt_buffer_create(RT_BUFFER *bf, const char *name, goto fail_bufalloc; } - alchemy_build_name(bcb->name, name, &buffer_namegen); + generate_name(bcb->name, name, &buffer_namegen); bcb->magic = buffer_magic; bcb->mode = mode; bcb->bufsz = bufsz; diff --git a/lib/alchemy/cond.c b/lib/alchemy/cond.c index 6ef388a..9b3d013 100644 --- a/lib/alchemy/cond.c +++ b/lib/alchemy/cond.c @@ -49,10 +49,8 @@ struct syncluster alchemy_cond_table; -static struct alchemy_namegen cond_namegen = { - .prefix = "cond", - .length = sizeof ((struct alchemy_cond *)0)->name, -}; +static DEFINE_NAME_GENERATOR(cond_namegen, "cond", + struct alchemy_cond, name); DEFINE_LOOKUP_PRIVATE(cond, RT_COND); @@ -109,7 +107,7 @@ int rt_cond_create(RT_COND *cond, const char *name) goto out; } - alchemy_build_name(ccb->name, name, &cond_namegen); + generate_name(ccb->name, name, &cond_namegen); __RT(pthread_condattr_init(&cattr)); __RT(pthread_condattr_setpshared(&cattr, mutex_scope_attribute)); __RT(pthread_condattr_setclock(&cattr, CLOCK_COPPERPLATE)); diff --git a/lib/alchemy/event.c b/lib/alchemy/event.c index c1ab944..018e825 100644 --- a/lib/alchemy/event.c +++ b/lib/alchemy/event.c @@ -44,10 +44,8 @@ struct syncluster alchemy_event_table; -static struct alchemy_namegen event_namegen = { - .prefix = "event", - .length = sizeof ((struct alchemy_event *)0)->name, -}; +static DEFINE_NAME_GENERATOR(event_namegen, "event", + struct alchemy_event, name); DEFINE_LOOKUP_PRIVATE(event, RT_EVENT); @@ -124,7 +122,7 @@ int rt_event_create(RT_EVENT *event, const char *name, goto out; } - alchemy_build_name(evcb->name, name, &event_namegen); + generate_name(evcb->name, name, &event_namegen); evcb->magic = event_magic; if (mode & EV_PRIO) evobj_flags = EVOBJ_PRIO; diff --git a/lib/alchemy/heap.c b/lib/alchemy/heap.c index b1281ed..f61abb1 100644 --- a/lib/alchemy/heap.c +++ b/lib/alchemy/heap.c @@ -37,10 +37,8 @@ struct syncluster alchemy_heap_table; -static struct alchemy_namegen heap_namegen = { - .prefix = "heap", - .length = sizeof ((struct alchemy_heap *)0)->name, -}; +static DEFINE_NAME_GENERATOR(heap_namegen, "heap", + struct alchemy_heap, name); DEFINE_SYNC_LOOKUP(heap, RT_HEAP); @@ -146,7 +144,7 @@ int rt_heap_create(RT_HEAP *heap, goto out; } - alchemy_build_name(hcb->name, name, &heap_namegen); + generate_name(hcb->name, name, &heap_namegen); hcb->magic = heap_magic; hcb->mode = mode; hcb->size = heapsz; diff --git a/lib/alchemy/internal.c b/lib/alchemy/internal.c index 793a1f8..7e998ff 100644 --- a/lib/alchemy/internal.c +++ b/lib/alchemy/internal.c @@ -24,22 +24,6 @@ #include <copperplate/heapobj.h> #include "internal.h" -char *alchemy_build_name(char *buf, const char *name, - struct alchemy_namegen *ngen) -{ - int len = ngen->length - 1, tag; - - if (name && *name) { - strncpy(buf, name, len); - buf[len] = '\0'; - } else { - tag = atomic_add_fetch(ngen->serial, 1); - snprintf(buf, len, "%s@%d", ngen->prefix, tag); - } - - return buf; -} - int alchemy_bind_object(const char *name, struct syncluster *sc, RTIME timeout, int offset, diff --git a/lib/alchemy/internal.h b/lib/alchemy/internal.h index de3675c..ad5d35a 100644 --- a/lib/alchemy/internal.h +++ b/lib/alchemy/internal.h @@ -19,14 +19,9 @@ #ifndef _ALCHEMY_INTERNAL_H #define _ALCHEMY_INTERNAL_H +#include "boilerplate/ancillaries.h" #include "timer.h" -struct alchemy_namegen { - const char *prefix; - int length; - int serial; -}; - #define DEFINE_SYNC_LOOKUP(__name, __dsctype) \ static inline struct alchemy_ ## __name * \ get_alchemy_ ## __name(__dsctype *desc, \ @@ -89,9 +84,6 @@ find_alchemy_ ## __name(__dsctype *desc, int *err_r) \ struct syncluster; -char *alchemy_build_name(char *buf, const char *name, - struct alchemy_namegen *ngen); - int alchemy_bind_object(const char *name, struct syncluster *sc, RTIME timeout, int offset, diff --git a/lib/alchemy/mutex.c b/lib/alchemy/mutex.c index 8aeb5e1..96722fa 100644 --- a/lib/alchemy/mutex.c +++ b/lib/alchemy/mutex.c @@ -52,10 +52,8 @@ struct syncluster alchemy_mutex_table; -static struct alchemy_namegen mutex_namegen = { - .prefix = "mutex", - .length = sizeof ((struct alchemy_mutex *)0)->name, -}; +static DEFINE_NAME_GENERATOR(mutex_namegen, "mutex", + struct alchemy_mutex, name); DEFINE_LOOKUP(mutex, RT_MUTEX); @@ -112,7 +110,7 @@ int rt_mutex_create(RT_MUTEX *mutex, const char *name) goto out; } - alchemy_build_name(mcb->name, name, &mutex_namegen); + generate_name(mcb->name, name, &mutex_namegen); mcb->owner = no_alchemy_task; __RT(pthread_mutexattr_init(&mattr)); __RT(pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT)); diff --git a/lib/alchemy/pipe.c b/lib/alchemy/pipe.c index 8ef39ac..da91e90 100644 --- a/lib/alchemy/pipe.c +++ b/lib/alchemy/pipe.c @@ -31,10 +31,8 @@ struct syncluster alchemy_pipe_table; -static struct alchemy_namegen pipe_namegen = { - .prefix = "pipe", - .length = sizeof ((struct alchemy_pipe *)0)->name, -}; +static DEFINE_NAME_GENERATOR(pipe_namegen, "pipe", + struct alchemy_pipe, name); DEFINE_LOOKUP_PRIVATE(pipe, RT_PIPE); @@ -96,7 +94,7 @@ int rt_pipe_create(RT_PIPE *pipe, if (ret) goto fail_sockopt; - alchemy_build_name(pcb->name, name, &pipe_namegen); + generate_name(pcb->name, name, &pipe_namegen); pcb->sock = sock; pcb->magic = pipe_magic; diff --git a/lib/alchemy/queue.c b/lib/alchemy/queue.c index 1b91170..0b14202 100644 --- a/lib/alchemy/queue.c +++ b/lib/alchemy/queue.c @@ -39,10 +39,8 @@ struct syncluster alchemy_queue_table; -static struct alchemy_namegen queue_namegen = { - .prefix = "queue", - .length = sizeof ((struct alchemy_queue *)0)->name, -}; +static DEFINE_NAME_GENERATOR(queue_namegen, "queue", + struct alchemy_queue, name); DEFINE_SYNC_LOOKUP(queue, RT_QUEUE); @@ -137,7 +135,7 @@ int rt_queue_create(RT_QUEUE *queue, const char *name, if (qcb == NULL) goto out; - alchemy_build_name(qcb->name, name, &queue_namegen); + generate_name(qcb->name, name, &queue_namegen); /* * The message pool has to be part of the main heap for proper * sharing between processes. diff --git a/lib/alchemy/sem.c b/lib/alchemy/sem.c index b7bf44b..88a0997 100644 --- a/lib/alchemy/sem.c +++ b/lib/alchemy/sem.c @@ -49,10 +49,8 @@ struct syncluster alchemy_sem_table; -static struct alchemy_namegen sem_namegen = { - .prefix = "sem", - .length = sizeof ((struct alchemy_sem *)0)->name, -}; +static DEFINE_NAME_GENERATOR(sem_namegen, "sem", + struct alchemy_sem, name); DEFINE_LOOKUP_PRIVATE(sem, RT_SEM); @@ -149,7 +147,7 @@ int rt_sem_create(RT_SEM *sem, const char *name, goto out; } - alchemy_build_name(scb->name, name, &sem_namegen); + generate_name(scb->name, name, &sem_namegen); scb->magic = sem_magic; if (syncluster_addobj(&alchemy_sem_table, scb->name, &scb->cobj)) { diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c index 422f056..2a0496e 100644 --- a/lib/alchemy/task.c +++ b/lib/alchemy/task.c @@ -39,10 +39,8 @@ union alchemy_wait_union { struct syncluster alchemy_task_table; -static struct alchemy_namegen task_namegen = { - .prefix = "task", - .length = sizeof ((struct alchemy_task *)0)->name, -}; +static DEFINE_NAME_GENERATOR(task_namegen, "task", + struct alchemy_task, name); static struct alchemy_task *find_alchemy_task(RT_TASK *task, int *err_r) { @@ -211,7 +209,7 @@ static int create_tcb(struct alchemy_task **tcbp, RT_TASK *task, if (tcb == NULL) return -ENOMEM; - alchemy_build_name(tcb->name, name, &task_namegen); + generate_name(tcb->name, name, &task_namegen); tcb->mode = mode; tcb->entry = NULL; /* Not yet known. */ _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git