2 * \file ferret/lib/sensor/__llist_consumer.c
3 * \brief locked list consumer functions.
6 * \author Martin Pohlack <mp26@os.inf.tu-dresden.de>
9 * (c) 2007-2009 Technische Universität Dresden
10 * This file is part of TUD:OS and distributed under the terms of the
11 * GNU General Public License 2.
12 * Please see the COPYING-GPL-2 file for details.
14 #if FERRET_LLIST_MAGIC != ahK6eeNa
15 #error Do not directly include this file, use a propper wrapper!
17 #undef FERRET_LLIST_MAGIC
22 //#include <l4/log/l4log.h>
24 #include <l4/ferret/types.h>
26 #include <l4/sys/ipc.h>
28 // fixme: maybe later we need functions to get more than 1 element out
29 // of the buffer, thereby saving some locking overhead
30 int PREFIX(get)(PREFIX(moni_t) * list, ferret_list_entry_t * el)
35 * 2. check if new data is available (no -> return -1)
36 * 3. check if we lost something and update lost counter
37 * 4. compute offset in locked list's data array
42 FERRET_LLIST_LOCAL_LOCK(list);
44 // check if we have new events for the consumer
45 if (L4_UNLIKELY(list->glob->head.value <= list->next_read.value))
46 return -1; // we have no new events
47 // check if we have lost events
48 if (L4_UNLIKELY(list->glob->head.value - list->next_read.value >
51 list->lost += list->glob->head.value - list->next_read.value -
53 list->next_read.value = list->glob->head.value - list->glob->count;
55 index = list->next_read.lh.low & list->glob->count_mask;
56 memcpy(el, list->out_buf + (index << list->glob->element_size_ld),
57 list->glob->element_size);
59 list->next_read.value++;
60 FERRET_LLIST_LOCAL_UNLOCK(list);
63 //return -2; // corrupt sensor
66 void PREFIX(init_consumer)(void ** addr)
68 PREFIX(moni_t) * temp;
70 temp = malloc(sizeof(PREFIX(moni_t)));
72 // setup some pointers
73 temp->glob = *addr; // store pointer to global structure
74 temp->out_buf = temp->glob->data;
77 temp->header.major = temp->glob->header.major;
78 temp->header.minor = temp->glob->header.minor;
79 temp->header.instance = temp->glob->header.instance;
80 temp->header.type = temp->glob->header.type;
82 // init. local information
84 temp->next_read.value = 0;
86 #ifdef FERRET_LLIST_HAVE_LOCAL_LOCK
87 FERRET_LLIST_LOCAL_INIT(temp);
93 void PREFIX(free_consumer)(void ** addr)
95 void * temp = ((PREFIX(moni_t) *)(*addr))->glob;