void synchronized_await(Mutex& mtx, CondVar& cv) {
     CPPA_REQUIRE(!closed());
     if (try_block()) {
         std::unique_lock<Mutex> guard(mtx);
         while (blocked()) cv.wait(guard);
     }
 }
Exemple #2
0
void save_blocker::on_unblock(play_controller* controller, void (play_controller::*callback)()) {
	if(try_block()) {
		unblock();
		(controller->*callback)();
	} else {
		controller_ = controller;
		callback_ = callback;
	}
}
 void synchronized_await(Mutex& mtx, CondVar& cv) {
   CAF_ASSERT(! closed());
   if (! can_fetch_more() && try_block()) {
     std::unique_lock<Mutex> guard(mtx);
     while (blocked()) {
       cv.wait(guard);
     }
   }
 }
 bool synchronized_await(Mutex& mtx, CondVar& cv, const TimePoint& timeout) {
   CAF_ASSERT(!closed());
   if (try_block()) {
     std::unique_lock<Mutex> guard(mtx);
     while (blocked()) {
       if (cv.wait_until(guard, timeout) == std::cv_status::timeout) {
         // if we're unable to set the queue from blocked to empty,
         // than there's a new element in the list
         return !try_unblock();
       }
     }
   }
   return true;
 }
Exemple #5
0
void *block_pool_alloc_align(struct block_pool *bp, size_t size, size_t align) {
	void *ret;
	
	if (align)
		align--;
	
	//if there aren't any blocks, make a new one
	if (!bp->count) {
		bp->count = 1;
		return new_block_tiny(bp->block, size);
	}
	
	//try the root block
	ret = try_block(bp->block, size, align);
	if (ret)
		return ret;
	
	//root block is filled, percolate down and try the biggest one
	percolate_down(bp, 0);
	ret = try_block(bp->block, size, align);
	if (ret)
		return ret;
	
	//the biggest wasn't big enough; we need a new block
	if (bp->count >= bp->alloc) {
		//make room for another block
		bp->alloc += bp->alloc;
		bp->alloc++;
		bp->block = realloc(bp->block, bp->alloc * sizeof(struct block));
	}
	ret = new_block(bp->block+(bp->count++), size);
	
	//fix the heap after adding the new block
	percolate_up(bp, bp->count-1);
	
	return ret;
}