Exemple #1
0
/**
 * Send next packet in DNS request
 *
 * @v dns		DNS request
 */
static int dns_send_packet ( struct dns_request *dns ) {
	static unsigned int qid = 0;
	size_t qlen;

	/* Increment query ID */
	dns->query.dns.id = htons ( ++qid );

	DBGC ( dns, "DNS %p sending query ID %d\n", dns, qid );

	/* Start retransmission timer */
	start_timer ( &dns->timer );

	/* Send the data */
	qlen = ( ( ( void * ) dns->qinfo ) - ( ( void * ) &dns->query )
		 + sizeof ( dns->qinfo ) );
	return xfer_deliver_raw ( &dns->socket, &dns->query, qlen );
}
void routesplinesinit (void)
{
    if (!(bs = (box *) malloc (BINC * sizeof (box)))) {
        fprintf (stderr, "cannot allocate bs\n");
        abort ();
    }
    maxbn = BINC;
    if (!(ps = (point *) malloc (PINC * sizeof (point)))) {
        fprintf (stderr, "cannot allocate ps\n");
        abort ();
    }
    maxpn = PINC;
    minbbox.LL.x = minbbox.LL.y = INT_MAX;
    minbbox.UR.x = minbbox.UR.y = INT_MIN;
    Show_boxes = FALSE;
	if (Verbose) start_timer();
}
Exemple #3
0
void xlui::line_edit::remove_selected_text() {
	_selection = false;
	xlui::string text = _text.mid(0, m_iSelectionStart);
	if(!m_iSelectionStart) {
		m_iActualCursor = 0;
	}
	if(_text.get_character_count() > m_iSelectionStart + m_iSelectionCount) {
		_text = text + _text.mid(m_iSelectionStart + m_iSelectionCount);
	} else {
		_text = text;
		m_iActualCursor = _text.get_character_count();
	}
	m_iSelectionStart = m_iSelectionCount = 0;
	stop_timer(m_iTimerId);
	m_iTimerId = start_timer(500);
	update();
}
void lifting_hopper_fn(){
    if (just_entered_state){
        // pulse_backward();
        pulse_forward();
        Serial.println("lifting_hopper_fn");
        debug_blue->led_on();
        start_timer(SERVO_TIMER, 1500);
        extend_dumper();
        times_hopper_lifted++;
    }
    check_pulse();
    // if (respond_to_key(NULL_STATE)) return; 
    // if (respond_to_timer_and_dumper_finished(SERVO_TIMER, LOWERING_HOPPER)) return;
    // if (respond_to_dumper_finished(LOWERING_HOPPER)) return; 
    if (respond_to_timer(SERVO_TIMER, LOWERING_HOPPER)) return; 
    // if (respond_to_timer(SERVO_TIMER, LIFTING_HOPPER)) return; 
}
Exemple #5
0
void twine_exit() {
    // get the current thread, set current to the next one
    twine_thread *old;
    old = current;
    current = current->next;

    // free our allocated space - frees the stack too?
    free(old);
    if (current == NULL) exit(0);

    start_timer();   
    // set the context to the next thread
    // no need to get or swap contexts because we're exiting
    // this thread
    int ret = setcontext(&current->ctx);
    if (ret == -1) die("twine_exit: setcontext()");
}
Exemple #6
0
int k_get_process_priority(int pid){
	int time;
	PCB *p = get_process(pid, gp_pcbs);
	#ifdef TIMING
	start_timer();
	#endif
	#ifdef DEBUG_0 
	printf("getting priority for process %d\n", p->m_pid);
	#endif /* ! DEBUG_0 */
	if (p == NULL) {
		return -1;
	}
	#ifdef TIMING
	time = end_timer();
	#endif
	return p->m_priority;
}
Exemple #7
0
void heartbeat_timer(void)
{
	gd_addr			*addr_ptr;
	gd_region		*r_top, *r_save, *r_local;
	sgmnt_addrs		*csa;
	jnl_private_control	*jpc;
	int			rc;

	/* It will take heartbeat_counter about 1014 years to overflow. */
	heartbeat_counter++;
	/* Check every 1 minute if we have an older generation journal file open. If so, close it.
	 * The only exceptions are
	 *	a) The source server can have older generations open and they should not be closed.
	 *	b) If we are in the process of switching to a new journal file while we get interrupted
	 *		by the heartbeat timer, we should not close the older generation journal file
	 *		as it will anyways be closed by the mainline code. But identifying that we are in
	 *		the midst of a journal file switch is tricky so we check if the process is in
	 *		crit for this region and if so we skip the close this time and wait for the next heartbeat.
	 */
	if ((INTRPT_OK_TO_INTERRUPT == intrpt_ok_state) && !is_src_server
		&& (0 == heartbeat_counter % NUM_HEARTBEATS_FOR_OLDERJNL_CHECK))
	{
		for (addr_ptr = get_next_gdr(NULL); addr_ptr; addr_ptr = get_next_gdr(addr_ptr))
		{
			for (r_local = addr_ptr->regions, r_top = r_local + addr_ptr->n_regions; r_local < r_top; r_local++)
			{
				if (!r_local->open || r_local->was_open)
					continue;
				if ((dba_bg != r_local->dyn.addr->acc_meth) && (dba_mm != r_local->dyn.addr->acc_meth))
					continue;
				csa = &FILE_INFO(r_local)->s_addrs;
				if (csa->now_crit)
					continue;
				jpc = csa->jnl;
				if ((NULL != jpc) && (NOJNL != jpc->channel) && JNL_FILE_SWITCHED(jpc))
				{	/* The journal file we have as open is not the latest generation journal file. Close it */
					/* Assert that we never have an active write on a previous generation journal file. */
					assert(process_id != jpc->jnl_buff->io_in_prog_latch.u.parts.latch_pid);
					JNL_FD_CLOSE(jpc->channel, rc);	/* sets jpc->channel to NOJNL */
					jpc->pini_addr = 0;
				}
			}
		}
	}
	start_timer((TID)heartbeat_timer, HEARTBEAT_INTERVAL, heartbeat_timer, 0, NULL);
}
// figure out how to make these into substates or something...
void correcting_rotation_2_fn(){
    if (just_entered_state){
        start_state_init_timer(400);
        debug_green->led_on();
    }
    if (state_init_timer_finished()){
        rotate_left(8);
        state_init_finished = true;
        start_timer(MAIN_STATE_TIMER, 60);
        debug_green->led_off();
        debug_red->led_off();
    }
    if (state_init_finished){
        // if (respond_to_timer(MAIN_STATE_TIMER, MOVING_FW_TO_ALIGN_WITH_SERVER)) return;
        if (respond_to_timer(MAIN_STATE_TIMER, MOVE_TOWARDS_SERVER)) return;
    }
}
void retracting_button_presser_fn(){
    if (just_entered_state){
        Serial.println("retracting_button_presser_fn");
        //move servo back a bit
        debug_blue->led_on();
        retract_button_presser();
        start_timer(SERVO_TIMER, BUTTON_PRESSER_DELAY);
    }
    // if (respond_to_enough_presses(3,STRAIGHT_BACK_TO_DEPO)) return;
    unsigned char coins_to_get = coins_for_exchanges[coin_collection_round];
    if (respond_to_enough_presses(coins_to_get,WAIT_FOR_LAST_COIN)) return;
    if (respond_to_key(RETRACTING_BUTTON_PRESSER)) return;
    if (respond_to_timer(SERVO_TIMER, EXTENDING_BUTTON_PRESSER)) return;
    // if (respond_to_timer(SERVO_TIMER, NULL_STATE)) return;
    // if (respond_to_timer(SERVO_TIMER, RETRACTING_BUTTON_PRESSER)) return;
    // if (respond_to_button_presser_finished(EXTENDING_BUTTON_PRESSER)) return;
}
Exemple #10
0
/**
 * ソケット送信
 *
 * @param[in] sock ソケット
 * @return ステータス
 */
static st_client
send_sock(int sock)
{
    int retval = 0;    /* 戻り値 */
    size_t length = 0; /* 長さ */
    ssize_t slen = 0;  /* 送信するバイト数 */

    expr = _readline(stdin);
    if (!expr)
        return EX_ALLOC_ERR;

    if (*expr == '\0') { /* 文字列長ゼロ */
        memfree((void **)&expr, NULL);
        return EX_EMPTY;
    }

    if (!strcmp((char *)expr, "quit") ||
        !strcmp((char *)expr, "exit"))
        return EX_QUIT;

    length = strlen((char *)expr) + 1;
    dbgdump(expr, length, "stdin: expr=%zu", length);

    if (g_tflag)
        start_timer(&start_time);

    /* データ設定 */
    slen = set_client_data(&sdata, expr, length);
    if (slen < 0) /* メモリ確保できない */
        return EX_ALLOC_ERR;
    dbglog("slen=%zd", slen);

    if (g_gflag)
        outdump(sdata, slen, "send: sdata=%p, length=%zd", sdata, slen);
    stddump(sdata, slen, "send: sdata=%p, length=%zd", sdata, slen);

    /* データ送信 */
    retval = send_data(sock, sdata, (size_t *)&slen);
    if (retval < 0) /* エラー */
        return EX_SEND_ERR;

    memfree((void **)&expr, (void **)&sdata, NULL);

    return EX_SUCCESS;
}
Exemple #11
0
/*
 * Start a corpse decay or revive timer.
 * This takes the age of the corpse into consideration as of 3.4.0.
 */
void start_corpse_timeout(struct obj *body)
{
	long when; 		/* rot away when this old */
	long corpse_age;	/* age of corpse          */
	int rot_adjust;
	short action;

#define TAINT_AGE (50L)		/* age when corpses go bad */
#define TROLL_REVIVE_CHANCE 37	/* 1/37 chance for 50 turns ~ 75% chance */
#define ROT_AGE (250L)		/* age when corpses rot away */

	/* lizards and lichen don't rot or revive */
	if (body->corpsenm == PM_LIZARD || body->corpsenm == PM_LICHEN) return;

	action = ROT_CORPSE;		/* default action: rot away */
	rot_adjust = in_mklev ? 25 : 10;	/* give some variation */
	corpse_age = moves - body->age;
	if (corpse_age > ROT_AGE)
		when = rot_adjust;
	else
		when = ROT_AGE - corpse_age;
	when += (long)(rnz(rot_adjust) - rot_adjust);

	if (is_rider(&mons[body->corpsenm])) {
		/*
		 * Riders always revive.  They have a 1/3 chance per turn
		 * of reviving after 12 turns.  Always revive by 500.
		 */
		action = REVIVE_MON;
		for (when = 12L; when < 500L; when++)
		    if (!rn2(3)) break;

	} else if (mons[body->corpsenm].mlet == S_TROLL && !body->norevive) {
		long age;
		for (age = 2; age <= TAINT_AGE; age++)
		    if (!rn2(TROLL_REVIVE_CHANCE)) {	/* troll revives */
			action = REVIVE_MON;
			when = age;
			break;
		    }
	}
	
	if (body->norevive) body->norevive = 0;
	start_timer(body->olev, when, TIMER_OBJECT, action, body);
}
Exemple #12
0
// Sends an update request to MariaDB
// @param dbname the name of the database
// @param query the query to send
// @param count the number of affected rows
// @return the time it took
static uint64_t run_maria_update(char *dbname, char *query, uint64_t *count) {
    
    struct timespec start;          // The time structure
    uint64_t time;                  // The elapsed time
    
    MYSQL *con = mysql_init(NULL);  // Mariadb connection
    
    // Make sure we can connect
    if (con == NULL) {
        
        fprintf(stderr, "%s\n", mysql_error(con));
        exit(1);
        
    } //end if
    
    // Try to connect to a database
    if (mysql_real_connect(con, "localhost", "root", "proxymine", dbname, 0,
                           "/run/shm/mysqld.sock", 0) == NULL) {
        
        fprintf(stderr, "%s\n", mysql_error(con));
        mysql_close(con);
        exit(1);
        
    } //end if
    
    start_timer(&start);
    
    // Try to update the table
    if (mysql_real_query(con, query, strlen(query))) {
        
        fprintf(stderr, "%s\n", mysql_error(con));
        mysql_close(con);
        exit(1);
        
    } //end if
    
    time = stop_timer(start);
    
    *count = mysql_affected_rows(con);
    
    mysql_close(con);
    
    return time / (CLOCKS_PER_SEC / 1000);
    
} //end run_maria_updates
Exemple #13
0
void process_siren(void)
{
	static uint16_t timer_id = 0;
	static uint8_t step = 0;
	
	uint8_t mode;
	
	mode = GET_SIREN_MODE;
	
	if (0 == mode)
	{
		if (timer_id)
			stop_timer(timer_id);
			
		timer_id = 0;
		step = 0;
		CONTROL_OFF(CONTROL_SIREN);
		CONTROL_OFF(LAMP_RED);
	}
	else
	{
		CONTROL_ON(LAMP_RED);
		
		if (0 == timer_id)
		{
			timer_id = start_timer(siren_program[mode - 1][step]);

			if (step & 0x01)
				CONTROL_OFF(CONTROL_SIREN);
			else
				CONTROL_ON(CONTROL_SIREN);
		}
		else
			if (!timer_value(timer_id))
			{
				stop_timer(timer_id);
				timer_id = 0;
				
				step++;
				if (step > siren_step_count[mode - 1])
					step = 0;
					
			}
	}	
}
Exemple #14
0
// seg001:0004
int __pascal far proc_cutscene_frame(int wait_frames) {
	cutscene_wait_frames = wait_frames;
	do {
		start_timer(timer_0, cutscene_frame_time);
		play_both_seq();
		draw_proom_drects(); // changed order of drects and flash
		if (flash_time) {
			do_flash(flash_color);
		}
		if (flash_time) {
			--flash_time;
			remove_flash();
		}
		if (!check_sound_playing()) {
			play_next_sound();
		}
		do {
			if (!disable_keys && do_paused()) {
				stop_sounds();
				draw_rect(&screen_rect, 0);
#ifdef USE_FADE
				if (is_global_fading) {
					fade_palette_buffer->proc_restore_free(fade_palette_buffer);
					is_global_fading = 0;
				}
#endif
				return 1;
			}
#ifdef USE_FADE
			if (is_global_fading) {
				if (fade_palette_buffer->proc_fade_frame(fade_palette_buffer)) {
					fade_palette_buffer->proc_restore_free(fade_palette_buffer);
					is_global_fading = 0;
					return 2;
				}
			} else {
				idle();
			}
#else
			idle();
#endif
		} while(!has_timer_stopped(0)); // busy waiting?
	} while(--cutscene_wait_frames);
	return 0;
}
Exemple #15
0
/* Times a search for each element in |array[]| having |n| elements such that
   |array[i] == i|, repeated |n_iter| times, using function |f->search|. */
static void
time_successful_search (struct search_func *f, int array[], int n, int n_iter)
{
  clock_t timer;

  printf ("Timing %d sets of successful searches...  ", n_iter);
  fflush (stdout);

  start_timer (&timer);
  while (n_iter-- > 0)
    {
      int i;

      for (i = 0; i < n; i++)
        f->search (array, n, i);
    }
  stop_timer (timer);
}
Exemple #16
0
static void signal_interval_alarm(void)
{
  if (profile_on) {
    word *current_thread = suspend_current_thread();
    time_profile_scan((struct stack_frame *)
		      reconstruct_thread_sp(current_thread));
    resume_current_thread(current_thread);
  }

  if (thread_preemption_on) {
    thread_preemption_pending = 1;
    record_event(EV_SWITCH, (word)0);
  }

  signal_update_windows (timer_interval);

  start_timer(timer_interval);
}
void extending_button_presser_fn(){
    if (just_entered_state){
        Serial.println("extending_button_presser_fn");
        extend_button_presser();
        debug_green->led_on();
        start_timer(SERVO_TIMER, BUTTON_PRESSER_DELAY);

        pulse_forward();
        // set servo timer
    }
    check_pulse();

    // reenter the state and reincrement the servo
    if (respond_to_key(EXTENDING_BUTTON_PRESSER)) return;
    if (respond_to_timer(SERVO_TIMER, RETRACTING_BUTTON_PRESSER)) return; // uhh...
    // if (respond_to_timer(SERVO_TIMER, EXTENDING_BUTTON_PRESSER)) return; 
    // if (respond_to_button_presser_finished(RETRACTING_BUTTON_PRESSER)) return;
}
int process_ms_ack_reply(
        lispd_referral_cache_entry              *referral_entry,
        lispd_pending_referral_cache_entry      *pending_referral_entry)
{
    lispd_referral_cache_entry              *db_referral_entry = NULL;

    db_referral_entry = lookup_referral_cache_exact(
            referral_entry->mapping->eid_prefix, referral_entry->mapping->eid_prefix_length, DDT_END_PREFIX_DATABASES);

    /* Add referral cache entry to database */
    if (db_referral_entry == NULL){
        if (add_referral_cache_entry_to_db(referral_entry) != GOOD){
            lispd_log_msg(LISP_LOG_DEBUG_1,"process_ms_ack_reply: Coudn't add referral cache entry for prefix %s/%d",
                    get_char_from_lisp_addr_t(referral_entry->mapping->eid_prefix), referral_entry->mapping->eid_prefix_length);
            free_referral_cache_entry(referral_entry);
            remove_pending_referral_cache_entry_from_list(pending_referral_entry);
            return (BAD);
        }
        add_referral_cache_entry_to_tree(pending_referral_entry->previous_referral,referral_entry);
    }else{
        /* Entry already exist. Replace it with the new data. Valid if the previous entry was a ms ack or ms not registered ack */
        update_referral_cache_data(db_referral_entry, referral_entry);
        free_referral_cache_entry(referral_entry);
        referral_entry = db_referral_entry;
    }

    /* Program expiry time */
    program_referral_expiry_timer(referral_entry);
    /* Finish process and remove the pending referral cache from the list */
    if (pending_referral_entry->map_cache_entry->active == TRUE){
        // We have received a map reply
        remove_pending_referral_cache_entry_from_list(pending_referral_entry);
    }
    else{
        if (pending_referral_entry->ddt_request_retry_timer == NULL){
            pending_referral_entry->ddt_request_retry_timer = create_timer (DDT_MAP_REQ_RETRY_MS_ACK_TIMER);
        }
        pending_referral_entry->previous_referral = referral_entry;
        start_timer(pending_referral_entry->ddt_request_retry_timer, LISPD_INITIAL_MRQ_TIMEOUT,
                send_map_request_ddt_map_reply_miss, (void *)pending_referral_entry);
    }

    return (GOOD);
}
Exemple #19
0
void xlui::line_edit::mouse_move_event(xlui::mouse_move_event &event) {
	_selection = true;

	xlui::position pos = event.get_position();
//	xlui::string_dimension dim(_font, this);
	xlui::font_metric dim(_font);
	int32_t count = 0;
	xlui::string text = _text;
	int32_t width = dim.get_width(text);

	int32_t cursor = event.get_position().get_x();
	if(cursor < 0) {
		cursor = 0;
	}
	do {
		width = dim.get_width(text);
		count = text.get_character_count();
		text = text.mid(0, count - 1);
		count = text.get_character_count();
	} while(cursor <= width && count > 0);

	if(cursor < width) {
		cursor = 0;
	} else {
		++count;
	}

	m_iSelectionStart = count < m_iActualCursor ? count : m_iActualCursor;
	m_iSelectionCount = count < m_iActualCursor ? m_iActualCursor - count : count - m_iActualCursor;
	if(!m_iSelectionCount) {
		_selection = false;
	}

	text = _text.mid(0, count);

//	xlui::string_dimension sel(_font, this);
	xlui::font_metric sel(_font);
	m_SelectionEnd.set_x(sel.get_width(text));
	m_SelectionEnd.set_y(event.get_position().get_y());

	stop_timer(m_iTimerId);
	m_iTimerId = start_timer(500);
	update();
}
Exemple #20
0
    virtual void on_mouse_button_down(int x, int y, unsigned flags)
    {
        unsigned i;
        if(flags & agg::mouse_right)
        {
            agg::scanline_u8 sl;
            agg::rasterizer_scanline_aa<> ras;
            start_timer();
            for(i = 0; i < 100; i++)
            {
                render_gouraud(sl, ras);
            }
            char buf[100];
            sprintf(buf, "Time=%2.2f ms", elapsed_time());
            message(buf);
        }

        if(flags & agg::mouse_left)
        {
            for (i = 0; i < 3; i++)
            {
                if(sqrt( (x-m_x[i]) * (x-m_x[i]) + (y-m_y[i]) * (y-m_y[i]) ) < 10.0)
                {
                    m_dx = x - m_x[i];
                    m_dy = y - m_y[i];
                    m_idx = i;
                    break;
                }
            }
            if(i == 3)
            {
                if(agg::point_in_triangle(m_x[0], m_y[0], 
                                          m_x[1], m_y[1],
                                          m_x[2], m_y[2],
                                          x, y))
                {
                    m_dx = x - m_x[0];
                    m_dy = y - m_y[0];
                    m_idx = 3;
                }

            }
        }
    }
Exemple #21
0
void
textclient_reshape (text_data *d,
                    int pix_w, int pix_h,
                    int char_w, int char_h,
                    int max_lines)
{
# if defined(HAVE_FORKPTY) && defined(TIOCSWINSZ)

  d->pix_w  = pix_w;
  d->pix_h  = pix_h;
  d->char_w = char_w;
  d->char_h = char_h;
  d->max_lines = max_lines;

# ifdef DEBUG
  fprintf (stderr, "%s: textclient: reshape: %dx%d, %dx%d\n", progname,
           pix_w, pix_h, char_w, char_h);
# endif

  if (d->pid && d->pipe)
    {
      /* Tell the sub-process that the screen size has changed. */
      struct winsize ws;
      ws.ws_col = char_w;
      ws.ws_row = char_h;
      ws.ws_xpixel = pix_w;
      ws.ws_ypixel = pix_h;
      ioctl (fileno (d->pipe), TIOCSWINSZ, &ws);
      kill (d->pid, SIGWINCH);
    }
# endif /* HAVE_FORKPTY && TIOCSWINSZ */


  /* If we're running xscreensaver-text, then kill and restart it any
     time the window is resized so that it gets an updated --cols arg
     right away.  But if we're running something else, leave it alone.
   */
  if (!strcmp (d->program, "xscreensaver-text"))
    {
      close_pipe (d);
      d->input_available_p = False;
      start_timer (d);
    }
}
Exemple #22
0
int main(int argc, char *argv[]) {

	// init cloud

	cloud_init();

	// create timer

	p_tm = create_timer(2, hello, 0);
	assert(p_tm);

	start_timer(p_tm);

	//  run cloud

	cloud_run(0);

	return 0;
}
Exemple #23
0
/* Returns sx|sy|dx|dy in an integer byte-by-byte from least to most
 * significant, indicating which move should be made next.
 *
 * We seperate the initial iteration of negamax out like this to track the
 * actual move associated with the best score. Doing so during the
 * deeper iterations is a waste of time. */
unsigned int calculate_move(struct chessboard *c, int color, int depth)
{
	struct move_list *l;
	int n, fbsx = -1, fbsy = -1, fbdx = -1, fbdy = -1;
	int val, best_val = INT_MIN, alpha = INT_MIN, beta = INT_MAX;
	struct raw_move m;
	struct timespec *t;

	expanded_moves = 0;
	evaluated_moves = 0;

	t = start_timer();
	l = allocate_move_list();
	for (int i = 0; i < 16; i++) {
		n = enumerate_moves(c, (color << 4) | i, l);
		expanded_moves += n;

		for (int j = 0; j < n; j++) {
			get_move(l, j, &m.sx, &m.sy, &m.dx, &m.dy);
			execute_raw_move(c, &m);
			evaluated_moves++;

			val = -negamax_algo(c, !color, depth - 1, -beta, -alpha);

			alpha = max(alpha, val);
			if (val > best_val) {
				best_val = val;
				fbsx = m.sx;
				fbsy = m.sy;
				fbdx = m.dx;
				fbdy = m.dy;
			}

			debug("Move %d/%d for piece %d (%d,%d) => (%d,%d) has heuristic value %d\n", j + 1, n, (color << 4) | i, m.sx, m.sy, m.dx, m.dy, val);
			unwind_raw_move(c, &m);
		}
	}
	free_move_list(l);
	expanded_moves += n;
	debug("Evaluated %luM/%luM expanded moves in %lu seconds\n", evaluated_moves / 1000000, expanded_moves / 1000000, get_timer_and_free(t) / 1000);

	return (fbsx) | (fbsy << 8) | (fbdx << 16) | (fbdy << 24);
}
Exemple #24
0
rt_public void send_rqst_0 (long int code)
{
	Request rqst;

#ifdef USE_ADD_LOG
    add_log(100, "sending request 0: %ld from ec", code);
#endif

#ifdef EIF_WINDOWS
	if (code == APPLICATION || code == ATTACH) {
		start_timer();
	}
#endif

	Request_Clean (rqst);
	rqst.rq_type = (int) code;

	ewb_send_packet(ewb_sp, &rqst);
}
LEMON_UNITTEST_CASE(RunQUnittest,TimeoutJobTest)
{
    runQ_service Q;

    for(size_t i = 0; i < 1; ++ i)
    {
        TimeoutJob::create(Q);

        Q.run();

        Q.reset();

        start_timer(Q,TimeoutJob1::create(Q),100);

        Q.run();

        Q.reset();
    }
}
Exemple #26
0
/* 
 * All transmissions are handled here to ensure that the receive timer 
 * is always started immediately after a packet is transmitted.
 */
static int send_packet_real(const void *packet, size_t len, int use_timer) {
	int ret_val = 0;

	if(pcap_inject(get_handle(), packet, len) == len)
	{
		ret_val = 1;
	}

	if (use_timer) {
		if(len < sizeof last_packet) {
			memcpy(last_packet, packet, len);
			last_len = len;
		}
		start_timer();
	}

	return ret_val;

}
static void
oss_do_timing (unsigned char *ev)
{
  unsigned int parm = *(unsigned int *) &ev[4];
  midi_packet_header_t hdr;

  oss_midi_time_t tick;

  _dump_midi ();

  switch (ev[1])
    {
    case TMR_TEMPO:
#ifndef DEBUG
      if (!timer_started)
	start_timer ();
      hdr.magic = MIDI_HDR_MAGIC;
      hdr.event_type = MIDI_EV_TEMPO;
      hdr.options = MIDI_OPT_TIMED;
      hdr.time = current_tick;
      hdr.parm = parm;
      if (_write (__seqfd, &hdr, sizeof (hdr)) != sizeof (hdr))
	{
	  perror ("Write tempo");
	  exit (-1);
	}
#endif
      break;

    case TMR_WAIT_REL:
      tick = current_tick + parm;

      current_tick = tick;
      break;

    case TMR_WAIT_ABS:
      tick = parm;
      current_tick = tick;
      break;
    }

}
Exemple #28
0
void radio_sb_init (const uint8_t *address, hal_nrf_operation_mode_t operational_mode)
{
  hal_nrf_close_pipe(HAL_NRF_ALL);               // First close all radio pipes
                                                 // Pipe 0 and 1 open by default
  hal_nrf_open_pipe(HAL_NRF_PIPE0, false);       // Open pipe0, without/autoack

  hal_nrf_set_crc_mode(HAL_NRF_CRC_16BIT);       // Operates in 16bits CRC mode
  hal_nrf_set_auto_retr(0, RF_RETRANS_DELAY);    // Disables auto retransmit

  hal_nrf_set_address_width(HAL_NRF_AW_5BYTES);  // 5 bytes address width
  hal_nrf_set_address(HAL_NRF_TX, address);      // Set device's addresses
  hal_nrf_set_address(HAL_NRF_PIPE0, address);   // Sets recieving address on 
                                                 // pipe0  
  
  if(operational_mode == HAL_NRF_PTX)            // Mode depentant settings
  {
    hal_nrf_set_operation_mode(HAL_NRF_PTX);     // Enter TX mode
  }
  else
  {
    hal_nrf_set_operation_mode(HAL_NRF_PRX);     // Enter RX mode
    hal_nrf_set_rx_pload_width((uint8_t)HAL_NRF_PIPE0, RF_PAYLOAD_LENGTH);
                                                 // Pipe0 expect 
                                                 // PAYLOAD_LENGTH byte payload
                                                 // PAYLOAD_LENGTH in radio.h
  }

  hal_nrf_set_rf_channel(RF_CHANNEL);            // Operating on static channel 
                                                 // Defined in radio.h. 
                                                 // Frequenzy = 
                                                 //        2400 + RF_CHANNEL
  hal_nrf_set_power_mode(HAL_NRF_PWR_UP);        // Power up device

//hal_nrf_set_datarate(HAL_NRF_1MBPS);           // Uncomment this line for 
                                                 // compatibility with nRF2401 
                                                 // and nRF24E1

  start_timer(RF_POWER_UP_DELAY);                // Wait for the radio to 
  wait_for_timer();                              // power up

  radio_set_status (RF_IDLE);                    // Radio now ready
}                                                
Exemple #29
0
static void
bench_s2k (unsigned long s2kcount)
{
  gpg_error_t err;
  const char passphrase[] = "123456789abcdef0";
  char keybuf[128/8];
  unsigned int repetitions = 10;
  unsigned int count;
  const char *elapsed;
  int pass = 0;

 again:
  start_timer ();
  for (count = 0; count < repetitions; count++)
    {
      err = gcry_kdf_derive (passphrase, strlen (passphrase),
                             GCRY_KDF_ITERSALTED_S2K,
                             GCRY_MD_SHA1, "saltsalt", 8, s2kcount,
                             sizeof keybuf, keybuf);
      if (err)
        die ("gcry_kdf_derive failed: %s\n", gpg_strerror (err));
      dummy_consumer (keybuf, sizeof keybuf);
    }
  stop_timer ();

  elapsed = elapsed_time (repetitions);
  if (!pass++)
    {
      if (!atoi (elapsed))
        {
          repetitions = 10000;
          goto again;
        }
      else if (atoi (elapsed) < 10)
        {
          repetitions = 100;
          goto again;
        }
    }

  printf ("%s\n", elapsed);
}
Exemple #30
0
/*
 *	init_timers initializes all non-thread timers and puts the
 *	service routine on the callout queue.  All timers must be
 *	serviced by the callout routine once an hour.
 */
void
init_timers(void)
{
	register int	i;
	register timer_t	this_timer;

	/*
	 *	Initialize all the kernel timers and start the one
	 *	for this cpu (master) slaves start theirs later.
	 */
	this_timer = &kernel_timer[0];
	for ( i=0 ; i<NCPUS ; i++, this_timer++) {
		timer_init(this_timer);
		current_timer[i] = (timer_t) 0;
	}

	mp_disable_preemption();
	start_timer(&kernel_timer[cpu_number()]);
	mp_enable_preemption();
}