コード例 #1
0
ファイル: perft.cpp プロジェクト: stevemaughan/maverick
t_nodes perft(struct t_board *board, int depth) {

    struct t_move_list move_list[1];
    struct t_undo undo[1];

    t_nodes total_nodes = 0;
    t_nodes move_nodes = 0;

    unsigned long start = time_now();

    int i;

    if (board->in_check)
        generate_evade_check(board, move_list);
    else
        generate_moves(board, move_list);

    for (i = move_list->count - 1; i >= 0; i--) {
        if (make_move(board, move_list->pinned_pieces, move_list->move[i], undo)) {
            move_nodes = 0;
            if (depth > 1)
                move_nodes += do_perft(board, depth - 1);
            printf(move_as_str(move_list->move[i]));
            printf(" = %u\n", move_nodes);
            unmake_move(board, undo);
            total_nodes += move_nodes;
        }
    }

    unsigned long finish = time_now();

    if (finish == start)
        printf("Total Nodes: %I64d\n", total_nodes);
    else
        printf("Total Nodes: %I64d in %d milliseconds = nps %I64d\n", total_nodes, finish - start, 1000 * total_nodes / (finish - start));

    return total_nodes;
}
コード例 #2
0
ファイル: group_node.cpp プロジェクト: mikegulf/quickmsg
  void
  GroupNodeImpl::handle_whisper(const std::string& uuid, zmsg_t* zmsg)
  {    
    MessagePtr msg(new Message);
    msg->header.stamp = time_now();
    msg->header.context = uuid;
    msg->header.src_uuid = uuid;
    char* a_str = zmsg_popstr(zmsg);
    msg->msg = a_str;
    free(a_str);
    auto range = whisper_handlers_.equal_range("w");
    std::for_each(range.first, range.second,
		  [&](handlers_t::value_type& c){c.second.first(msg.get(), c.second.second);});
  }
コード例 #3
0
ファイル: ip_voter.cpp プロジェクト: EricMyers47/OpenSpace
	// returns true if our external IP changed
	bool ip_voter::maybe_rotate()
	{
		ptime now = time_now();

		// if we have more than or equal to 50 votes,
		// we rotate. Also, if it's been more than 5 minutes
		// and we have at least one vote, we also rotate.
		// this is the inverse condition, since this is the case
		// were we exit, without rotating
		if (m_total_votes < 50
			&& (now - m_last_rotate < minutes(5) || m_total_votes == 0)
			&& m_valid_external)
			return false;

		// this shouldn't really happen if we have at least one
		// vote.
		if (m_external_addresses.empty()) return false;

		// if there's just one vote, go with that
		std::vector<external_ip_t>::iterator i;
		if (m_external_addresses.size() == 1)
		{
			// avoid flapping. We need more votes to change our mind on the
			// external IP
			if (m_external_addresses[0].num_votes < 2) return false;
		}
		else
		{
			// find the top two votes.
			std::partial_sort(m_external_addresses.begin()
				, m_external_addresses.begin() + 2, m_external_addresses.end());

			// if we don't have enough of a majority voting for the winning
			// IP, don't rotate. This avoids flapping
			if (m_external_addresses[0].num_votes * 2 / 3 <= m_external_addresses[1].num_votes)
				return false;
		}

		i = m_external_addresses.begin();

		bool ret = m_external_address != i->addr;
		m_external_address = i->addr;

		m_external_address_voters.clear();
		m_total_votes = 0;
		m_external_addresses.clear();
		m_last_rotate = now;
		m_valid_external = true;
		return ret;
	}
コード例 #4
0
ファイル: pay.c プロジェクト: cdecker/lightning
static struct command_result *waitsendpay_error(struct command *cmd,
						const char *buf,
						const jsmntok_t *error,
						struct pay_command *pc)
{
	const jsmntok_t *codetok, *scidtok, *dirtok;
	int code;

	attempt_failed_tok(pc, "waitsendpay", buf, error);

	codetok = json_get_member(buf, error, "code");
	if (!json_to_int(buf, codetok, &code))
		plugin_err("waitsendpay error gave no 'code'? '%.*s'",
			   error->end - error->start, buf + error->start);

	/* FIXME: Handle PAY_UNPARSEABLE_ONION! */

	/* Many error codes are final. */
	if (code != PAY_TRY_OTHER_ROUTE) {
		return forward_error(cmd, buf, error, pc);
	}

	scidtok = json_delve(buf, error, ".data.erring_channel");
	if (!scidtok)
		plugin_err("waitsendpay error no erring_channel '%.*s'",
			   error->end - error->start, buf + error->start);
	dirtok = json_delve(buf, error, ".data.erring_direction");
	if (!dirtok)
		plugin_err("waitsendpay error no erring_direction '%.*s'",
			   error->end - error->start, buf + error->start);

	if (time_after(time_now(), pc->stoptime)) {
		return waitsendpay_expired(cmd, pc);
	}

	/* If failure is in routehint part, try next one */
	if (channel_in_routehint(pc->current_routehint, buf, scidtok))
		return next_routehint(cmd, pc);

	/* Otherwise, add erring channel to exclusion list. */
	tal_arr_expand(&pc->excludes,
		       tal_fmt(pc->excludes, "%.*s/%c",
			       scidtok->end - scidtok->start,
			       buf + scidtok->start,
			       buf[dirtok->start]));
	/* Try again. */
	return start_pay_attempt(cmd, pc, "Excluded channel %s",
				 pc->excludes[tal_count(pc->excludes)-1]);
}
コード例 #5
0
ファイル: smtsmtp.c プロジェクト: INNOAUS/gsl
MODULE write_body_header (THREAD *thread)
{
    tcb = thread-> tcb;                 /*  Point to thread's context        */
    smtp_msg = tcb-> message;           /*  only for readability             */

    *strout = '\0';                     /*   clears out buffer */

    /* Set the date and time of the message.                                  */
    xstrcat ( strout, "Date: ", encode_mime_time (date_now (), time_now ()),
              " \r\n", NULL);

    replacechrswith (smtp_msg-> dest_uids, ";", ',');
    xstrcat (strout, "To: ", smtp_msg-> dest_uids, "\r\n", NULL);
    
    if ( strstr( smtp_msg-> sender_uid, "<" ) != NULL &&
         strstr( smtp_msg-> sender_uid, ">" ) != NULL )
        xstrcat (strout, "Reply-To:",  smtp_msg-> sender_uid, "\r\n", NULL);
    else
        xstrcat (strout, "Reply-To:<", smtp_msg-> sender_uid, ">\r\n", NULL);

    xstrcat (strout, "Sender:", smtp_msg-> sender_uid, "\r\n", NULL);
    xstrcat (strout, "From:",   smtp_msg-> sender_uid, "\r\n", NULL);

    xstrcat (strout, "X-Mailer: sflmail function\r\n", NULL);

    /* Set the mime version. */
    xstrcat (strout, "MIME-Version: 1.0\r\n",
            "Content-Type: Multipart/Mixed; boundary=\"",
            tcb-> message_boundary,
            "\"\r\n",
            NULL);

    /* Send the subject and message body. */
    ASSERT (smtp_msg-> subject != NULL); /* XXX I'm not too sure */
    xstrcat (strout, "Subject:", smtp_msg-> subject, "\r\n\r\n", NULL);

    /* Send the plain text body header */
    xstrcat (strout, tcb-> plain_text_body_header, NULL);

    send_smtsock_write(
        &sockq,
        0,                              /* Timeout in seconds, zero = none */
        tcb-> sock_handle,              /* Socket to write to */
        (word) strlen (strout),         /* Amount of data to write */
        strout,                         /* Block of data to write */
        FALSE,                          /* Whether to always reply           */
        (void *) SOCK_TAG_WRITE);       /* User-defined request tag */
    TRACE_SMTP (strout);
}
コード例 #6
0
	void timeout_handler::set_timeout(int completion_timeout, int read_timeout)
	{
		m_completion_timeout = completion_timeout;
		m_read_timeout = read_timeout;
		m_start_time = m_read_time = time_now();

		if (m_abort) return;

		int timeout = (std::min)(
			m_read_timeout, (std::min)(m_completion_timeout, m_read_timeout));
		error_code ec;
		m_timeout.expires_at(m_read_time + seconds(timeout), ec);
		m_timeout.async_wait(bind(
			&timeout_handler::timeout_callback, self(), _1));
	}
コード例 #7
0
ファイル: timer.c プロジェクト: schnitzeltony/z80
/** @brief adjust the time when a timer expires */
int tmr_adjust(tmr_t *timer, tmr_time_t t, uint32_t param, tmr_time_t r)
{
	int i;
	for (i = 0; i < ti; i++)
		if (timer == timers[i])
			break;
	if (i >= ti)
		return -1;

	timer->expire = time_now() + t;
	timer->restart = r;
	timer->param = param;
	cycles = z80_cc;
	return 0;
}
コード例 #8
0
ファイル: bandwidth_manager.cpp プロジェクト: Chaduke/bah.mod
	bandwidth_manager::bandwidth_manager(int channel
#ifdef TORRENT_VERBOSE_BANDWIDTH_LIMIT
		, bool log = false
#endif		
		)
		: m_queued_bytes(0)
		, m_channel(channel)
		, m_abort(false)
	{
#ifdef TORRENT_VERBOSE_BANDWIDTH_LIMIT
		if (log)
			m_log.open("bandwidth_limiter.log", std::ios::trunc);
		m_start = time_now();
#endif
	}
コード例 #9
0
ファイル: schedule.c プロジェクト: eest/opendnssec
/**
 * Inspect head of queue and wakeup a worker now or set alarm.
 * Caller SHOULD hold schedule->schedule_lock. Failing to do so
 * could possibly cause a thread to miss the wakeup.
 */
static void
set_alarm(schedule_type* schedule)
{
    time_t now = time_now();
    task_type *task = get_first_task(schedule);
    if (!task || task->when == -1) {
        ods_log_debug("[%s] no alarm set", schedule_str);
    } else if (task->when == 0 || task->when <= now) {
        ods_log_debug("[%s] signal now", schedule_str);
        pthread_cond_signal(&schedule->schedule_cond);
    } else {
        ods_log_debug("[%s] SIGALRM set", schedule_str);
        alarm(task->when - now);
    }
}
コード例 #10
0
ファイル: timer.c プロジェクト: mikesun/xen-cow-checkpointing
Timer * Timer_set(double delay, TimerFn *fn, unsigned long data) {
    // Get 'now'.
    double now = time_now();
    Timer *timer = NULL;
    timer = ALLOCATE(Timer);
    if(!timer) goto exit;
    // Add delay to now to get expiry time.
    timer->expiry = now + delay;
    timer->fn = fn;
    timer->data = data;

    Timer_add(timer);
exit:
    return timer;
}
コード例 #11
0
ファイル: log.c プロジェクト: KansasLinuxFest/rs-serve
void do_log_debug(const char *file, int line, char *format, ...) {
  va_list ap;
  va_start(ap, format);
  char *timestamp = time_now();
  char new_format[strlen(timestamp) +
                  strlen(format) +
                  strlen(file) +
                  5 + // (reasonable length for 'line')
                  6 + // space for PID
                  + 23];
  sprintf(new_format, "[%d] [%s] [DEBUG] %s:%d: %s\n", getpid(), timestamp, file, line, format);
  vfprintf(RS_LOG_FILE, new_format, ap);
  va_end(ap);
  fflush(RS_LOG_FILE);
}
コード例 #12
0
ファイル: timer.c プロジェクト: schnitzeltony/z80
/** @brief allocate a new timer */
tmr_t *tmr_alloc(void (*callback)(uint32_t), tmr_time_t t, uint32_t param, tmr_time_t r)
{
	tmr_t *timer;
	if (ti >= MAX_TMR)
		return NULL;
	timers[ti] = timer = calloc(1, sizeof(tmr_t));
	if (NULL == timer)
		return NULL;
	ti++;
	timer->expire = time_now() + t;
	timer->restart = r;
	timer->param = param;
	timer->callback = callback;
	cycles = z80_cc;
	return timer;
}
コード例 #13
0
ファイル: udp.c プロジェクト: JayconSystems/c3listener
void udp_readcb(struct bufferevent *bev, void *c) {
    UNUSED(c);
    char buf[3] = {0};
    struct evbuffer *input = bufferevent_get_input(bev);
    while (evbuffer_get_length(input) >= 3) {
        bufferevent_read(bev, buf, 3);
        if (!strncmp(buf, "ACK", 3)) {
            udp_last_ack = time_now();
            if (!connection_valid) {
                connection_valid = true;
                log_notice("Connected to %s", config_get_remote_hostname());
            }
        }
    }
    return;
}
コード例 #14
0
void wspace_last_mc_marker_work( Conclctor *last_marker ) {
   
   GC *gc = last_marker->gc;
   if( gc->gc_concurrent_status != GC_CON_TRACING )
   	return;
   
   gc_con_update_stat_after_marking(gc); //calculate marked size
    //just debugging
   Con_Collection_Statistics *con_collection_stat = gc_ms_get_con_collection_stat((GC_MS*)gc);
   con_collection_stat->marking_end_time = time_now();
   int64 con_marking_time = con_collection_stat->marking_end_time - con_collection_stat->marking_start_time;
   INFO2("gc.scheduler", "[MOSTLY_CON] con marking time=" << con_marking_time << " us");

   state_transformation( gc, GC_CON_TRACING, GC_CON_TRACE_DONE );
   //INFO2("gc.con.info", "<new state 3> first marking thread finished its job, GC is waiting for all the marking threads finish, current marker num is [" << gc->num_active_markers << "]" );
}
コード例 #15
0
ファイル: datapath.c プロジェクト: BiangHoo/ofsoftswitch13
void
dp_run(struct datapath *dp) {
    time_t now = time_now();
    struct remote *r, *rn;
    size_t i;

    if (now != dp->last_timeout) {
        dp->last_timeout = now;
        meter_table_add_tokens(dp->meters);
        pipeline_timeout(dp->pipeline);
    }

    poll_timer_wait(1000);
    dp_ports_run(dp);

    /* Talk to remotes. */
    LIST_FOR_EACH_SAFE (r, rn, struct remote, node, &dp->remotes) {
        remote_run(dp, r);
    }

    for (i = 0; i < dp->n_listeners; ) {
        struct pvconn *pvconn = dp->listeners[i];
        struct vconn *new_vconn;

        int retval = pvconn_accept(pvconn, OFP_VERSION, &new_vconn);
        if (!retval) {
            struct rconn * rconn_aux = NULL;
            if (dp->n_listeners_aux && dp->listeners_aux[i] != NULL) {
                struct pvconn *pvconn_aux = dp->listeners_aux[i];
                struct vconn *new_vconn_aux;
                int retval_aux = pvconn_accept(pvconn_aux, OFP_VERSION, &new_vconn_aux);
                if (!retval_aux)
                    rconn_aux = rconn_new_from_vconn("passive_aux", new_vconn_aux);
            }
            remote_create(dp, rconn_new_from_vconn("passive", new_vconn), rconn_aux);
        }
        else if (retval != EAGAIN) {
            VLOG_WARN_RL(LOG_MODULE, &rl, "accept failed (%s)", strerror(retval));
            dp->listeners[i] = dp->listeners[--dp->n_listeners];
            if (dp->n_listeners_aux) {
                dp->listeners_aux[i] = dp->listeners_aux[--dp->n_listeners_aux];
            }
            continue;
        }
        i++;
    }
}
コード例 #16
0
static int tcp_wait_for_events(tcp_context_t *tcp)
{
	/* Wait for events. */
	fdset_t *set = &tcp->set;
	int nfds = poll(set->pfd, set->n, TCP_SWEEP_INTERVAL * 1000);

	/* Mark the time of last poll call. */
	time_now(&tcp->last_poll_time);

	/* Process events. */
	unsigned i = 0;
	while (nfds > 0 && i < set->n) {

		/* Terminate faulty connections. */
		int fd = set->pfd[i].fd;

		/* Active sockets. */
		if (set->pfd[i].revents & POLLIN) {
			--nfds; /* One less active event. */

			/* Indexes <0, client_threshold) are master sockets. */
			if (i < tcp->client_threshold) {
				/* Faulty master sockets shall be sorted later. */
				(void) tcp_event_accept(tcp, i);
			} else {
				if (tcp_event_serve(tcp, i) != KNOT_EOK) {
					fdset_remove(set, i);
					close(fd);
					continue; /* Stay on the same index. */
				}
			}

		}

		if (set->pfd[i].revents & (POLLERR|POLLHUP|POLLNVAL)) {
			--nfds; /* One less active event. */
			fdset_remove(set, i);
			close(fd);
			continue; /* Stay on the same index. */
		}

		/* Next socket. */
		++i;
	}

	return nfds;
}
コード例 #17
0
//called by the marker when it finishes
void gc_con_update_stat_after_marking(GC *gc)
{
  POINTER_SIZE_INT num_live_obj = 0;
  POINTER_SIZE_INT size_live_obj = 0;  
  POINTER_SIZE_INT num_dirty_obj_traced = 0;

  unsigned int num_conclctors = gc->num_conclctors;
  for( unsigned int i=0; i<num_conclctors; i++ ) {
    Conclctor* conclctor = gc->conclctors[i];
    if( conclctor->role != CONCLCTOR_ROLE_MARKER )
      continue;
    num_live_obj += conclctor->live_obj_num;
    size_live_obj += conclctor->live_obj_size;
    num_dirty_obj_traced += conclctor->num_dirty_slots_traced;
    conclctor->live_obj_num = 0;
    conclctor->live_obj_size = 0;
    conclctor->num_dirty_slots_traced = 0;
  }

  unsigned int write_barrier_marked_size = gc_get_mutator_write_barrier_marked_size(gc);
  Con_Collection_Statistics * con_collection_stat = gc_ms_get_con_collection_stat((GC_MS*)gc);
  con_collection_stat->live_size_marked = size_live_obj + write_barrier_marked_size;
  //INFO2("gc.con.scheduler", "[Mark Finish] live_marked_size:      "<<con_collection_stat->live_size_marked<<" bytes");
  
   /*statistics information update (marking_end_time, trace_rate) */
  con_collection_stat->marking_end_time = time_now();
  int64 marking_time = (unsigned int)(con_collection_stat->marking_end_time - con_collection_stat->marking_start_time);

  unsigned int heap_size = 
  	con_collection_stat->surviving_size_at_gc_end + 
  	gc_get_mutator_new_obj_size(gc);
  	
  con_collection_stat->trace_rate = heap_size/trans_time_unit(marking_time);
   


  /*
  //statistics just for debugging
  unsigned int marker_num = gc_get_conclcor_num(gc, CONCLCTOR_ROLE_MARKER);
  float heap_used_rate = (float)heap_size/gc->committed_heap_size;
  unsigned int new_obj_size_marking = gc_get_mutator_new_obj_size(gc) - con_collection_stat->alloc_size_before_alloc_live;
  unsigned int alloc_rate_marking = new_obj_size_marking/trans_time_unit(con_collection_stat->marking_end_time - con_collection_stat->marking_start_time);
  INFO2("gc.con.scheduler", "[Mark Finish] tracing time=" <<marking_time<<" us, trace rate=" << con_collection_stat->trace_rate<<"b/ms, current heap used="<<heap_used_rate );
  INFO2("gc.con.scheduler", "[Mark Finish] marker num="<<marker_num << ", alloc factor=" << (float)alloc_rate_marking/con_collection_stat->alloc_rate);
  */
}
コード例 #18
0
ファイル: timer.c プロジェクト: schnitzeltony/z80
/** @brief reset the time when a timer expires */
int tmr_reset(tmr_t *timer, tmr_time_t t)
{
	int i;
	for (i = 0; i < ti; i++)
		if (timer == timers[i])
			break;
	if (i >= ti)
		return -1;

	if (time_never == t) {
		timer->expire = time_never;
	} else {
		timer->expire = time_now() + t;
	}
	cycles = z80_cc;
	return 0;
}
コード例 #19
0
ファイル: conf_debug.c プロジェクト: daixinning/oxygen
/*****************************************************************************
 函 数 名  : conf_dbg_dump
 功能描述  : dump数据块的数据
 参数列表  : const void *buffer
             int buf_len
 返 回 值  : void
*****************************************************************************/
void conf_dbg_dump(const void *buffer, int buf_len)
{
    int i;
    u8_t *ptr;
    char str[17] = {0};
    FILE *out;
    asc_time_t now;

    if ((dbg_level < DBG_DEBUG) || (buf_len == 0)) {
        return;
    }

    out = (log_file != NULL) ? log_file : stderr;

    pthread_mutex_lock(&out_mutex);

    fprintf(out, "%s [DEBUG] Buffer length is %d.\n", time_now(&now), buf_len);

    for (i = 0, ptr = (u8_t*)buffer; (i < buf_len) || ((i & 0xf) != 0); ++i) {
        if ((i & 0xf) == 0) {
            fprintf(out, "  [%04d]", i);
        } else if ((i & 0x7) == 0) {
            fprintf(out, " ");
        }

        if (i < buf_len) {
            fprintf(out, " %02x", (u8_t)(ptr[i]));
            if ((0x20 <=  ptr[i]) && (ptr[i] <= 0x7e)) {
                str[i & 0xf] = ptr[i];
            } else {
                str[i & 0xf] = '.';
            }
        } else {
            fprintf(out, "   ");
            str[i & 0xf] = 0;
        }

        if ((i & 0xf) == 0xf) {
            fprintf(out, "  |  %s\n", str);
        }
    }

    pthread_mutex_unlock(&out_mutex);

    return;
}
コード例 #20
0
ファイル: enforce_task.c プロジェクト: eest/opendnssec
task_type *
enforce_task(engine_type *engine, bool all)
{
	task_id what_id;
	const char *what = "enforce";
	const char *who = "next zone";
	struct enf_task_ctx *ctx = &enforcer_context;
	if (!ctx) {
		ods_log_error("Malloc failure, enforce task not scheduled");
		return NULL;
	}
	ctx->engine = engine;
	ctx->enforce_all = all;
	what_id = task_register(what, module_str, enforce_task_perform);
	return task_create(what_id, time_now(), who, what, ctx,
		enforce_task_clean_ctx);
}
コード例 #21
0
ファイル: fail-open.c プロジェクト: TakashiSasaki/openflow
void
fail_open_start(struct secchan *secchan, const struct settings *s,
                struct switch_status *ss,
                struct rconn *local_rconn, struct rconn *remote_rconn)
{
    struct fail_open_data *fail_open = xmalloc(sizeof *fail_open);
    fail_open->s = s;
    fail_open->local_rconn = local_rconn;
    fail_open->remote_rconn = remote_rconn;
    fail_open->lswitch = NULL;
    fail_open->boot_deadline = time_now() + s->probe_interval * 3;
    if (s->enable_stp) {
        fail_open->boot_deadline += STP_EXTRA_BOOT_TIME;
    }
    switch_status_register_category(ss, "fail-open",
                                    fail_open_status_cb, fail_open);
    add_hook(secchan, &fail_open_hook_class, fail_open);
}
コード例 #22
0
ファイル: cevent.c プロジェクト: Joinhack/thr_socket
//return push queue count or J_ERR
int cevents_poll(cevents *cevts, msec_t ms) {
	int rs, i, count = 0, flag = 0;
	cevent_fired *fired;
	cevent *evt;
	if(cevts == NULL) {
		ERROR("can't be happend\n");
		abort();
	}
	LOCK(&cevts->lock);
	rs = cevents_poll_impl(cevts, ms);
	UNLOCK(&cevts->lock);
	time_now(&cevts->poll_sec, &cevts->poll_ms);
	if(rs > 0) {
		for(i = 0; i < rs; i++) {
			fired = cevts->fired + i;
			evt = cevts->events + fired->fd;
			if(!evt->mask)
				continue;
			if(evt->mask & CEV_PERSIST) {
				fired->mask |= CEV_PERSIST;

				if(evt->mask && (fired->mask & CEV_READ)) {
					//just send read event to event queue.
					if(evt->read_proc(cevts, fired->fd, evt->priv, fired->mask) == 0) {
						cevents_del_event(cevts, fired->fd, CEV_READ);
						cevents_push_fired(cevts, clone_cevent_fired(cevts, fired));
						count++;
					}
				}
				if(evt->mask && (fired->mask & CEV_WRITE)) {
					evt->write_proc(cevts, fired->fd, evt->priv, fired->mask);
				}
			} else {
				//unbind the events.
				cevents_del_event(cevts, fired->fd, fired->mask);
				cevents_push_fired(cevts, clone_cevent_fired(cevts, fired));
				count++;
			}
		}
	}
	//must sleep, let other thread grant the lock. maybe removed when the time event added.
	usleep(2);
	return count;
}
コード例 #23
0
ファイル: flow_table.c プロジェクト: kazuyas/trema-edge
static void
age_flow_entries( void *user_data ) {
  const uint8_t table_id = *( uint8_t * ) user_data;

  assert( valid_table_id( table_id ) );

  if ( !lock_pipeline() ) {
    return;
  }

  struct timespec now = { 0, 0 };
  time_now( &now );

  foreach_flow_entry( table_id, age_flow_entries_walker, &now );

  if ( !unlock_pipeline() ) {
    return;
  }
}
コード例 #24
0
ファイル: time.c プロジェクト: plujon/hrs3-c
static void test_time_whms(void)
{
  a_time t_ = time_clone(time_now()), *t = &t_;
#define X(wday, hour, min, sec) do {                                  \
    time_whms(t, wday, hour, min, sec);                              \
    time_t time = time_time(t);                                      \
    a_time t2;                                                         \
    time_init(&t2, time);                                             \
    const struct tm *tm = time_tm(&t2);                                \
    if (tm->tm_wday != wday) TFAILF(" %s", "wday mismatch");          \
    if (tm->tm_sec != sec) TFAILF(" sec %d vs %d", tm->tm_sec, sec); \
    if (tm->tm_min != min) TFAILF(" min %d vs %d", tm->tm_min, min); \
    if (tm->tm_hour != hour) TFAILF(" hour %d vs %d", tm->tm_hour, hour); \
  } while_0
  X(0, 0, 0, 0);
  X(1, 1, 1, 1);
  X(6, 23, 59, 59);
#undef X
}
コード例 #25
0
ファイル: protocol.c プロジェクト: Daimas/android-pachi
/* Write the time, client address, prefix, and string s to stderr atomically.
 * s should end with a \n */
void
logline(struct in_addr *client, char *prefix, char *s)
{
	double now = time_now();

	char addr[INET_ADDRSTRLEN];
	if (client) {
#ifdef _WIN32
		strcpy(addr, inet_ntoa(*client));
#else
		inet_ntop(AF_INET, client, addr, sizeof(addr));
#endif
	} else {
		addr[0] = '\0';
	}
	pthread_mutex_lock(&log_lock);
	fprintf(stderr, "%s%15s %9.3f: %s", prefix, addr, now - start_time, s);
	pthread_mutex_unlock(&log_lock);
}
コード例 #26
0
ファイル: fileop.c プロジェクト: teddokano/CaFE2
int fileop_save_by_name( char *file_name )
{
	FILE	*fp;
	char	name[ MAX_TOKEN_LENGTH ];
	char	s[80];
	
	strcpy( name, file_name );

	file_handle_path( name, MAX_TOKEN_LENGTH );
	
	if ( NULL == (fp	= fopen( name, "w" )) )
	{
		cprintf( ERROR, CONT, "fail to save file \"%s\"\n", name );
		return ( ERROR );
	}

	fprintf( fp, "###\n" );
	fprintf( fp, "### CaFE file made by \"save\" command.\n" );
	fprintf( fp, "###    --- %s ---\n", version_string( s ) );

	time_now( s );
	
	fprintf( fp, "###\n###    ### saved : %s\n###\n", s );
	fprintf( fp, "\n\n### user stack operation functions\n\n" );

	fprintf( fp, "0 >newlydefined_{\n" );
	fprintf( fp, "0 >newlydefined_k}\n\n" );
	fprintf( fp, "fisdef {    if z :@ :{ =new =target ; 1 >newlydefined_{ ; pop\n\n" );
	fprintf( fp, "fisdef k}   if z :@ :k} =parent =target ; 1 >newlydefined_k} ; pop\n\n\n" );
	
	fprintf( fp, "### content of stack\n\n" );
	
	save_stack( NULL, fp );
	
	fprintf( fp, "\n\n### content of stack end\n\n" );

	fprintf( fp, "<newlydefined_{  if t :@ forget { ;  pop\n" );
	fprintf( fp, "<newlydefined_k} if t :@ forget k} ; pop\n" );
	
	fclose( fp );

	return ( NO_ERROR );
}
コード例 #27
0
ファイル: timer.c プロジェクト: mikesun/xen-cow-checkpointing
/** Set the process real-time timer to go off at a given expiry time.
 * The timer will not be set to go off in less than 10 ms
 * (even if the expiry time is sooner, or in the past).
 *
 * @param expiry time (in seconds)
 * @return 0 on success, error code otherwise
 */
static int itimer_set(double expiry) {
    struct itimerval val = {};
    struct itimerval old = {};
    double now, delay;
    int err = 0;

    if(expiry == 0.0) {
        val.it_value.tv_sec = 0;
        val.it_value.tv_usec = 0;
    } else {
        now = time_now();
        delay = expiry - now;
        if(delay < 0.01) delay = 0.01;
        val.it_value.tv_sec = (long)delay;
        val.it_value.tv_usec = (long)((delay - (double)(long)delay) * 1.0e6);
    }
    err = setitimer(ITIMER_REAL, &val, &old);
    return err;
}
コード例 #28
0
ファイル: schedule.c プロジェクト: eest/opendnssec
task_type*
schedule_pop_task(schedule_type* schedule)
{
    time_t now = time_now();
    task_type* task;

    pthread_mutex_lock(&schedule->schedule_lock);
        task = get_first_task(schedule);
        if (!task || (!task->flush && (task->when == -1 || task->when > now))) {
            /* nothing to do now, sleep and wait for signal */
            pthread_cond_wait(&schedule->schedule_cond,
                &schedule->schedule_lock);
            task = NULL;
        } else {
            task = pop_first_task(schedule);
        }
    pthread_mutex_unlock(&schedule->schedule_lock);
    return task;
}
コード例 #29
0
ファイル: schedule.c プロジェクト: eest/opendnssec
int
schedule_flush_type(schedule_type* schedule, task_id id)
{
    ldns_rbnode_t *node, *nextnode;
    int nflushed = 0;
    
    ods_log_debug("[%s] flush task", schedule_str);
    if (!schedule || !schedule->tasks) return 0;

    pthread_mutex_lock(&schedule->schedule_lock);
        node = ldns_rbtree_first(schedule->tasks);
        while (node && node != LDNS_RBTREE_NULL) {
            nextnode = ldns_rbtree_next(node);
            if (node->data && ((task_type*)node->data)->what == id) {
                /* Merely setting flush is not enough. We must set it
                 * to the front of the queue as well. */
                node = ldns_rbtree_delete(schedule->tasks, node->data);
                if (!node) break; /* stange, bail out */
                if (node->data) { /* task */
                    ((task_type*)node->data)->flush = 1;
                    /* This is important for our tests only. If a task is
                     * set to flush it should not affect the current time.
                     * Otherwise timeleap will advance time. */
                    ((task_type*)node->data)->when = time_now();
                    if (!ldns_rbtree_insert(schedule->tasks, node)) {
                        ods_log_crit("[%s] Could not reschedule task "
                            "after flush. A task has been lost!",
                            schedule_str);
                        free(node);
                        /* Do not free node->data it is still in use
                         * by the other rbtree. */
                        break;
                    }
                    nflushed++;
                }
            }
            node = nextnode;
        }
        /* wakeup! work to do! */
        pthread_cond_signal(&schedule->schedule_cond);
    pthread_mutex_unlock(&schedule->schedule_lock);
    return nflushed;
}
コード例 #30
0
static unsigned int gc_con_heap_full_otf( GC *gc )
{
   unsigned int partial_type; //for time measuring and debugging
   int disable_count = vm_suspend_all_threads();
   Con_Collection_Statistics *con_collection_stat = gc_ms_get_con_collection_stat((GC_MS*)gc);
   con_collection_stat->pause_start_time = time_now();
   switch(gc->gc_concurrent_status) {
   	case GC_CON_START_MARKERS :
       case GC_CON_TRACING :
       case GC_CON_TRACE_DONE :
         partial_type = GC_PARTIAL_PMSS;
         gc_partial_con_PMSS(gc);
	  break;
       case GC_CON_BEFORE_SWEEP : // only when current sweep is set to false
         partial_type = GC_PARTIAL_CMSS; 
         gc_partial_con_CMSS(gc);
         break;
       case GC_CON_SWEEPING :
       case GC_CON_SWEEP_DONE :
         partial_type = GC_PARTIAL_CMPS;
         gc_partial_con_CMPS(gc);
         break;
       case GC_CON_BEFORE_FINISH : //heap can be exhausted when sweeping finishes, very rare
         partial_type = GC_PARTIAL_FCSR;
	  gc_merge_free_list_global(gc);
	  gc_reset_after_con_collection(gc);
	  set_con_nil(gc);
	  break;
	case GC_CON_RESET :
	case GC_CON_NIL :
	case GC_CON_STW_ENUM :
	  /*do nothing, if still in gc_con_reset, will wait to finish after resuming. this case happens rarely*/
	  partial_type = GC_PARTIAL_FCSR; 
	  break;
	/* other state is illegal here */
	default:
         INFO2("gc.con.info", "illegal state when the heap is out [" << gc->gc_concurrent_status << "]");
         RAISE_ERROR;
    }
    vm_resume_all_threads(disable_count);
    return partial_type;
}