mn_workqueue.hpp
Go to the documentation of this file.
1 /*
2 *This file is part of the Mini Thread Library (https://github.com/RoseLeBlood/MiniThread ).
3 *Copyright (c) 2020 Amber-Sophia Schroeck
4 *
5 *The Mini Thread Library is free software; you can redistribute it and/or modify
6 *it under the terms of the GNU Lesser General Public License as published by
7 *the Free Software Foundation, version 3, or (at your option) any later version.
8 
9 *The Mini Thread Library is distributed in the hope that it will be useful, but
10 *WITHOUT ANY WARRANTY; without even the implied warranty of
11 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 *General Public License for more details.
13 *
14 *You should have received a copy of the GNU Lesser General Public
15 *License along with the Mini Thread Library; if not, see
16 *<https://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef MINLIB_ESP32_WORK_QUEUE_BASE_
20 #define MINLIB_ESP32_WORK_QUEUE_BASE_
21 
22 #include "mn_queue.hpp"
23 #include "mn_workqueue_item.hpp"
24 #include "mn_workqueue_task.hpp"
25 
26 namespace mn {
27  namespace queue {
41  friend class work_queue_task;
42  public:
50  uint16_t usStackDepth,
51  uint8_t uiMaxWorkItems);
52 
56  virtual ~basic_work_queue();
57 
68  virtual int create(int iCore = MN_THREAD_CONFIG_DEFAULT_WORKQUEUE_CORE);
73  virtual void destroy();
74 
85  virtual int queue(work_queue_item_t *work,
86  unsigned int timeout = MN_THREAD_CONFIG_TIMEOUT_QUEUE_DEFAULT);
87 
93  volatile bool& running() { return m_bRunning; }
94 
98  uint8_t get_num_items_worked();
102  uint8_t get_num_items_error();
103 
109  bool is_ready();
110  protected:
117  virtual work_queue_item* get_next_item(unsigned int timeout);
118 
127  virtual int create_engine(int iCore) = 0;
132  virtual void destroy_engine() = 0;
133  protected:
148 
150  uint16_t m_usStackDepth;
152 
156  volatile uint8_t m_uiNumWorks;
160  volatile uint8_t m_uiErrorsNumWorks;
164  volatile bool m_bRunning;
165  };
166  }
167 }
168 
169 #endif
Definition: mn_mutex.hpp:37
priority
Task priority.
Definition: mn_task.hpp:93
Queue class wrapper for FreeRTOS queues.
Definition: queue/mn_queue.hpp:31
Definition: mn_workqueue.hpp:40
uint8_t get_num_items_error()
Definition: mn_workqueue.cpp:126
virtual int queue(work_queue_item_t *work, unsigned int timeout=MN_THREAD_CONFIG_TIMEOUT_QUEUE_DEFAULT)
Definition: mn_workqueue.cpp:91
virtual work_queue_item * get_next_item(unsigned int timeout)
Definition: mn_workqueue.cpp:102
basic_work_queue(basic_task::priority uiPriority, uint16_t usStackDepth, uint8_t uiMaxWorkItems)
Definition: mn_workqueue.cpp:35
basic_task::priority m_uiPriority
Definition: mn_workqueue.hpp:149
mutex_t m_ThreadJob
Definition: mn_workqueue.hpp:147
virtual int create(int iCore=MN_THREAD_CONFIG_DEFAULT_WORKQUEUE_CORE)
Definition: mn_workqueue.cpp:61
bool is_ready()
Definition: mn_workqueue.cpp:135
uint8_t m_uiMaxWorkItems
Definition: mn_workqueue.hpp:151
uint8_t get_num_items_worked()
Definition: mn_workqueue.cpp:117
virtual int create_engine(int iCore)=0
virtual ~basic_work_queue()
Definition: mn_workqueue.cpp:54
uint16_t m_usStackDepth
Definition: mn_workqueue.hpp:150
virtual void destroy()
Definition: mn_workqueue.cpp:80
mutex_t m_ThreadStatus
Definition: mn_workqueue.hpp:142
volatile bool & running()
Definition: mn_workqueue.hpp:93
virtual void destroy_engine()=0
volatile bool m_bRunning
Definition: mn_workqueue.hpp:164
volatile uint8_t m_uiErrorsNumWorks
Definition: mn_workqueue.hpp:160
volatile uint8_t m_uiNumWorks
Definition: mn_workqueue.hpp:156
queue_t * m_pWorkItemQueue
Definition: mn_workqueue.hpp:137
Definition: mn_workqueue_item.hpp:30
Definition: mn_workqueue_task.hpp:33
#define MN_THREAD_CONFIG_TIMEOUT_QUEUE_DEFAULT
Definition: mn_config.hpp:387
#define MN_THREAD_CONFIG_DEFAULT_WORKQUEUE_CORE
Pre defined on which core must run the work queue task, can override in the create function.
Definition: mn_config.hpp:103
basic_queue< T, TMAXITEMS, TITEMSIZE > queue
Definition: container/mn_queue.hpp:239
Definition: mn_allocator_typetraits.hpp:25