Пример #1
0
/****************************************************************//**
Inserts the trx handle in the trx system trx list in the right position.
The list is sorted on the trx id so that the biggest id is at the list
start. This function is used at the database startup to insert incomplete
transactions to the list. */
static
void
trx_list_insert_ordered(
/*====================*/
	trx_t*	trx)	/*!< in: trx handle */
{
	trx_t*	trx2;

	ut_ad(mutex_own(&kernel_mutex));

	trx2 = UT_LIST_GET_FIRST(trx_sys->trx_list);

	while (trx2 != NULL) {
		if (ut_dulint_cmp(trx->id, trx2->id) >= 0) {

			ut_ad(ut_dulint_cmp(trx->id, trx2->id) == 1);
			break;
		}
		trx2 = UT_LIST_GET_NEXT(trx_list, trx2);
	}

	if (trx2 != NULL) {
		trx2 = UT_LIST_GET_PREV(trx_list, trx2);

		if (trx2 == NULL) {
			UT_LIST_ADD_FIRST(trx_list, trx_sys->trx_list, trx);
		} else {
			UT_LIST_INSERT_AFTER(trx_list, trx_sys->trx_list,
					     trx2, trx);
		}
	} else {
		UT_LIST_ADD_LAST(trx_list, trx_sys->trx_list, trx);
	}
}
Пример #2
0
void
buf_flush_insert_sorted_into_flush_list(
/*====================================*/
	buf_block_t*	block)	/* in: block which is modified */
{
	buf_block_t*	prev_b;
	buf_block_t*	b;

	ut_ad(mutex_own(&(buf_pool->mutex)));

	prev_b = NULL;
	b = UT_LIST_GET_FIRST(buf_pool->flush_list);

	while (b && (ut_dulint_cmp(b->oldest_modification,
				   block->oldest_modification) > 0)) {
		prev_b = b;
		b = UT_LIST_GET_NEXT(flush_list, b);
	}

	if (prev_b == NULL) {
		UT_LIST_ADD_FIRST(flush_list, buf_pool->flush_list, block);
	} else {
		UT_LIST_INSERT_AFTER(flush_list, buf_pool->flush_list, prev_b,
				     block);
	}

	ut_ad(buf_flush_validate_low());
}
Пример #3
0
mem_block_t*
mem_heap_add_block(
/*===============*/
				/* out: created block, NULL if did not
				succeed */
	mem_heap_t* 	heap,	/* in: memory heap */
	ulint		n)	/* in: number of bytes user needs */
{
	mem_block_t*	block; 
	mem_block_t*	new_block; 
	ulint		new_size;

	ut_ad(mem_heap_check(heap));

	block = UT_LIST_GET_LAST(heap->base);

	/* We have to allocate a new block. The size is always at least
	doubled until the standard size is reached. After that the size
	stays the same, except in cases where the caller needs more space. */
		
	new_size = 2 * mem_block_get_len(block);

	if (heap->type != MEM_HEAP_DYNAMIC) {
		/* From the buffer pool we allocate buffer frames */
		ut_a(n <= MEM_MAX_ALLOC_IN_BUF);

		if (new_size > MEM_MAX_ALLOC_IN_BUF) {
			new_size = MEM_MAX_ALLOC_IN_BUF;
		}
	} else if (new_size > MEM_BLOCK_STANDARD_SIZE) {

		new_size = MEM_BLOCK_STANDARD_SIZE;
	}

	if (new_size < n) {
		new_size = n;
	}
	
	new_block = mem_heap_create_block(heap, new_size, NULL, heap->type,
						heap->file_name, heap->line);
	if (new_block == NULL) {

		return(NULL);
	}

	/* Add the new block as the last block */

	UT_LIST_INSERT_AFTER(list, heap->base, block, new_block);

	return(new_block);
}
Пример #4
0
void OSEventThread::addTimer(event_timer_t * ev)
{
    //event_timer_t * list;
    //if (ev->timespan > 0) {
    //    // add to timer list
    //    list = UT_LIST_GET_FIRST(mTimerList);
    //    ev->timeout = ev->timespan + OS::GetTickCount();

    //    // keep list sorted
    //    while ( (list) && (list->timeout < ev->timeout )) {
    //            list = UT_LIST_GET_NEXT(watchNode,ev);
    //        }
    //    // list now points to the first event older than ev
    //    UT_LIST_INSERT_AFTER(watchNode,mTimerList,list,ev);
    //} 

    TRACE("~~~~ +addTimer (%d) ~~~~\n",ev->timespan);
    event_timer_t * tev = UT_LIST_GET_FIRST(mTimerList);
    event_timer_t * prev;

    ev->timeout = ev->timespan + OS::GetTickCount();

    if(tev == NULL || tev->timeout > ev->timeout){
        UT_LIST_ADD_FIRST(watchNode,mTimerList,ev);
        TRACE("~~~~ -addWatch ,timeout(%d),count(%d)~~~~\n",ev->timeout,mTimerList.count);
        return;
        //return true;
    }

    do{ 
        prev  = tev;
        tev = UT_LIST_GET_NEXT(watchNode,prev);  
    }while (tev && tev->timeout < ev->timeout);

    UT_LIST_INSERT_AFTER(watchNode,mTimerList,prev,ev);
    TRACE("~~~~ -addTimer ,timeout(%d),count(%d)~~~~\n",ev->timeout,mTimerList.count);
   // return true;
    
}
Пример #5
0
bool  OSEventThread::addWatch(event_req_t * ev)
{
    TRACE("~~~~ +addWatch (%d) ~~~~\n",ev->fd);
    event_req_t * tev = UT_LIST_GET_FIRST(mWatchList);
    event_req_t * prev;

    FD_SET(ev->fd, &mReadFds);
    if (ev->fd >= mMaxfFd) mMaxfFd = ev->fd+1;

    if(tev == NULL || tev->fd > ev->fd){
        UT_LIST_ADD_FIRST(watchNode,mWatchList,ev);
        TRACE("~~~~ -addWatch ,mMaxfFd(%d),count(%d)~~~~\n",mMaxfFd,mWatchList.count);
        return true;
    }

    do{ 
        prev  = tev;
        tev = UT_LIST_GET_NEXT(watchNode,prev);  
    }while (tev && tev->fd < ev->fd);
    
    UT_LIST_INSERT_AFTER(watchNode,mWatchList,prev,ev);
    TRACE("~~~~ -addWatch ,mMaxfFd(%d),count(%d)~~~~\n",mMaxfFd,mWatchList.count);
    return true;
}
Пример #6
0
/**********************************************************************
Adds a block to the LRU list. */
UNIV_INLINE
void
buf_LRU_add_block_low(
/*==================*/
	buf_block_t*	block,	/* in: control block */
	ibool		old)	/* in: TRUE if should be put to the old blocks
				in the LRU list, else put to the start; if the
				LRU list is very short, the block is added to
				the start, regardless of this parameter */
{
	ulint	cl;

	ut_ad(buf_pool);
	ut_ad(block);
	ut_ad(mutex_own(&(buf_pool->mutex)));

	ut_a(block->state == BUF_BLOCK_FILE_PAGE);
	ut_a(!block->in_LRU_list);

	block->old = old;
	cl = buf_pool_clock_tic();

	if (srv_use_awe && block->frame) {
		/* Add to the list of mapped pages; for simplicity we always
		add to the start, even if the user would have set 'old'
		TRUE */

		UT_LIST_ADD_FIRST(awe_LRU_free_mapped,
				  buf_pool->awe_LRU_free_mapped, block);
	}

	if (!old || (UT_LIST_GET_LEN(buf_pool->LRU) < BUF_LRU_OLD_MIN_LEN)) {

		UT_LIST_ADD_FIRST(LRU, buf_pool->LRU, block);

		block->LRU_position = cl;
		block->freed_page_clock = buf_pool->freed_page_clock;
	} else {
		UT_LIST_INSERT_AFTER(LRU, buf_pool->LRU, buf_pool->LRU_old,
				     block);
		buf_pool->LRU_old_len++;

		/* We copy the LRU position field of the previous block
		to the new block */

		block->LRU_position = (buf_pool->LRU_old)->LRU_position;
	}

	block->in_LRU_list = TRUE;

	if (UT_LIST_GET_LEN(buf_pool->LRU) > BUF_LRU_OLD_MIN_LEN) {

		ut_ad(buf_pool->LRU_old);

		/* Adjust the length of the old block list if necessary */

		buf_LRU_old_adjust_len();

	} else if (UT_LIST_GET_LEN(buf_pool->LRU) == BUF_LRU_OLD_MIN_LEN) {

		/* The LRU list is now long enough for LRU_old to become
		defined: init it */

		buf_LRU_old_init();
	}
}