Exemple #1
0
void cleanupStrings()
{
    while (!heapStrings.empty())
    {
        free(heapStrings.front());
        heapStrings.pop();
    }
}
Exemple #2
0
 void wait_and_pop(T& value) {
     std::unique_lock<std::mutex> lock(m_mutex);
     m_data_available.wait(lock, [this] {
         return !m_queue.empty();
     });
     value=std::move(m_queue.front());
     m_queue.pop();
 }
Exemple #3
0
	void pop(int& x) {
		AppLock l(m);
		while(Q.empty()) {
			c.wait(l);
		}
		x = Q.front();
		Q.pop();
	}
Exemple #4
0
 void operator<<(std::queue<_Tp,Range> lhs)
 {
         for(;!lhs.empty();){
                 std::cout<<lhs.front()<<token;
                 lhs.pop();
         }
         std::cout<<last_token<<std::flush;
 }
Exemple #5
0
void PartialMerkleTree::setCompressed(std::queue<uchar_vector>& hashQueue, std::queue<bool>& bitQueue, unsigned int depth)
{
    depth_ = depth;

    if (hashQueue.empty() || bitQueue.empty()) {
        throw std::runtime_error("PartialMerkleTree::setCompressed - Invalid compressed partial merkle tree data.");
    }

    bool bit = bitQueue.front();
    bits_.push_back(bit);
    bitQueue.pop();

    // We've reached a leaf of the partial merkle tree
    if (depth == 0 || !bit) {
        root_ = hashQueue.front();
        merkleHashes_.push_back(hashQueue.front());
        if (bit) txHashes_.push_back(hashQueue.front());
        hashQueue.pop();
        return;
    }

    depth--;

    // we're not at a leaf and bit is set so recurse
    PartialMerkleTree leftSubtree;
    leftSubtree.setCompressed(hashQueue, bitQueue, depth);

    merkleHashes_.swap(leftSubtree.merkleHashes_);
    txHashes_.swap(leftSubtree.txHashes_);
    bits_.splice(bits_.end(), leftSubtree.bits_);

    if (!hashQueue.empty()) {
        // A right subtree also exists, so find it
        PartialMerkleTree rightSubtree;
        rightSubtree.setCompressed(hashQueue, bitQueue, depth);

        root_ = sha256_2(leftSubtree.root_ + rightSubtree.root_);
        merkleHashes_.splice(merkleHashes_.end(), rightSubtree.merkleHashes_);
        txHashes_.splice(txHashes_.end(), rightSubtree.txHashes_);
        bits_.splice(bits_.end(), rightSubtree.bits_);
    }
    else {
        // There's no right subtree - copy over this node's hash
        root_ = sha256_2(leftSubtree.root_ + leftSubtree.root_);
    }
}
	//Entry point for pool threads.
	void execute()
	{
		while( true )
		{
			//Wait on condition variable while the task is empty and the pool is
			//still running.
			boost::unique_lock< boost::mutex > lock( mutex_ );
			while( tasks_.empty() && !stop_ )
			{
                cv_task_.wait( lock );
			}

			// Copy task locally and remove from the queue. This is done within
			// its own scope so that the task object is destructed immediately
			// after running the task. This is useful in the event that the function
			// contains shared_ptr arguments bound via bind.
			if( !tasks_.empty() )
			{
				++busy_;
				boost::function< void() > task = tasks_.front();
				tasks_.pop();

				lock.unlock();

				//Run the task.
				try
				{
					task();
				}
				catch( const std::exception& )
				{
					//Suppress all exceptions
				}

				// Task has finished, so increment count of available threads
				lock.lock();
				++processed_;
				++available_;
				--busy_;
				cv_finished_.notify_one();
			}
			else if( stop_ ) {
				break;
			}
        }
    }
Exemple #7
0
 void wait_and_pop ( Data& value )
 {
    boost::mutex::scoped_lock lock ( _mutex ) ;
    while ( _queue.empty () )
       _cond.wait ( lock ) ;
    value = _queue.front () ;
    _queue.pop () ;
 }
Exemple #8
0
 std::pair<size_t, size_t> push(pair_type && pair, boost::asio::io_service & main_service)
 {
     auto empty = _sessions.empty();
     _sessions.push(std::move(pair));
     if (empty)
         main_service.post(std::bind(&auth_queue::next, this));
     return { _sessions.size(), _counter };
 }
void deleteNodes(std::queue<BruteNode *> &delQueue)
{
	while (!delQueue.empty())
	{
		delete delQueue.front();
		delQueue.pop();
	}
}
Exemple #10
0
 void wait_and_pop(T& value)
 {
     std::unique_lock<std::mutex> lk(mut);
     data_cond.wait(lk,[this]{return !data_queue.empty();});
     value=data_queue.front();
     data_queue.pop();
     empty_cond.notify_one();
 }
Exemple #11
0
	// wait and pop
	void waitPop(T& value) {
		std::unique_lock<std::mutex> lock(mtx_); // GUARD
		while (queue_.empty()) {
			conditionvar_.wait(lock); // WAIT
		}
		value = queue_.front();
		queue_.pop();
	}
Exemple #12
0
void cleanupArgs()
{
    while (!args.empty())
    {
        delete args.front();
        args.pop();
    }
}
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		int i;
		int flag1=1,flag2=1,flag3=1;
		while(!ty1.empty())ty1.pop();
		while(!ty2.empty())ty2.pop();
		while(!ty3.empty())ty3.pop();
		int order,x;
		for(i=1;i<=n;i++){
			scanf("%d%d",&order,&x);
			if(order==1){
				ty3.push(x);
				ty2.push(x);
				ty1.push(x);
				}
			else {
				if(flag3&&!ty3.empty()){
					if(ty3.top()==x)ty3.pop();
					else flag3=0;
					}
				else flag3=0;
				
				if(flag2&&!ty2.empty()){
					if(ty2.top()==x)ty2.pop();
					else flag2=0;
					}
				else flag2=0;
				
				if(flag1&&!ty1.empty()){
					if(ty1.front()==x)ty1.pop();
					else flag1=0;
					}
				else flag1=0;
				}
			}
		int sum=flag1+flag2+flag3;
		if(sum>=2)printf("not sure\n");
		else if(sum==0)printf("impossible\n");
		else if(flag1)printf("queue\n");
		else if(flag2)printf("priority queue\n");
		else printf("stack\n"); 
		}
	return 0;
	}
Exemple #14
0
		bool try_pop(T &value)
		{
			std::lock_guard<std::mutex> lk(mut);
			if(data_queue.empty())
				return false;
			value = std::move(data_queue.front());
			data_queue.pop();
			return true;
		}
Exemple #15
0
		std::shared_ptr<T> try_pop() 
		{
			std::lock_guard<std::mutex> lk(mut);
			if(data_queue.empty())
				return std::shared_ptr<T> ();
			std::shared_ptr<T> res(std::make_shared<T>(std::move(data_queue.front())));
			data_queue.pop();
			return res;
		}
//This will return true if there is a nextJob, and uses the first parameter
// called job to store the job in for use.
bool ThreadSafeQ::getNextJob(int& job){
	std::lock_guard<std::mutex> lock(mutex);
	if (!q.empty()){
		job = q.front();
		q.pop();
		return true;
	}
	return false;
}
Exemple #17
0
    void workerThread()
    {
        while (d_keepWorkerRunning)
        {
            unique_lock<mutex> g(d_jobQueueMutex);

            while (d_jobQueue.empty()) { d_hasJob.wait(g); }

            Job job = d_jobQueue.front();
            assert(!d_jobQueue.empty());
            d_jobQueue.pop();
            
            g.release(); // <------------ PATCH
            d_jobQueueMutex.unlock();

            job();
        }
    }
Exemple #18
0
void invalidateRequests()
{
	c_wait_event("checked");
	invalidated = true;

	while (!requests.empty())
		requests.pop();
	c_publish_event("cleared");
}
Exemple #19
0
    sf::Keyboard::Key popKey() {
        assert(!keysReleased.empty() && "KeyBuffer is empty.  This function should not be called");

        sf::Keyboard::Key key = keysReleased.front();
        keysReleased.pop();

        return key;

    }
Exemple #20
0
static SpawnRequest_t *dequeue_spawn_request(void) {
    ASSERT_IS_LOCKED(s_spawn_queue_lock);
    SpawnRequest_t *result = NULL;
    if (!s_request_queue.empty()) {
        result = s_request_queue.front();
        s_request_queue.pop();
    }
    return result;
}
Exemple #21
0
int __FASTCALL__ GetEvent( void (*prompt)(),int (*alt_action)(),TWindow * win)
{
  int key;
  while(kb_queue.empty()) __GetEventQue(prompt,win);
  key = kb_queue.front();
  kb_queue.pop();
  if(key==KE_TAB && alt_action) key=(*alt_action)();
  return key;
}
 std::shared_ptr<message_base> wait_and_pop()
 {
     std::unique_lock<std::mutex> lk(m);
     // Block until queue isn't empty
     c.wait(lk,[&]{return !q.empty();});
     auto res=q.front();
     q.pop();
     return res;
 }
Exemple #23
0
 BOOLEAN try_pop ( Data& value )
 {
    boost::mutex::scoped_lock lock ( _mutex ) ;
    if ( _queue.empty () )
       return FALSE ;
    value = _queue.front () ;
    _queue.pop () ;
    return TRUE ;
 }
Exemple #24
0
DFhackCExport command_result plugin_onupdate (color_ostream &out)
{
    while (!cmds.empty())
    {
        Core::getInstance().runCommand(out, cmds.front());
        cmds.pop();
    }
    return CR_OK;
}
Exemple #25
0
void DispatchEvents() {
	lock_guard guard(mutex_);

	while (!g_dispatchQueue.empty()) {
		DispatchQueueItem item = g_dispatchQueue.back();
		g_dispatchQueue.pop();
		item.e->Dispatch(item.params);
	}
}
Exemple #26
0
 bool try_pop(T& value) {
     std::lock_guard<std::mutex> lock(m_mutex);
     if (m_queue.empty()) {
         return false;
     }
     value=std::move(m_queue.front());
     m_queue.pop();
     return true;
 }
Exemple #27
0
 std::shared_ptr<T> wait_and_pop()
 {
     std::unique_lock<std::mutex> lk(mut);
     data_cond.wait(lk, [this] {return !data_queue.empty();});
     std::shared_ptr<T> res(
         std::make_shared<T>(std::move(data_queue.front())));
     data_queue.pop();
     return res;
 }
Exemple #28
0
	// try non-blocking pop
	bool tryPop(T& value) {
		std::unique_lock<std::mutex> lock(mtx_); // GUARD
		if (queue_.empty()) {
			return false;
		}
		value = queue_.front();
		queue_.pop();
		return true;
	}
Exemple #29
0
 /// \return immediately, with true if successful retrieval
 bool try_and_pop(T& popped_item){
   std::lock_guard<std::mutex> lock(m_);
   if(queue_.empty()){
     return false;
   }
   popped_item=std::move(queue_.front());
   queue_.pop();
   return true;
 }
Exemple #30
0
	/**@brief set the value for val object, lock the class to prevent simultaneous access
	 *
	 * @param val a value to set with the next object
	 * @return whether or not there was another object to pop
	 */
	bool getVal(T & val) {
		std::lock_guard<std::mutex> lock(mut_);
		if (!vals_.empty()) {
			val = vals_.front();
			vals_.pop();
			return true;
		}
		return false;
	}