X-Git-Url: https://git.hcoop.net/clinton/Smoothieware.git/blobdiff_plain/2ec0fe9e949383131dbf8c759160318f10f9a992..c501670b6ac2e7529af69e00c1600e46a90e2c68:/src/modules/robot/Conveyor.cpp diff --git a/src/modules/robot/Conveyor.cpp b/src/modules/robot/Conveyor.cpp index f91709fd..02449060 100644 --- a/src/modules/robot/Conveyor.cpp +++ b/src/modules/robot/Conveyor.cpp @@ -23,7 +23,8 @@ using namespace std; Conveyor::Conveyor(){ this->current_block = NULL; this->looking_for_new_block = false; - flush_blocks = 0; + queue.resize(32); + gc_pending = queue.tail_i; } void Conveyor::on_module_loaded(){ @@ -32,31 +33,29 @@ void Conveyor::on_module_loaded(){ // Delete blocks here, because they can't be deleted in interrupt context ( see Block.cpp:release ) void Conveyor::on_idle(void* argument){ - while (flush_blocks > 0){ + while (queue.tail_i != gc_pending) + { // Cleanly delete block - Block* block = queue.get_tail_ref(); + Block* block = queue.tail_ref(); block->gcodes.clear(); - queue.delete_tail(); - __disable_irq(); - flush_blocks--; - __enable_irq(); + queue.consume_tail(); } } void Conveyor::append_gcode(Gcode* gcode) { gcode->mark_as_taken(); - if (queue.size() == 0) + if (queue.is_empty()) THEKERNEL->call_event(ON_GCODE_EXECUTE, gcode); else - queue.get_ref(queue.size() - 1)->append_gcode(gcode); + queue.head_ref()->append_gcode(gcode); } // Append a block to the list Block* Conveyor::new_block(){ // Take the next untaken block on the queue ( the one after the last one ) - Block* block = this->queue.get_head_ref(); + Block* block = this->queue.head_ref(); // Then clean it up block->clear(); @@ -64,7 +63,7 @@ Block* Conveyor::new_block(){ block->final_rate = -2; // Create a new virgin Block in the queue - this->queue.push_back(Block()); + queue.produce_head(); return block; } @@ -84,7 +83,7 @@ void Conveyor::pop_and_process_new_block(int debug){ if( this->current_block != NULL ){ this->looking_for_new_block = false; return; } // Return if queue is empty - if( this->queue.size() == 0 ){ + if( queue.is_empty() ){ this->current_block = NULL; // TODO : ON_QUEUE_EMPTY event this->looking_for_new_block = false; @@ -92,7 +91,7 @@ void Conveyor::pop_and_process_new_block(int debug){ } // Get a new block - this->current_block = this->queue.get_ref(0); + this->current_block = this->queue.tail_ref(); // Tell all modules about it THEKERNEL->call_event(ON_BLOCK_BEGIN, this->current_block); @@ -110,21 +109,26 @@ void Conveyor::pop_and_process_new_block(int debug){ } // Wait for the queue to have a given number of free blocks -void Conveyor::wait_for_queue(int free_blocks){ - while( this->queue.size() >= this->queue.capacity()-free_blocks ){ +void Conveyor::wait_for_queue(int free_blocks) +{ + while (queue.is_full()) THEKERNEL->call_event(ON_IDLE); - } } // Wait for the queue to be empty -void Conveyor::wait_for_empty_queue(){ - while( this->queue.size() > 0){ +void Conveyor::wait_for_empty_queue() +{ + while (!queue.is_empty()) THEKERNEL->call_event(ON_IDLE); - } } // Return true if the queue is empty -bool Conveyor::is_queue_empty(){ - return (this->queue.size() == 0); +bool Conveyor::is_queue_empty() +{ + return queue.is_empty(); } + +// feels hacky, but apparently the way to do it +#include "HeapRing.cpp" +template class HeapRing;