From aac276872bc7fd71f1e25f4193d013cde0cee149 Mon Sep 17 00:00:00 2001 From: Ban Siesta Date: Sun, 24 May 2015 10:02:08 +0100 Subject: [PATCH] ringbuffer: use a namespace for ringbuffer to avoid 'multiple definitions in vtable' bug --- src/drivers/device/module.mk | 5 +++-- src/drivers/device/ringbuffer.cpp | 7 ++++++- src/drivers/device/ringbuffer.h | 12 +++++------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/drivers/device/module.mk b/src/drivers/device/module.mk index a9e964ef94..c206a5037c 100644 --- a/src/drivers/device/module.mk +++ b/src/drivers/device/module.mk @@ -41,7 +41,8 @@ SRCS = \ cdev.cpp \ i2c_nuttx.cpp \ pio.cpp \ - spi.cpp + spi.cpp \ + ringbuffer.cpp else SRCS = \ device_posix.cpp \ @@ -50,5 +51,5 @@ SRCS = \ vdev_posix.cpp \ i2c_posix.cpp \ sim.cpp \ - ringbuffer.cpp + ringbuffer.cpp endif diff --git a/src/drivers/device/ringbuffer.cpp b/src/drivers/device/ringbuffer.cpp index 239b263ec2..c30e0a54df 100644 --- a/src/drivers/device/ringbuffer.cpp +++ b/src/drivers/device/ringbuffer.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (C) 2013 PX4 Development Team. All rights reserved. + * Copyright (C) 2013-2015 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -40,6 +40,9 @@ #include "ringbuffer.h" #include +namespace ringbuffer +{ + RingBuffer::RingBuffer(unsigned num_items, size_t item_size) : _num_items(num_items), _item_size(item_size), @@ -398,3 +401,5 @@ RingBuffer::print_info(const char *name) _tail, _buf); } + +} // namespace ringbuffer diff --git a/src/drivers/device/ringbuffer.h b/src/drivers/device/ringbuffer.h index 26d0df0272..4fcdaf47fa 100644 --- a/src/drivers/device/ringbuffer.h +++ b/src/drivers/device/ringbuffer.h @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (C) 2013 PX4 Development Team. All rights reserved. + * Copyright (C) 2013-2015 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -43,6 +43,9 @@ #include #include +namespace ringbuffer __EXPORT +{ + class RingBuffer { public: RingBuffer(unsigned ring_size, size_t entry_size); @@ -172,9 +175,4 @@ private: RingBuffer operator=(const RingBuffer&); }; -#ifdef __PX4_NUTTX -// Not sure why NuttX requires these to be defined in the header file -// but on other targets it causes a problem with multiple definitions -// at link time -#include "ringbuffer.cpp" -#endif +} // namespace ringbuffer