ADHD: Simplify FIFO use & address latent issues
Details
o FIFO_DEFINE incorrectly defined the fifo variable as 'workfifo'.
o fifo_add_item() gets multiply defined when new FIFOs are added.
Change the naming so that the fifo name is part of the function
signature. Made FIFO_ADD_ITEM() to create the proper function
name. Updated FIFO_DEFINE() to also create the proper name for
the 'add' function.
o Internalized __FIFO_DESCRIPTOR_ADDRESS(). This is no longer
needed when adding elements to the FIFO; it's now handled in
FIFO_ADD_ITEM().
Testing
Built ADHD on tegra2_aebl, x86-mario.
Verified gavd still functions properly on tegra2_aebl.
BUG=chromium-os:19558
TEST=See above.
Change-Id: Iae4e2fa4af3f61a739e87be4bb8def9d937977db
Signed-off-by: Taylor Hutt <thutt@chromium.org>
diff --git a/gavd/fifo.h b/gavd/fifo.h
index 4e4c3d8..4f8b07a 100644
--- a/gavd/fifo.h
+++ b/gavd/fifo.h
@@ -89,18 +89,30 @@
fifo_entry_t entry; \
} FIFO_ENTRY_TYPE(_name); \
extern fifo_t *_name; \
- extern unsigned fifo_add_item(fifo_t *fifo, \
+ extern unsigned XCONCAT(fifo_add_item_, _name)(fifo_t *fifo, \
const FIFO_ENTRY_TYPE(_name) *entry, \
void *data)
+/* FIFO_ADD_ITEM: Add an item to the named FIFO.
+ *
+ * _name : The name of the fifo. See FIFO_DEFINE, FIFO_DECLARE
+ * _entry: The name of the FIFO entry handler. See FIFO_ENTRY.
+ * _data : The data which is passed as an argument to '_entry'.
+ */
+#define FIFO_ADD_ITEM(_name, _entry, _data) \
+ XCONCAT(fifo_add_item_, _name)(_name, \
+ __FIFO_DESCRIPTOR_ADDRESS(_name, \
+ _entry), \
+ _data)
+
/* FIFO_DEFINE(<fifo name>): Define types & variables for a FIFO.
*
* See FIFO_DECLARE.
*/
#define FIFO_DEFINE(_name) \
LINKERSET_DECLARE(XCONCAT(fifo_entry_, _name)); \
- fifo_t *workfifo; \
- unsigned fifo_add_item(fifo_t *fifo, \
+ fifo_t *_name; \
+ unsigned XCONCAT(fifo_add_item_, _name)(fifo_t *fifo, \
const FIFO_ENTRY_TYPE(_name) *entry, \
void *data) \
{ \
@@ -109,18 +121,23 @@
/* __FIFO_DESCRIPTOR_ID: Creates the name of the internal FIFO descriptor.
*
+ * Internal use only.
+ *
* _fifo: The name of the FIFO. See FIFO_DECLARE().
* _id : The name of the FIFO entry. See FIFO_ENTRY().
*/
#define __FIFO_DESCRIPTOR_ID(_fifo, _id) \
XCONCAT(__fifo_descriptor_, XCONCAT(_fifo, XCONCAT(_, _id)))
-/* FIFO_DESCRIPTOR_ADDRESS: Obtains address of the descrbied FIFO descriptor.
+/* __FIFO_DESCRIPTOR_ADDRESS: Obtains address of the descrbied FIFO
+ * descriptor.
+ *
+ * Internal use only.
*
* _fifo: The name of the FIFO. See FIFO_DECLARE().
* _id : The name of the FIFO entry. See FIFO_ENTRY().
*/
-#define FIFO_DESCRIPTOR_ADDRESS(_fifo, _id) \
+#define __FIFO_DESCRIPTOR_ADDRESS(_fifo, _id) \
&__FIFO_DESCRIPTOR_ID(_fifo, _id)
/* __FIFO_ENTRY_FUNCTION: Creates function name for FIFO entry handler.
diff --git a/gavd/gpio_switch_monitor.c b/gavd/gpio_switch_monitor.c
index 805a59d..d7240f8 100644
--- a/gavd/gpio_switch_monitor.c
+++ b/gavd/gpio_switch_monitor.c
@@ -100,10 +100,7 @@
ss->insert_command = insert_command;
ss->remove_command = remove_command;
ss->state = current_state;
- if (fifo_add_item(workfifo,
- FIFO_DESCRIPTOR_ADDRESS(workfifo,
- gpio_switch_state),
- ss)) {
+ if (FIFO_ADD_ITEM(workfifo, gpio_switch_state, ss)) {
last_state = current_state;
} else {
free(ss);
diff --git a/gavd/set_factory_default.c b/gavd/set_factory_default.c
index 85c5a90..8050b6c 100644
--- a/gavd/set_factory_default.c
+++ b/gavd/set_factory_default.c
@@ -38,6 +38,5 @@
void factory_default_add_event(void)
{
- fifo_add_item(workfifo, FIFO_DESCRIPTOR_ADDRESS(workfifo,
- set_factory_default), NULL);
+ FIFO_ADD_ITEM(workfifo, set_factory_default, NULL);
}