Exemplo n.º 1
0
int resource_list_pending_insert(Resource_list_t *rl, char *rid)
{
  int err;
  char *prid;

  apr_thread_mutex_lock(rl->lock);
  move_to_top(rl->pending);
  err = 0;
  while ((prid = get_ele_data(rl->pending)) != NULL) {
log_printf(0, "rid=%s prid=%s\n", rid, prid);
    if (strcmp(rid, prid) == 0) {
       log_printf(0, "Attempting to insert an already pending RID=%s!\n", rid);
       err = 1;
       break;
    }

    move_down(rl->pending);
  }

  if (err == 0) {  //** Safe to insert it
    push(rl->pending, rid);
  }
  apr_thread_mutex_unlock(rl->lock);

  return(err);
}
Exemplo n.º 2
0
Arquivo: gti.c Projeto: Joker-vD/gti
int main(int argc, char **argv)
{
    int i;
    char *git_path;
    (void) argc;

    open_term();
    TERM_WIDTH = term_width();
    SLEEP_DELAY = 1000000 / (TERM_WIDTH + GTI_SPEED);

    init_space();
    for (i = -20; i < TERM_WIDTH; i++) {
        draw_car(i);
        usleep(SLEEP_DELAY);
        clear_car(i);
    }
    move_to_top();
    fflush(TERM_FH);
    git_path = getenv("GIT");
    if (git_path) {
      execv(git_path, argv);
    } else {
      execvp(GIT_NAME, argv);
    }
    /* error in exec if we land here */
    perror(GIT_NAME);
    return 1;
}
Exemplo n.º 3
0
Arquivo: gti.c Projeto: rwos/gti
int main(int argc, char **argv)
{
    int i;
    char *git_path;
    char *tmp;
    unsigned int gti_speed;
    draw_fn_t draw_fn;

    tmp = getenv("GTI_SPEED");
    if (!tmp || sscanf(tmp, "%u", &gti_speed) != 1) {
        gti_speed = GTI_SPEED;
    }
    open_term();
    TERM_WIDTH = term_width();
    FRAME_TIME = 1000 * 1000 * 10 / (gti_speed + TERM_WIDTH + 1);

    draw_fn = select_command(argc, argv);
    init_space();
    for (i = -20; i < TERM_WIDTH; i++) {
        draw_fn(i);
        clear_car(i);
    }
    move_to_top();
    fflush(TERM_FH);

    git_path = getenv("GIT");
    if (git_path) {
        execv(git_path, argv);
    } else {
        execvp(GIT_NAME, argv);
    }
    /* error in exec if we land here */
    perror(GIT_NAME);
    return 1;
}
Exemplo n.º 4
0
int resource_list_pending_activate(Resource_list_t *rl, char *rid, Resource_t *r)
{
  int slot;
  char *prid;

  apr_thread_mutex_lock(rl->lock);
  move_to_top(rl->pending);
  slot = -1;
  while ((prid = get_ele_data(rl->pending)) != NULL) {
log_printf(0, "rid=%s prid=%s\n", rid, prid);
    if (strcmp(rid, prid) == 0) {
       delete_current(rl->pending, 0, 0);
       slot = _resource_list_insert(rl, r);
       break;
    }

    move_down(rl->pending);
  }
  apr_thread_mutex_unlock(rl->lock);

  if (slot == -1) {
     log_printf(0, "No pending RID matches %s\n", rid);
  }

  return(slot);
}
Exemplo n.º 5
0
void _lru_process_waiters(cache_t *c)
{
    cache_lru_t *cp = (cache_lru_t *)c->fn.priv;
    lru_page_wait_t *pw = NULL;
    cache_cond_t *cache_cond;
    ex_off_t bytes_free, bytes_needed;

    if (stack_size(cp->pending_free_tasks) > 0) {  //**Check on pending free tasks 1st
        while ((cache_cond = (cache_cond_t *)pop(cp->pending_free_tasks)) != NULL) {
            log_printf(15, "waking up pending task cache_cond=%p stack_size left=%d\n", cache_cond, stack_size(cp->pending_free_tasks));
            apr_thread_cond_signal(cache_cond->cond);    //** Wake up the paused thread
        }
//     return;
    }

    if (stack_size(cp->waiting_stack) > 0) {  //** Also handle the tasks waiting for flushes to complete
        bytes_free = _lru_max_bytes(c) - cp->bytes_used;

        move_to_top(cp->waiting_stack);
        pw = get_ele_data(cp->waiting_stack);
        bytes_needed = pw->bytes_needed;
        while ((bytes_needed <= bytes_free) && (pw != NULL)) {
            bytes_free -= bytes_needed;
            delete_current(cp->waiting_stack, 1, 0);
            log_printf(15, "waking up waiting stack pw=%d\n", pw);

            apr_thread_cond_signal(pw->cond);    //** Wake up the paused thread

            //** Get the next one if available
            pw = get_ele_data(cp->waiting_stack);
            bytes_needed = (pw == NULL) ? bytes_free + 1 : pw->bytes_needed;
        }
    }

}
Exemplo n.º 6
0
void _opque_start_execution(opque_t *que)
{
    int n, i;
    callback_t *cb;
    op_generic_t *gop;
    que_data_t *q = &(que->qd);

    gop = opque_get_gop(que);
    if (gop->base.started_execution != 0) {
        return;
    }

    gop->base.started_execution = 1;

    n = stack_size(q->list);
    move_to_top(q->list);
    for (i=0; i<n; i++) {
        cb = (callback_t *)pop(q->list);
        gop = (op_generic_t *)cb->priv;
        if (gop->type == Q_TYPE_OPERATION) {
            log_printf(15, "qid=%d gid=%d\n",gop_id(opque_get_gop(que)), gop_get_id(gop));
            gop->base.started_execution = 1;
            gop->base.pc->fn->submit(gop->base.pc->arg, gop);
        } else {  //** It's a queue
            log_printf(15, "qid=%d Q gid=%d\n",gop_id(opque_get_gop(que)), gop_get_id(gop));
            lock_opque(gop->q);
            _opque_start_execution(gop->q->opque);
            unlock_opque(gop->q);
        }
    }

//  unlock_opque(q);
}
Exemplo n.º 7
0
Arquivo: gt.c Projeto: joeledwards/gt
void clear_car(int x)
{
  int i;
  move_to_top();
  for (i = 0; i < 10; i++) {
    line_at(x, "  ");
  }
}
Exemplo n.º 8
0
Arquivo: gti.c Projeto: Joker-vD/gti
void clear_car(int x)
{
    move_to_top();
    line_at(x, "  ");
    line_at(x, "  ");
    line_at(x, "  ");
    line_at(x, "  ");
    line_at(x, "  ");
    line_at(x, "  ");
    line_at(x, "  ");
}
Exemplo n.º 9
0
void _opque_print_stack(Stack_t *stack)
{
    op_generic_t *gop;
    int i=0;

    if (log_level() <= 15) return;

    move_to_top(stack);
    while ((gop = (op_generic_t *)get_ele_data(stack)) != NULL) {
        log_printf(15, "    i=%d gid=%d type=%d\n", i, gop_id(gop), gop_get_type(gop));
        i++;
        move_down(stack);
    }

    if (stack_size(stack) != i) log_printf(0, "Stack size mismatch! stack_size=%d i=%d\n", stack_size(stack), i);
}
Exemplo n.º 10
0
Arquivo: gti.c Projeto: Joker-vD/gti
void draw_car(int x)
{
    move_to_top();
    line_at(x, "   ,---------------.");
    line_at(x, "  /  /``````|``````\\\\");
    line_at(x, " /  /_______|_______\\\\________");
    line_at(x, "|]      GTI |'       |        |]");
    if (x % 2) {
    line_at(x, "=  .-:-.    |________|  .-:-.  =");
    line_at(x, " `  -+-  --------------  -+-  '");
    line_at(x, "   '-:-'                '-:-'  ");
    } else {
    line_at(x, "=  .:-:.    |________|  .:-:.  =");
    line_at(x, " `   X   --------------   X   '");
    line_at(x, "   ':-:'                ':-:'  ");
    }
}
Exemplo n.º 11
0
Arquivo: gti.c Projeto: rwos/gti
void draw_pull(int x)
{
    /* *INDENT-OFF* */
    move_to_top();
    line_at(x, "   ,---------------.               __");
    line_at(x, "  /  /``````|``````\\\\             /--\\");
    line_at(x, " /  /_______|_______\\\\________    \\__/");
    line_at(x, "|]      GTI |'       |        |] >-||");
    if (x % 2) {
    line_at(x, "=  .-:-.    |________|  .-:-.  = >-||");
    line_at(x, " `  -+-  --------------  -+-  '    || ");
    line_at(x, "   '-:-'                '-:-'      ||  ");
    } else {
    line_at(x, "=  .:-:.    |________|  .:-:.  = >-||");
    line_at(x, " `   X   --------------   X   '   /  \\");
    line_at(x, "   ':-:'                ':-:'    /    \\");
    }
    /* *INDENT-ON* */
    usleep(FRAME_TIME * 8);
}
Exemplo n.º 12
0
Arquivo: gti.c Projeto: rwos/gti
void draw_push(int x)
{
    /* *INDENT-OFF* */
    move_to_top();
    line_at(x, "   __      ,---------------.");
    line_at(x, "  /--\\   /  /``````|``````\\\\");
    line_at(x, "  \\__/  /  /_______|_______\\\\________");
    line_at(x, "   ||-< |]      GTI |'       |        |]");
    if (x % 2) {
    line_at(x, "   ||-< =  .-:-.    |________|  .-:-.  =");
    line_at(x, "   ||    `  -+-  --------------  -+-  '");
    line_at(x, "   ||      '-:-'                '-:-'  ");
    } else {
    line_at(x, "   ||-< =  .:-:.    |________|  .:-:.  =");
    line_at(x, "   /\\    `   X   --------------   X   '");
    line_at(x, "  /  \\     ':-:'                ':-:'  ");
    }
    /* *INDENT-ON* */
    usleep(FRAME_TIME * 10);
}
Exemplo n.º 13
0
Arquivo: gti.c Projeto: rwos/gti
void draw_std(int x)
{
    /* *INDENT-OFF* */
    move_to_top();
    line_at(x, "   ,---------------.");
    line_at(x, "  /  /``````|``````\\\\");
    line_at(x, " /  /_______|_______\\\\________");
    line_at(x, "|]      GTI |'       |        |]");
    if (x % 2) {
    line_at(x, "=  .-:-.    |________|  .-:-.  =");
    line_at(x, " `  -+-  --------------  -+-  '");
    line_at(x, "   '-:-'                '-:-'  ");
    } else {
    line_at(x, "=  .:-:.    |________|  .:-:.  =");
    line_at(x, " `   X   --------------   X   '");
    line_at(x, "   ':-:'                ':-:'  ");
    }
    /* *INDENT-ON* */
    usleep(FRAME_TIME);
}
Exemplo n.º 14
0
Arquivo: gt.c Projeto: joeledwards/gt
void draw_car(int x)
{
    move_to_top();
    line_at(x, "                                       ______________                               ");
    line_at(x, "                                  _.-''         || \\ `-.                           ");
    line_at(x, "                             _.-''              ||   \\  `-._       -=====/         ");
    line_at(x, "                   _____..-''.<(]_______________||_____\\    `-------/--/.          ");
    line_at(x, "         _..---''''__      /  ``     ____________|__________.....________\\         ");
    if (x % 2) {
    line_at(x, "   _.-'''__.-.='_`_`-.\\---|---'''''''       ` `  |   __  /.-'_`_`-.\\      \\.     ");
    line_at(x, " .' --''' .'/ /  |  \\ \\`. |                     /   '='.'/ /\\ | /\\ \\`.  __.|   ");
    line_at(x, " |--------|| |``-O-''| ||--\\-------------------/-------|| |''-O-``| ||''  /        ");
    line_at(x, " '''----..| \\ \\/_ _\\/ / |______________________________| \\ \\ _|_ / / `--'\"    ");
    line_at(x, "             `-.....-'                                    `-.....-'                 ");
    } else {
    line_at(x, "   _.-'''__.-.='_`_`-.\\---|---'''''''       ` `  |   __  /.-'_`_`-.\\      \\.     ");
    line_at(x, " .' --''' .'/ /\\   /\\ \\`. |                     /   '='.'/ /  |  \\ \\`.  __.|   ");
    line_at(x, " |--------|| |''-O-``| ||--\\-------------------/-------|| |``-O-''| ||''  /        ");
    line_at(x, " '''----..| \\ \\ _|_ / / |______________________________| \\ \\/_ _\\/ / `--'\"    ");
    line_at(x, "             `-.....-'                                    `-.....-'                 ");
    }
}
Exemplo n.º 15
0
int lru_page_access(cache_t *c, cache_page_t *p, int rw_mode, ex_off_t request_len)
{
    cache_lru_t *cp = (cache_lru_t *)c->fn.priv;
    page_lru_t *lp = (page_lru_t *)p->priv;

    if (rw_mode == CACHE_FLUSH) return(0);  //** Nothing to do for a flush

    //** Only update the position if the page is linked.
    //** Otherwise the page is destined to be dropped
    if (lp->ele != NULL) {
        cache_lock(c);
        if (lp->ele != NULL) {  //** Recehck with the lock on
            move_to_ptr(cp->stack, lp->ele);
            stack_unlink_current(cp->stack, 1);
            move_to_top(cp->stack);
            insert_link_above(cp->stack, lp->ele);
        }
        cache_unlock(c);
    }

    return(0);
}
Exemplo n.º 16
0
void MRUList::add(const wchar_t *file) {
	if (!mMaxCount)
		return;

	int index;

	// Does this file already exist?  If not, move it to the top.

	for(index=0; index<mMaxCount; index++) {
		int i = mKey[index];

		if (!i)
			continue;

		i -= 'a';

		if (!_wcsicmp(mFiles[i].c_str(), file)) {
			move_to_top(index);
			return;
		}
	}

	// Add file to list
	std::rotate(mKey.begin(), mKey.end()-1, mKey.end());

	if (mKey.front()) {
		index = mKey.front() - 'a';
	} else {
		index=0;
		while(!mFiles[index].empty())
			++index;
	}

	mFiles[index] = file;
	mKey.front() = (char)(index + 'a');

	mbDirty = true;
}
Exemplo n.º 17
0
TEST(ParameterTest, MoveToTop)
{
	std::unique_ptr<turbodbc::string_description> description(new turbodbc::string_description(10));

	turbodbc_test::mock_statement statement;

	auto const buffered_rows = 100;
	turbodbc::parameter parameter(statement, parameter_index, buffered_rows, std::move(description));

	auto const row_index = 42;
	std::string const expected("hi there!");
	std::memcpy(parameter.get_buffer()[row_index].data_pointer, expected.c_str(), expected.size() + 1);
	parameter.get_buffer()[row_index].indicator = expected.size();

	move_to_top(parameter, row_index);

	auto const & buffer = parameter.get_buffer();

	std::string const top_content(buffer[0].data_pointer);
	auto const top_indicator(buffer[0].indicator);
	EXPECT_EQ(expected, top_content);
	EXPECT_EQ(expected.size(), top_indicator);
}
Exemplo n.º 18
0
/*
*  A round is defined as playing to top and then to bottom until there are no
*  more cards in the hand deck.
*/
void play_round(deck_t *handdeck, deck_t *tabledeck) {
    while (handdeck->top != NULL) {
        move_to_top(handdeck, tabledeck);
        move_to_bottom(handdeck);
    }
}
Exemplo n.º 19
0
Stack_ele_t *pop_link(Stack_t *stack) {
   move_to_top(stack);

   return(stack_unlink_current(stack, 0));
}
Exemplo n.º 20
0
static cb_ret_t
help_execute_cmd (unsigned long command)
{
    cb_ret_t ret = MSG_HANDLED;

    switch (command)
    {
    case CK_Help:
        help_help (whelp);
        break;
    case CK_Index:
        help_index (whelp);
        break;
    case CK_Back:
        help_back (whelp);
        break;
    case CK_Up:
        help_prev_link (TRUE);
        break;
    case CK_Down:
        help_next_link (TRUE);
        break;
    case CK_PageDown:
        move_forward (help_lines - 1);
        break;
    case CK_PageUp:
        move_backward (help_lines - 1);
        break;
    case CK_HalfPageDown:
        move_forward (help_lines / 2);
        break;
    case CK_HalfPageUp:
        move_backward (help_lines / 2);
        break;
    case CK_Top:
        move_to_top ();
        break;
    case CK_Bottom:
        move_to_bottom ();
        break;
    case CK_Enter:
        help_select_link ();
        break;
    case CK_LinkNext:
        help_next_link (FALSE);
        break;
    case CK_LinkPrev:
        help_prev_link (FALSE);
        break;
    case CK_NodeNext:
        help_next_node ();
        break;
    case CK_NodePrev:
        help_prev_node ();
        break;
    case CK_Quit:
        dlg_stop (whelp);
        break;
    default:
        ret = MSG_NOT_HANDLED;
    }

    return ret;
}
Exemplo n.º 21
0
Task_que_t *task_lock(Task_coord_t *tc, ibp_task_t *task, Resource_t *r, char *cid, int op, 
            int offset, int len, int tryagain, Allocation_t *a, int *lock)
{

  osd_id_t id;
  Task_que_t *tq;
  int err, i;

  *lock = TASK_LOCK_ERROR;
  if (sscanf(cid, LU, &id) == 0) {  
     return(NULL);
  }

  log_printf(10, "task_lock: Lock requested for cid=%s id=" LU " ns=%d ta=%d!\n", cid, id, task->ns->id, tryagain);        

//  lock_tc(tc);

  tq = (Task_que_t *)g_hash_table_lookup(tc->table, cid);
  if (tq == NULL) {  //** Not in the que
     if ((err = get_allocation_resource(r, id, a)) != 0) {   //** Get the allocation
        log_printf(10, "task_lock id =%s not found\n", cid);
//        unlock_tc(tc)
        return(NULL);
     }

  log_printf(10, "task_lock: cid=%s id=" LU " a->id=" LU " ns=%d ta=%d!\n", cid, id, a->id, task->ns->id, tryagain); flush_log();

     if (a->type == IBP_BYTEARRAY) {  //** Don't need to worry about serializing op
        *lock = TASK_LOCK_GRANTED;
//        unlock_tc(tc)
        return(NULL);
     }

     log_printf(10, "task_lock: Creating new task_que for id=%s! ns=%d\n", cid, task->ns->id);   flush_log();
 
     if ((tq = create_task_que()) == NULL) {      //** Get a new slice to add
        log_printf(0, "task_lock:  Error allocating new 'Task_que_t'!\n");        
//        unlock_tc(tc)  
        return(NULL);
     }

     log_printf(10, "task_lock: AFTER creatied new task_que for id=%s! ns=%d\n", cid, task->ns->id);   flush_log();

     //*** Init the new data structure ***
     tq->cid = strdup(cid);  //** Dup the CID
 tq->dummycid = strdup(cid);  //** Debugging only so REMOVE
     tq->a = *a;
     tq->r = r;

     g_hash_table_insert(tc->table, tq->cid, tq);  //**Insert it into the table
     log_printf(10, "task_lock: AFTER g_hash_table_insert  id=%s! ns=%d\n", cid, task->ns->id);   flush_log();

  }

  pthread_mutex_lock(&(tq->qlock));  //** Get the lock

  //** At this point we have a data structure that has to be managed
  if ((op == TASK_MANAGE) || (a->type == IBP_BYTEARRAY)) {  //** Don't need to worry about serializing op
     *lock = TASK_LOCK_GRANTED;
     *a = tq->a;
     pthread_mutex_unlock(&(tq->qlock)); 
//     unlock_tc(tc)
     return(NULL);
  }

  //** Anything else qoes in the queue

  debug_code(
     Stack_t *rque = tq->io_que[TASK_READ_QUE];
     Stack_t *wque = tq->io_que[TASK_WRITE_QUE];
     ibp_task_t *rt;
     ibp_task_t *wt;
     move_to_top(rque); move_to_top(wque);
     rt = (ibp_task_t *)get_ele_data(rque);
     wt = (ibp_task_t *)get_ele_data(wque);
     debug_printf(10, "task_lock:  Start of routine ");
     if (rt == NULL) { debug_printf(10, "rtask=NULL * "); } else { debug_printf(10, "rtask=%d * ", rt->ns->id); }     
     if (wt == NULL) { debug_printf(10, "wtask=NULL\n"); } else { debug_printf(10, "wtask=%d\n", wt->ns->id); }     
  )