mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 22:59:47 +08:00
Experimental spsc queue
This commit is contained in:
parent
f296d9eadf
commit
d8d24b7509
56
src/experimental/atomic.h
Normal file
56
src/experimental/atomic.h
Normal file
@ -0,0 +1,56 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2017 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ETL_ATOMIC__
|
||||
#define __ETL_ATOMIC__
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if ETL_ATOMIC_SUPPORTED == 1
|
||||
#include <atomic>
|
||||
|
||||
namespace etl
|
||||
{
|
||||
typedef std::atomic<uint32_t> atomic_uint32_t;
|
||||
}
|
||||
#define ETL_CPP11_ATOMIC_AVAILABLE 1
|
||||
#elif defined(ETL_COMPILER_ARM)
|
||||
#include "atomic/atomic_arm.h"
|
||||
#define ETL_ETL_ATOMIC_AVAILABLE 1
|
||||
#elif defined(ETL_COMPILER_GCC)
|
||||
#include "atomic/atomic_gcc.h"
|
||||
#define ETL_ATOMIC_AVAILABLE 1
|
||||
#elif defined(ETL_COMPILER_MSVC)
|
||||
#include "atomic/atomic_windows.h"
|
||||
#define ETL_ATOMIC_AVAILABLE 1
|
||||
#else
|
||||
#warning NO ATOMIC SUPPORT DEFINED!
|
||||
#define ETL_ATOMIC_AVAILABLE 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
57
src/experimental/spsc_queue.h
Normal file
57
src/experimental/spsc_queue.h
Normal file
@ -0,0 +1,57 @@
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include "atomic.h"
|
||||
|
||||
struct spsc_queue_implementation
|
||||
{
|
||||
enum
|
||||
{
|
||||
UNKNOWN,
|
||||
STD_ATOMIC,
|
||||
ETL_ATOMIC,
|
||||
CMSIS_RTOS2,
|
||||
FREERTOS,
|
||||
GCC,
|
||||
WIN32
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T, const size_t IMPLEMENTATION = spsc_queue_implementation::UNKNOWN>
|
||||
class ispsc_queue;
|
||||
|
||||
template <typename T, const size_t SIZE, const size_t IMPLEMENTATION = spsc_queue_implementation::UNKNOWN>
|
||||
class spsc_queue : public ispsc_queue;
|
||||
|
||||
#if ETL_ATOMIC_AVAILABLE
|
||||
template <typename T>
|
||||
class ispsc_queue<T, spsc_queue_implementation::STD_ATOMIC>
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
template <typename T, const size_t SIZE>
|
||||
class spsc_queue<T, SIZE, spsc_queue_implementation::STD_ATOMIC>
|
||||
: public ispsc_queue<T, spsc_queue_implementation::STD_ATOMIC>
|
||||
{
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
#if ETL_OPERATING_SYSTEM == ETL_CMSIS_RTOS2
|
||||
template <typename T, const size_t SIZE>
|
||||
class spsc_queue<T, SIZE, spsc_queue_implementation::CMSIS_RTOS2>
|
||||
: public ispsc_queue<T, spsc_queue_implementation::CMSIS_RTOS2>
|
||||
{
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
#if ETL_OPERATING_SYSTEM == ETL_FREERTOS
|
||||
template <typename T, const size_t SIZE>
|
||||
class spsc_queue<T, SIZE, spsc_queue_implementation::FREERTOS>
|
||||
: public ispsc_queue<T, spsc_queue_implementation::FREERTOS>
|
||||
{
|
||||
|
||||
};
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user