Skip to content
Snippets Groups Projects
Commit 9d8403eb authored by Federico's avatar Federico
Browse files

Reorder Queue methods

parent b7dcc404
Branches
No related tags found
2 merge requests!40Update to Miosix 2.7,!17Draft: Improved miosix build system and fixed cmake scripts
......@@ -88,13 +88,6 @@ public:
*/
void waitUntilNotFull();
/**
* Get an element from the queue. If the queue is empty, then sleep until
* an element becomes available.
* \param elem an element from the queue
*/
void get(T& elem);
/**
* Put an element to the queue. If the queue is full, then sleep until a
* place becomes available.
......@@ -103,46 +96,53 @@ public:
void put(const T& elem);
/**
* Get an element from the queue, only if the queue is not empty.<br>
* Put an element to the queue, only if th queue is not full.<br>
* Can ONLY be used inside an IRQ, or when interrupts are disabled.
* \param elem an element from the queue. The element is valid only if the
* \param elem element to add. The element has been added only if the
* return value is true
* \return true if the queue was not empty
* \return true if the queue was not full.
*/
bool IRQget(T& elem);
bool IRQput(const T& elem);
/**
* Get an element from the queue, only if the queue is not empty.<br>
* Put an element to the queue, only if th queue is not full.<br>
* Can ONLY be used inside an IRQ, or when interrupts are disabled.
* \param elem an element from the queue. The element is valid only if the
* \param elem element to add. The element has been added only if the
* return value is true
* \param hppw is not modified if no thread is woken or if the woken thread
* has a lower or equal priority than the currently running thread, else is
* set to true
* \return true if the queue was not empty
* \return true if the queue was not full.
*/
bool IRQget(T& elem, bool& hppw);
bool IRQput(const T& elem, bool& hppw);
/**
* Put an element to the queue, only if th queue is not full.<br>
* Get an element from the queue. If the queue is empty, then sleep until
* an element becomes available.
* \param elem an element from the queue
*/
void get(T& elem);
/**
* Get an element from the queue, only if the queue is not empty.<br>
* Can ONLY be used inside an IRQ, or when interrupts are disabled.
* \param elem element to add. The element has been added only if the
* \param elem an element from the queue. The element is valid only if the
* return value is true
* \return true if the queue was not full.
* \return true if the queue was not empty
*/
bool IRQput(const T& elem);
bool IRQget(T& elem);
/**
* Put an element to the queue, only if th queue is not full.<br>
* Get an element from the queue, only if the queue is not empty.<br>
* Can ONLY be used inside an IRQ, or when interrupts are disabled.
* \param elem element to add. The element has been added only if the
* \param elem an element from the queue. The element is valid only if the
* return value is true
* \param hppw is not modified if no thread is woken or if the woken thread
* has a lower or equal priority than the currently running thread, else is
* set to true
* \return true if the queue was not full.
* \return true if the queue was not empty
*/
bool IRQput(const T& elem, bool& hppw);
bool IRQget(T& elem, bool& hppw);
/**
* Clear all items in the queue.<br>
......@@ -215,35 +215,59 @@ void Queue<T,len>::waitUntilNotFull()
}
template <typename T, unsigned int len>
void Queue<T,len>::get(T& elem)
void Queue<T,len>::put(const T& elem)
{
FastInterruptDisableLock dLock;
IRQwakeWaitingThread();
while(isEmpty())
while(isFull())
{
waiting=Thread::IRQgetCurrentThread();
Thread::IRQenableIrqAndWait(dLock);
IRQwakeWaitingThread();
}
numElem--;
elem=buffer[getPos];
if(++getPos==len) getPos=0;
numElem++;
buffer[putPos]=elem;
if(++putPos==len) putPos=0;
}
template <typename T, unsigned int len>
void Queue<T,len>::put(const T& elem)
bool Queue<T,len>::IRQput(const T& elem)
{
IRQwakeWaitingThread();
if(isFull()) return false;
numElem++;
buffer[putPos]=elem;
if(++putPos==len) putPos=0;
return true;
}
template <typename T, unsigned int len>
bool Queue<T,len>::IRQput(const T& elem, bool& hppw)
{
if(waiting && (Thread::IRQgetCurrentThread()->IRQgetPriority() <
waiting->IRQgetPriority())) hppw=true;
IRQwakeWaitingThread();
if(isFull()) return false;
numElem++;
buffer[putPos]=elem;
if(++putPos==len) putPos=0;
return true;
}
template <typename T, unsigned int len>
void Queue<T,len>::get(T& elem)
{
FastInterruptDisableLock dLock;
IRQwakeWaitingThread();
while(isFull())
while(isEmpty())
{
waiting=Thread::IRQgetCurrentThread();
Thread::IRQenableIrqAndWait(dLock);
IRQwakeWaitingThread();
}
numElem++;
buffer[putPos]=elem;
if(++putPos==len) putPos=0;
numElem--;
elem=buffer[getPos];
if(++getPos==len) getPos=0;
}
template <typename T, unsigned int len>
......@@ -270,30 +294,6 @@ bool Queue<T,len>::IRQget(T& elem, bool& hppw)
return true;
}
template <typename T, unsigned int len>
bool Queue<T,len>::IRQput(const T& elem)
{
IRQwakeWaitingThread();
if(isFull()) return false;
numElem++;
buffer[putPos]=elem;
if(++putPos==len) putPos=0;
return true;
}
template <typename T, unsigned int len>
bool Queue<T,len>::IRQput(const T& elem, bool& hppw)
{
if(waiting && (Thread::IRQgetCurrentThread()->IRQgetPriority() <
waiting->IRQgetPriority())) hppw=true;
IRQwakeWaitingThread();
if(isFull()) return false;
numElem++;
buffer[putPos]=elem;
if(++putPos==len) putPos=0;
return true;
}
//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