Skip to content
Snippets Groups Projects
Commit 4c7045a2 authored by Federico's avatar Federico
Browse files

Fix class Queue not calling destructors for types that need it

parent d963e7fd
Branches
Tags before-git-migration
2 merge requests!40Update to Miosix 2.7,!17Draft: Improved miosix build system and fixed cmake scripts
......@@ -175,11 +175,7 @@ public:
* Same as reset(), but to be used only inside IRQs or when interrupts are
* disabled.
*/
void IRQreset()
{
IRQwakeWaitingThread();
putPos=getPos=numElem=0;
}
void IRQreset();
//Unwanted methods
Queue(const Queue& s) = delete;
......@@ -290,11 +286,28 @@ bool Queue<T,len>::IRQget(T& elem, bool *hppw)
IRQwakeWaitingThread();
if(isEmpty()) return false;
numElem--;
elem=buffer[getPos];
elem=std::move(buffer[getPos]);
if(++getPos==len) getPos=0;
return true;
}
template <typename T, unsigned int len>
void Queue<T,len>::IRQreset()
{
IRQwakeWaitingThread();
//Relying on constant folding to omit this code for trivial types
if(std::is_trivially_destructible<T>::value==false)
{
while(!isEmpty())
{
numElem--;
buffer[getPos].~T();
if(++getPos==len) getPos=0;
}
}
putPos=getPos=numElem=0;
}
//This partial specialization is meant to to produce compiler errors in case an
//attempt is made to instantiate a Queue with zero size, as it is forbidden
template<typename T> class Queue<T,0> {};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment