Example #1
0
int main(int argc, char** argv) {
    ArrayQueue MevaCua; 
    cout<< "Mida actual de la cua: " << MevaCua.size() << endl; 
    cout<< "Encuem 3 elements a la cua... " << endl; 
    
    MevaCua.enqueue('1');
    MevaCua.enqueue('2'); 
    try{
    MevaCua.enqueue('3'); 
    }
    catch(CuaPlena& e){
            cout << e.what() << endl;
    }
    
    MevaCua.print(); 
    cout << "Cua plena (0:no, 1:si): " << MevaCua.full()<<endl; 
    cout<< "Treiem 1er element de la cua: "<<endl;
    try{
    MevaCua.dequeue();
    }
    catch(CuaBuida& e){
            cout << e.what() << endl;
        }
    MevaCua.print(); 
    cout<< "Treiem 2on element de la cua: " <<endl; 
    MevaCua.dequeue();  
    cout<< "Encuem 2 elements a la cua... " << endl; 
    MevaCua.enqueue('4'); 
    MevaCua.enqueue('5');  
    cout<< "Treiem 3er element de la cua: " <<endl; 
    MevaCua.dequeue(); 
    MevaCua.print(); 
    cout<<"Mida actual de la cua: " << MevaCua.size() << endl; 
    cout<<"Cua buida (0:no, 1:si): " << MevaCua.empty()<<endl;
}
Example #2
0
 /**
  * Initiate the detection of the minimal event barrier starting
  * now. If this method returns false it means that no events were
  * currently active and the minimal event barrier was infinitely
  * small. If this method returns false the handler will not be
  * notified of the completion of the barrier. If this method
  * returns true it means that the started barrier is pending and
  * that the handler passed to this method will be notified of its
  * completion at a later time.
  *
  * @return true if a barrier was started, false if no events were active
  * @param handler handler notified of the completion of the barrier
  **/
 bool startBarrier(T &handler) {
     if (_count == 0 && _queue.empty()) {
         return false;
     }
     _queue.push(std::make_pair(_count, &handler));
     ++_token;
     _count = 0;
     return true;
 }
Example #3
0
 /**
  * Signal the completion of an event. The value passed to this
  * method must be the same as the return value previously obtained
  * from the startEvent method. This method will signal the
  * completion of all pending barriers that were completed by the
  * completion of this event.
  *
  * @param token opaque token identifying the completed event
  **/
 void completeEvent(uint32_t token) {
     if (token == _token) {
         --_count;
         return;
     }
     --_queue.access(_queue.size() - (_token - token)).first;
     while (!_queue.empty() && _queue.front().first == 0) {
         _queue.front().second->completeBarrier();
         _queue.pop();
     }
 }
Example #4
0
/*
 * Sequence of instructions that the queue object can run.
 */
int main(int argc, char** argv) {
    ArrayQueue mevaCua (MAX_QUEUE);
    cout << "Mida actual de la cua: " << mevaCua.size() << endl;
    cout << "Encuem 3 elements a la cua..." << endl;
    mevaCua.enqueue(1); mevaCua.enqueue(2); mevaCua.enqueue(3);
    mevaCua.print();
    cout << "Cua plena (0: no, 1: si): " << mevaCua.full() << endl;
    cout << "Traiem 1er element de la cua: " << mevaCua.dequeue() << endl;
    mevaCua.print();
    cout << "Traiem 2on element de la cua: " << mevaCua.dequeue() << endl;
    cout << "Encuem 2 elements a la cua... " << endl;
    mevaCua.enqueue(4); mevaCua.enqueue(5);
    cout << "Traiem 3er element de la cua: " << mevaCua.dequeue() << endl;
    cout << "Mida actual de la cua: " << mevaCua.size() << endl;
    mevaCua.print();
    cout << "Cua buida (0:no, 1:si): " << mevaCua.empty() << endl;
    return 0;
}