本文整理汇总了C++中print_time函数的典型用法代码示例。如果您正苦于以下问题:C++ print_time函数的具体用法?C++ print_time怎么用?C++ print_time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print_time函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
print_time();
return 0;
}
开发者ID:pandolia,项目名称:advanced-linux-program,代码行数:5,代码来源:p8.6-print-time.c
示例2: main
//.........这里部分代码省略.........
if (verbosity > 0) fprintf(stderr, "%s\n", lperrmsg);
if (lperrno != NOTINDICT) exit(-1);
else continue;
}
if (sentence_length(sent) > parse_options_get_max_sentence_length(opts)) {
sentence_delete(sent);
if (verbosity > 0) {
fprintf(stdout,
"Sentence length (%d words) exceeds maximum allowable (%d words)\n",
sentence_length(sent), parse_options_get_max_sentence_length(opts));
}
continue;
}
/* First parse with cost 0 or 1 and no null links */
parse_options_set_disjunct_cost(opts, 2);
parse_options_set_min_null_count(opts, 0);
parse_options_set_max_null_count(opts, 0);
parse_options_reset_resources(opts);
num_linkages = sentence_parse(sent, opts);
/* Now parse with null links */
if ((num_linkages == 0) && (!parse_options_get_batch_mode(opts))) {
if (verbosity > 0) fprintf(stdout, "No complete linkages found.\n");
if (parse_options_get_allow_null(opts)) {
parse_options_set_min_null_count(opts, 1);
parse_options_set_max_null_count(opts, sentence_length(sent));
num_linkages = sentence_parse(sent, opts);
}
}
if (parse_options_timer_expired(opts)) {
if (verbosity > 0) fprintf(stdout, "Timer is expired!\n");
}
if (parse_options_memory_exhausted(opts)) {
if (verbosity > 0) fprintf(stdout, "Memory is exhausted!\n");
}
if ((num_linkages == 0) &&
parse_options_resources_exhausted(opts) &&
parse_options_get_panic_mode(opts)) {
print_total_time(opts);
if (verbosity > 0) fprintf(stdout, "Entering \"panic\" mode...\n");
parse_options_reset_resources(panic_parse_opts);
parse_options_set_verbosity(panic_parse_opts, verbosity);
num_linkages = sentence_parse(sent, panic_parse_opts);
if (parse_options_timer_expired(panic_parse_opts)) {
if (verbosity > 0) fprintf(stdout, "Timer is expired!\n");
}
}
print_total_time(opts);
if (parse_options_get_batch_mode(opts)) {
batch_process_some_linkages(label, sent, opts);
}
else {
process_some_linkages(sent, opts);
}
sentence_delete(sent);
if (external_space_in_use != 0) {
fprintf(stderr, "Warning: %d bytes of external space leaked.\n",
external_space_in_use);
}
}
if (parse_options_get_batch_mode(opts)) {
print_time(opts, "Total");
fprintf(stderr,
"%d error%s.\n", batch_errors, (batch_errors==1) ? "" : "s");
}
parsing_space_leaked = space_in_use - dictionary_and_option_space;
if (parsing_space_leaked != 0) {
fprintf(stderr, "Warning: %d bytes of space leaked during parsing.\n",
parsing_space_leaked);
}
parse_options_delete(panic_parse_opts);
parse_options_delete(opts);
dictionary_delete(dict);
if (space_in_use != parsing_space_leaked) {
fprintf(stderr,
"Warning: %d bytes of dictionary and option space leaked.\n",
space_in_use - parsing_space_leaked);
}
else if (parsing_space_leaked == 0) {
fprintf(stderr, "Good news: no space leaked.\n");
}
if (external_space_in_use != 0) {
fprintf(stderr, "Warning: %d bytes of external space leaked.\n",
external_space_in_use);
}
return 0;
}
开发者ID:IncorexLLC,项目名称:Elchi,代码行数:101,代码来源:parse.c
示例3: main
int main(int argc, char **argv)
{
enum state state;
unsigned char command;
struct timeval tval;
struct packet pkt;
/* Open a socket and start listening to a scpefied port */
open_udp_socket();
srand(time(NULL));
/* Startup: */
build_send_packet(BROADCAST, CMD_MASTERREQ, 0); /* Search for a master */
change_state(&state, STATE_STARTUP, &tval, NULL);
for(;;)
{
struct timeval curtime;
gettimeofday(&curtime, NULL);
printf(" ");
print_time(&curtime);
/*printf(" TIME: %10d sec %10d usec\n",
(unsigned int)curtime.tv_sec, (unsigned int)curtime.tv_usec);*/
recv_msg(&pkt, &tval);
command = pkt.type;
//printf("Command received = %d\n", command);
switch(state | command)
{
/* STARTUP */
case(STATE_STARTUP | CMD_TIMEOUT):
build_send_packet(BROADCAST, CMD_MASTERUP, 0);
change_state(&state, STATE_MASTER, &tval, &master_timeout);
break;
case(STATE_STARTUP | CMD_MASTERUP):
build_send_packet(pkt.ip, CMD_SLAVEUP, 0);
// no break;
case(STATE_STARTUP | CMD_MASTERREQ):
case(STATE_STARTUP | CMD_MASTERACK):
case(STATE_STARTUP | CMD_ELECTION):
change_state(&state, STATE_SLAVE, &tval, NULL);
break;
/* MASTER */
/* Launch a new thread and process separately? Prevents loss of messages */
case(STATE_MASTER | CMD_TIMEOUT):
/* Does the Master needs to send his clock? */
build_send_packet(BROADCAST, CMD_CLOCKREQ, 1);
//change_state(&state, STATE_MASTER, &tval, MASTER_TIMEOUT);
/* Change to an intermediate state in order to wait for all slaves
* to send their clocks. After the MASTER_ADJTIME_TIMEOUT no more clock
* packets will be accepted and the "slow" slaves, if any, won't
* be synchronized*/
change_state(&state, STATE_MASTER_ADJTIME, &tval, &master_adjtime_timeout);
/* Possibly new thread? Non blocking function...*/
adjust_master_prepare();
break;
case(STATE_MASTER | CMD_MASTERREQ):
build_send_packet(pkt.ip, CMD_MASTERACK, 0);
break;
case(STATE_MASTER | CMD_QUIT):
build_send_packet(pkt.ip, CMD_ACK, 0);
change_state(&state, STATE_SLAVE, &tval, NULL);
break;
case(STATE_MASTER | CMD_ELECTION):
case(STATE_MASTER | CMD_MASTERUP):
build_send_packet(pkt.ip, CMD_QUIT, 0);
break;
/* MASTER_ADJTIME */
case(STATE_MASTER_ADJTIME | CMD_CLOCKREQ_RESPONSE):
/* Got time from client */
adjust_master_addslave(pkt.ip, &pkt.time);
break;
case(STATE_MASTER_ADJTIME | CMD_TIMEOUT):
/* Calculate avg clocks and send to each slave his correction */
/* Restart the synchronization timer */
change_state(&state, STATE_MASTER, &tval, &master_timeout);
adjust_master_calcandsend();
break;
/* SLAVE */
case(STATE_SLAVE | CMD_CLOCKREQ):
/* Send clock packet to master and change to an intermediate state
* in order to wait for a synch packet */
build_send_packet(pkt.ip, CMD_CLOCKREQ_RESPONSE, 1);
change_state(&state, STATE_SLAVE, &tval, NULL);
break;
case(STATE_SLAVE | CMD_TIMEOUT):
build_send_packet(BROADCAST, CMD_ELECTION, 0);
change_state(&state, STATE_CANDIDATE, &tval, &candidate_timeout);
//.........这里部分代码省略.........
开发者ID:brunoseivam,项目名称:clocksync,代码行数:101,代码来源:main.c
示例4: main
int main(int argc, char *argv[])
{
struct timeval T1,T2 ;
pthread_t *threads = NULL ;
int thread_num = 0 ;
char *store_name = NULL ;
int mode = 0 ;
if( argc != 4 ){
help() ;
exit(1) ;
}
thread_num = atoi( argv[2] ) ;
store_name = argv[1] ;
mode = atoi(argv[3]) ;
obj_store = store_name ;
int a[10] = {0};
int q = 0 ;
for(q = 0 ; q < 10 ; q++)
a[q] = q; /* initialize parameter about stm operation*/
for(q = 0 ; q < 3100000 ; q++)
static_key[q] = q; /* initialize key */
per_thread_count = TOTAL_COUNT / thread_num;
/* count for per thread operation */
if(( threads == (pthread_t *)malloc(thread_num * sizeof(pthread_t)))
== NULL){
perror("thread malloc error") ;
exit(1);
}/* thread create and error check */
int ret_val = 0 ; /*return value check */
if( mode == 1 ){ /* list insert operation */
ret_val = stm_pos_list_init(store_name) ;
ret_val = stm_pos_list_open(store_name) ;
}else if( mode == 2){ /* hash insert operation */
int rec_num = 8 ; /*hard coding will be changed */
ret_val = stm_pos_create_hashtable(store_name,rec_num,NULL,NULL);
ret_val = stm_pos_hashtable_open(store_name) ;
}else if(mode == 3){ /* btree insert operation */
ret_val = stm_pos_btree_init(store_name);
ret_val = stm_pos_btree_open(store_name) ;
} /* data structure init and open complete */
/* insert & remove operation part */
if( mode == 1 ){
gettimeofday(&T1,NULL);
for(i = 0 ; i < threads_num ; i++){
if(pthread_create(&threads[i],NULL,stm_list_insert,
(void*)&a[i])!=0){
fprintf(stderr,"error creating threads") ;
exit(1) ;
}
}
for(i = 0 ; i < threads_num ; i++){
if(pthread_join(threads[i],NULL)!=0){
fprintf(stderr,"error waiting threads") ;
exit(1);
}
}
gettimeofday(&T2,NULL) ;
print_time(T1,T2); /*calculate total response time*/
stm_pos_list_close(store_name) ;
}else if(mode == 2){
gettimeofday(&T1,NULL) ;
for( i = 0 ; i < threads_num ; i++){
if(pthread_create(&threads[i],NULL,stm_hash_insert,
(void*)&a[i])!=0){
fprintf(stderr,"error creating threads") ;
exit(1) ;
}
}
for( i = 0 ; i < threads_num ; i++){
if( pthread_join(threads[i],NULL)!=0){
fprintf(stderr,"error waiting threads") ;
exit(1);
}
}
gettimeofday(&T2,NULL) ;
print_time(T1,T2);
stm_pos_hashtable_close(store_name);
}else if(mode == 3){
gettimeofday(&T1,NULL) ;
for( i = 0 ; i < threads_num ; i++){
if(pthread_create(&threads[i],NULL,stm_btree_insert,
(void*)&a[i])!=0){
fprintf(stderr,"error creating threads") ;
exit(1) ;
}
}
for( i = 0 ; i < threads_num ; i++){
if( pthread_join(threads[i],NULL)!=0){
fprintf(stderr,"error waiting threads") ;
exit(1);
}
}
//.........这里部分代码省略.........
开发者ID:kunulee,项目名称:f-stm,代码行数:101,代码来源:kv_perf.c
示例5: set_time
void set_time(void) {
uint8_t mode = init_set_menu(2);
uint8_t hour, min, sec;
hour = time_h;
min = time_m;
sec = time_s;
while (!check_timeout()) {
if (just_pressed & 0x2) {
just_pressed = 0;
screenmutex++;
if (mode == SET_TIME) {
DEBUG(putstring("Set time hour"));
// ok now its selected
mode = SET_HOUR;
// display instructions below
print_menu_opts("change hr","set hour");
} else if (mode == SET_HOUR) {
DEBUG(putstring("Set time min"));
mode = SET_MIN;
// display instructions below
print_menu_opts("change min","set mins");
} else if (mode == SET_MIN) {
DEBUG(putstring("Set time sec"));
mode = SET_SEC;
// display instructions below
print_menu_opts("change sec","set secs");
} else {
// done!
DEBUG(putstring("done setting time"));
mode = SET_TIME;
// display instructions below
print_menu_advance();
writei2ctime(sec, min, hour, 0, date_d, date_m, date_y);
time_h = hour;
time_m = min;
time_s = sec;
}
print_time(hour,min,sec,mode);
screenmutex--;
}
// was easter egg
if ((just_pressed & 0x4) || (pressed & 0x4)) {
just_pressed = 0;
screenmutex++;
if (mode == SET_HOUR) {
hour = (hour+1) % 24;
time_h = hour;
}
if (mode == SET_MIN) {
min = (min+1) % 60;
}
if (mode == SET_SEC) {
sec = (sec+1) % 60;
}
print_time(hour,min,sec,mode);
screenmutex--;
if (pressed & 0x4)
delay_ms(200);
}
}
}
开发者ID:Someguynamedjoe,项目名称:monochron,代码行数:68,代码来源:config.c
示例6: a2dp_write
int a2dp_write(a2dpData d, const void* buffer, int count)
{
struct bluetooth_data* data = (struct bluetooth_data*)d;
uint8_t* src = (uint8_t *)buffer;
int codesize;
int err, ret = 0;
long frames_left = count;
int encoded;
unsigned int written;
const char *buff;
int did_configure = 0;
#ifdef ENABLE_TIMING
uint64_t begin, end;
DBG("********** a2dp_write **********");
begin = get_microseconds();
#endif
err = check_for_start(data);
if (err < 0)
return err;
pthread_mutex_lock(&data->mutex);
codesize = data->codesize;
while (frames_left >= codesize) {
/* Enough data to encode (sbc wants 512 byte blocks) */
if (data->sbc.priv == NULL) {
ERR("bad state");
ret = -EINVAL;
goto done;
}
encoded = sbc_encode(&(data->sbc), src, codesize,
data->buffer + data->count,
sizeof(data->buffer) - data->count,
&written);
if (encoded <= 0) {
ERR("Encoding error %d", encoded);
goto done;
}
VDBG("sbc_encode returned %d, codesize: %d, written: %d\n",
encoded, codesize, written);
src += encoded;
data->count += written;
data->frame_count++;
data->samples += encoded;
data->nsamples += encoded/4;
/* No space left for another frame then send or frame count limit reached */
if ((data->frame_count == 15) || (data->count + written >= data->link_mtu) ||
(data->count + written >= BUFFER_SIZE)) {
VDBG("sending packet %d, count %d, link_mtu %u",
data->seq_num, data->count,
data->link_mtu);
err = avdtp_write(data);
if (err < 0) {
pthread_mutex_unlock(&data->mutex);
return err;
}
}
ret += encoded;
frames_left -= encoded;
}
if (frames_left > 0)
ERR("%ld bytes left at end of a2dp_write\n", frames_left);
done:
pthread_mutex_unlock(&data->mutex);
#ifdef ENABLE_TIMING
end = get_microseconds();
print_time("a2dp_write total", begin, end);
#endif
return ret;
}
开发者ID:OmarBizreh,项目名称:Sliding_XZ,代码行数:76,代码来源:liba2dp.c
示例7: main
//.........这里部分代码省略.........
if (write_test)
shake_memory(buf, size);
this_time = now();
ret_size = make_request(fd, buf, size, offset + woffset);
if (ret_size < 0) {
if (errno != EINTR)
err(3, "request failed");
} else if (ret_size < size)
warnx("request returned less than expected: %zu", ret_size);
else if (ret_size > size)
errx(3, "request returned more than expected: %zu", ret_size);
time_now = now();
this_time = time_now - this_time;
time_next = time_now + interval;
part_sum += this_time;
part_sum2 += this_time * this_time;
if (this_time < part_min)
part_min = this_time;
if (this_time > part_max)
part_max = this_time;
if (!quiet) {
print_size(ret_size);
printf(" %s %s (%s %s", write_test ? "to" : "from",
path, fstype, device);
if (device_size)
print_size(device_size);
printf("): request=%d time=", request);
print_time(this_time);
printf("\n");
}
if ((period_request && (part_request >= period_request)) ||
(period_time && (time_next >= period_deadline))) {
part_avg = part_sum / part_request;
part_mdev = sqrt(part_sum2 / part_request - part_avg * part_avg);
printf("%d %.0f %.0f %.0f %.0f %.0f %.0f %.0f\n",
part_request, part_sum,
1000000. * part_request / part_sum,
1000000. * part_request * size / part_sum,
part_min, part_avg,
part_max, part_mdev);
time_sum += part_sum;
time_sum2 += part_sum2;
if (part_min < time_min)
time_min = part_min;
if (part_max > time_max)
time_max = part_max;
part_min = LLONG_MAX;
part_max = LLONG_MIN;
part_sum = part_sum2 = 0;
part_request = 0;
period_deadline = time_now + period_time;
}
if (!randomize) {
woffset += size;
if (woffset + size > wsize)
开发者ID:yksuh,项目名称:ioping,代码行数:67,代码来源:ioping.c
示例8: main
main ()
{
static REAL aa[200][200],a[200][201],b[200],x[200];
REAL cray,ops,total,norma,normx;
REAL resid,residn,eps,t1,tm,tm2;
REAL epslon(),second(),kf;
static int ipvt[200],n,i,ntimes,info,lda,ldaa,kflops;
lda = 201;
ldaa = 200;
cray = .056;
n = 100;
fprintf(stdout,ROLLING);fprintf(stdout,PREC);fprintf(stdout,"Precision Linpack\n\n");
fprintf(stderr,ROLLING);fprintf(stderr,PREC);fprintf(stderr,"Precision Linpack\n\n");
ops = (2.0e0*(n*n*n))/3.0 + 2.0*(n*n);
matgen(a,lda,n,b,&norma);
t1 = second();
dgefa(a,lda,n,ipvt,&info);
time[0][0] = second() - t1;
t1 = second();
dgesl(a,lda,n,ipvt,b,0);
time[1][0] = second() - t1;
total = time[0][0] + time[1][0];
/* compute a residual to verify results. */
for (i = 0; i < n; i++) {
x[i] = b[i];
}
matgen(a,lda,n,b,&norma);
for (i = 0; i < n; i++) {
b[i] = -b[i];
}
dmxpy(n,b,n,lda,x,a); // Optimized function
resid = 0.0;
normx = 0.0;
for (i = 0; i < n; i++) {
resid = (resid > fabs((double)b[i])) ? resid : fabs((double)b[i]);
normx = (normx > fabs((double)x[i])) ? normx : fabs((double)x[i]);
}
eps = epslon((REAL)ONE);
residn = resid/( n*norma*normx*eps );
printf(" norm. resid resid machep");
printf(" x[0]-1 x[n-1]-1\n");
printf(" %8.1f %16.8e%16.8e%16.8e%16.8e\n",
(double)residn, (double)resid, (double)eps,
(double)x[0]-1, (double)x[n-1]-1);
fprintf(stderr," times are reported for matrices of order %5d\n",n);
fprintf(stderr," dgefa dgesl total kflops unit");
fprintf(stderr," ratio\n");
time[2][0] = total;
time[3][0] = ops/(1.0e3*total);
time[4][0] = 2.0e3/time[3][0];
time[5][0] = total/cray;
fprintf(stderr," times for array with leading dimension of%5d\n",lda);
print_time(0);
matgen(a,lda,n,b,&norma);
t1 = second();
dgefa(a,lda,n,ipvt,&info);
time[0][1] = second() - t1;
t1 = second();
dgesl(a,lda,n,ipvt,b,0);
time[1][1] = second() - t1;
total = time[0][1] + time[1][1];
time[2][1] = total;
time[3][1] = ops/(1.0e3*total);
time[4][1] = 2.0e3/time[3][1];
time[5][1] = total/cray;
matgen(a,lda,n,b,&norma);
t1 = second();
dgefa(a,lda,n,ipvt,&info);
time[0][2] = second() - t1;
t1 = second();
dgesl(a,lda,n,ipvt,b,0);
time[1][2] = second() - t1;
total = time[0][2] + time[1][2];
time[2][2] = total;
time[3][2] = ops/(1.0e3*total);
time[4][2] = 2.0e3/time[3][2];
time[5][2] = total/cray;
ntimes = NTIMES;
tm2 = 0.0;
t1 = second();
for (i = 0; i < ntimes; i++) {
tm = second();
matgen(a,lda,n,b,&norma);
tm2 = tm2 + second() - tm;
dgefa(a,lda,n,ipvt,&info);
}
//.........这里部分代码省略.........
开发者ID:caidongyun,项目名称:parallella-computing,代码行数:101,代码来源:clinpack.c
示例9: main
int main(int argc, char * argv[]) {
pinyin_option_t options = USE_TONE | PINYIN_INCOMPLETE;
ChewingLargeTable largetable(options);
FacadePhraseIndex phrase_index;
FILE * gbfile = fopen("../../data/gb_char.table", "r");
if (NULL == gbfile) {
fprintf(stderr, "open gb_char.table failed!\n");
exit(ENOENT);
}
largetable.load_text(gbfile);
fseek(gbfile, 0L, SEEK_SET);
phrase_index.load_text(1, gbfile);
fclose(gbfile);
FILE * gbkfile = fopen("../../data/gbk_char.table", "r");
if (NULL == gbkfile) {
fprintf(stderr, "open gbk_char.table failed!\n");
exit(ENOENT);
}
largetable.load_text(gbkfile);
fseek(gbkfile, 0L, SEEK_SET);
phrase_index.load_text(2, gbkfile);
fclose(gbkfile);
MemoryChunk * new_chunk = new MemoryChunk;
largetable.store(new_chunk);
largetable.load(new_chunk);
char* linebuf = NULL; size_t size = 0;
while( getline(&linebuf, &size, stdin) ){
linebuf[strlen(linebuf)-1] = '\0';
if ( strcmp ( linebuf, "quit" ) == 0)
break;
FullPinyinParser2 parser;
ChewingKeyVector keys = g_array_new(FALSE, FALSE, sizeof(ChewingKey));
ChewingKeyRestVector key_rests =
g_array_new(FALSE, FALSE, sizeof(ChewingKeyRest));
parser.parse(options, keys, key_rests, linebuf, strlen(linebuf));
if (0 == keys->len) {
fprintf(stderr, "Invalid input.\n");
continue;
}
guint32 start = record_time();
PhraseIndexRanges ranges;
memset(ranges, 0, sizeof(PhraseIndexRanges));
guint8 min_index, max_index;
phrase_index.get_sub_phrase_range(min_index, max_index);
for (size_t i = min_index; i < max_index; ++i) {
ranges[i] = g_array_new(FALSE, FALSE, sizeof(PhraseIndexRange));
}
for (size_t i = 0; i < bench_times; ++i) {
largetable.search(keys->len, (ChewingKey *)keys->data, ranges);
}
for (size_t i = min_index; i < max_index; ++i) {
g_array_set_size(ranges[i], 0);
}
print_time(start, bench_times);
largetable.search(keys->len, (ChewingKey *)keys->data, ranges);
for (size_t i = min_index; i < max_index; ++i) {
GArray * & range = ranges[i];
if (range) {
if (range->len)
printf("range items number:%d\n", range->len);
for (size_t k = 0; k < range->len; ++k) {
PhraseIndexRange * onerange =
&g_array_index(range, PhraseIndexRange, k);
printf("start:%d\tend:%d\n", onerange->m_range_begin,
onerange->m_range_end);
PhraseItem item;
for ( phrase_token_t token = onerange->m_range_begin;
token != onerange->m_range_end; ++token){
phrase_index.get_phrase_item( token, item);
/* get phrase string */
gunichar2 buffer[MAX_PHRASE_LENGTH + 1];
item.get_phrase_string(buffer);
char * string = g_utf16_to_utf8
( buffer, item.get_phrase_length(),
NULL, NULL, NULL);
printf("%s\t", string);
g_free(string);
ChewingKey chewing_buffer[MAX_PHRASE_LENGTH];
size_t npron = item.get_n_pronunciation();
guint32 freq;
//.........这里部分代码省略.........
开发者ID:hollylee,项目名称:libpinyin,代码行数:101,代码来源:test_chewing_table.cpp
示例10: displayRunner
void displayRunner(const Trunner *runner) {
char recordCopy[6], timelagCopy[6];
print_time(runner->record, recordCopy); print_time(runner->time_lag, timelagCopy);
printf("%s- |record| %s |lag| %s\n", runner->name, recordCopy, timelagCopy);
}
开发者ID:LukasDagne,项目名称:Multilevel_Abstract_datatypes,代码行数:6,代码来源:runner.c
示例11: clump
//.........这里部分代码省略.........
*temp_clump = NEW;
}
/* modify the OLD index */
index[OLD] = NEW;
}
/* write initial clump IDs */
/* this works also with writing out cur_clump, but only
* prev_clump is complete and will not change any more */
if (row > 0) {
if (write(cfd, prev_clump + 1, csize) != csize)
G_fatal_error(_("Unable to write to temp file"));
}
/* switch the buffers so that the current buffer becomes the previous */
temp_cell = cur_in;
cur_in = prev_in;
prev_in = temp_cell;
temp_clump = cur_clump;
cur_clump = prev_clump;
prev_clump = temp_clump;
}
/* write last row with initial clump IDs */
if (write(cfd, prev_clump + 1, csize) != csize)
G_fatal_error(_("Unable to write to temp file"));
G_percent(1, 1, 1);
/* generate a renumbering scheme */
G_message(_("Generating renumbering scheme..."));
G_debug(1, "%d initial labels", label);
/* allocate final clump ID */
renumber = (CELL *) G_malloc((label + 1) * sizeof(CELL));
renumber[0] = 0;
cat = 1;
G_percent(0, label, 1);
for (n = 1; n <= label; n++) {
G_percent(n, label, 1);
OLD = n;
NEW = index[n];
if (OLD != NEW) {
renumber[n] = 0;
/* find valid clump ID */
while (OLD != NEW) {
OLD = NEW;
NEW = index[OLD];
}
index[n] = NEW;
}
else
/* set final clump id */
renumber[n] = cat++;
}
/* rewind temp file */
lseek(cfd, 0, SEEK_SET);
if (print) {
fprintf(stdout, "clumps=%d\n", cat - 1);
}
else {
/****************************************************
* PASS 2 *
* apply renumbering scheme to initial clump labels *
****************************************************/
/* the input raster is no longer needed,
* using instead the temp file with initial clump labels */
G_message(_("Pass 2 of 2..."));
for (row = 0; row < nrows; row++) {
G_percent(row, nrows, 4);
if (read(cfd, cur_clump, csize) != csize)
G_fatal_error(_("Unable to read from temp file"));
temp_clump = cur_clump;
temp_cell = out_cell;
for (col = 0; col < ncols; col++) {
*temp_cell = renumber[index[*temp_clump]];
if (*temp_cell == 0)
Rast_set_c_null_value(temp_cell, 1);
temp_clump++;
temp_cell++;
}
Rast_put_row(out_fd, out_cell, CELL_TYPE);
}
G_percent(1, 1, 1);
}
close(cfd);
unlink(cname);
print_time(&cur_time);
return 0;
}
开发者ID:caomw,项目名称:grass,代码行数:101,代码来源:clump.c
示例12: test_adjtime
void test_adjtime(void)
{
int sc;
rtems_status_code status;
struct timeval delta;
struct timeval olddelta;
rtems_time_of_day *the_tod;
rtems_time_of_day tod;
rtems_interval ticks;
the_tod = &Dates[0];
print_time( "rtems_clock_set ", the_tod, "\n" );
status = rtems_clock_set( the_tod );
rtems_test_assert( !status );
delta.tv_sec = 0;
delta.tv_usec = 0;
olddelta.tv_sec = 0;
olddelta.tv_usec = 0;
puts( "adjtime - NULL delta - EINVAL" );
sc = adjtime( NULL, &olddelta );
rtems_test_assert( sc == -1 );
rtems_test_assert( errno == EINVAL );
puts( "adjtime - delta out of range - EINVAL" );
delta.tv_usec = 1000000000; /* 100 seconds worth */
sc = adjtime( &delta, &olddelta );
rtems_test_assert( sc == -1 );
rtems_test_assert( errno == EINVAL );
puts( "adjtime - delta too small - do nothing" );
delta.tv_sec = 0;
delta.tv_usec = 1;
sc = adjtime( &delta, &olddelta );
rtems_test_assert( sc == 0 );
puts( "adjtime - delta too small - do nothing, olddelta=NULL" );
sc = adjtime( &delta, NULL );
rtems_test_assert( sc == 0 );
puts( "adjtime - delta of one second forward, olddelta=NULL" );
delta.tv_sec = 1;
delta.tv_usec = 0;
sc = adjtime( &delta, NULL );
rtems_test_assert( sc == 0 );
puts( "adjtime - delta of one second forward" );
delta.tv_sec = 1;
delta.tv_usec = 0;
sc = adjtime( &delta, &olddelta );
rtems_test_assert( sc == 0 );
puts( "adjtime - delta of almost two seconds forward" );
delta.tv_sec = 1;
delta.tv_usec = 1000000 - 1;
sc = adjtime( &delta, &olddelta );
rtems_test_assert( sc == 0 );
/*
* spin until over 1/2 of the way to the
*/
ticks = rtems_clock_get_ticks_per_second();
rtems_test_assert( ticks );
ticks /= 2;
do {
status = rtems_clock_get_tod( &tod );
rtems_test_assert( !status );
} while ( tod.ticks <= ticks );
puts( "adjtime - delta of almost one second forward which bumps second" );
delta.tv_sec = 0;
delta.tv_usec = 1000000 - 1;
sc = adjtime( &delta, &olddelta );
rtems_test_assert( sc == 0 );
status = rtems_clock_get_tod( &tod );
rtems_test_assert( !status );
print_time( "rtems_clock_get_tod ", &tod, "\n" );
}
开发者ID:chch1028,项目名称:rtems,代码行数:81,代码来源:test.c
示例13: main
int
main(int argc, char **cargv)
{
int dbdata_type = 0;
int yield = 0;
open_db dbblock;
open_db *dbm;
EXIM_CURSOR *cursor;
uschar **argv = USS cargv;
uschar *key;
uschar keybuffer[1024];
/* Check the arguments, and open the database */
dbdata_type = check_args(argc, argv, US"dumpdb", US"");
dbm = dbfn_open(argv[1], argv[2], O_RDONLY, &dbblock);
if (dbm == NULL) exit(1);
/* Scan the file, formatting the information for each entry. Note
that data is returned in a malloc'ed block, in order that it be
correctly aligned. */
key = dbfn_scan(dbm, TRUE, &cursor);
while (key != NULL)
{
dbdata_retry *retry;
dbdata_wait *wait;
dbdata_callout_cache *callout;
dbdata_ratelimit *ratelimit;
int count_bad = 0;
int i, length;
uschar *t;
uschar name[MESSAGE_ID_LENGTH + 1];
void *value;
/* Keep a copy of the key separate, as in some DBM's the pointer is into data
which might change. */
if (Ustrlen(key) > sizeof(keybuffer) - 1)
{
printf("**** Overlong key encountered: %s\n", key);
return 1;
}
Ustrcpy(keybuffer, key);
value = dbfn_read_with_length(dbm, keybuffer, &length);
if (value == NULL)
fprintf(stderr, "**** Entry \"%s\" was in the key scan, but the record "
"was not found in the file - something is wrong!\n",
CS keybuffer);
else
{
/* Note: don't use print_time more than once in one statement, since
it uses a single buffer. */
switch(dbdata_type)
{
case type_retry:
retry = (dbdata_retry *)value;
printf(" %s %d %d %s\n%s ", keybuffer, retry->basic_errno,
retry->more_errno, retry->text,
print_time(retry->first_failed));
printf("%s ", print_time(retry->last_try));
printf("%s %s\n", print_time(retry->next_try),
(retry->expired)? "*" : "");
break;
case type_wait:
wait = (dbdata_wait *)value;
printf("%s ", keybuffer);
t = wait->text;
name[MESSAGE_ID_LENGTH] = 0;
if (wait->count > WAIT_NAME_MAX)
{
fprintf(stderr,
"**** Data for %s corrupted\n count=%d=0x%x max=%d\n",
CS keybuffer, wait->count, wait->count, WAIT_NAME_MAX);
wait->count = WAIT_NAME_MAX;
yield = count_bad = 1;
}
for (i = 1; i <= wait->count; i++)
{
Ustrncpy(name, t, MESSAGE_ID_LENGTH);
if (count_bad && name[0] == 0) break;
if (Ustrlen(name) != MESSAGE_ID_LENGTH ||
Ustrspn(name, "0123456789"
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ-") != MESSAGE_ID_LENGTH)
{
int j;
fprintf(stderr,
"**** Data for %s corrupted: bad character in message id\n",
CS keybuffer);
for (j = 0; j < MESSAGE_ID_LENGTH; j++)
fprintf(stderr, "%02x ", name[j]);
fprintf(stderr, "\n");
yield = 1;
break;
}
//.........这里部分代码省略.........
开发者ID:hillu,项目名称:exim,代码行数:101,代码来源:exim_dbutil.c
示例14: print_station
void print_station(struct station s) {
printf("%s\t", s.station_name);
print_time(s.arrival_time);
printf("\n");
}
开发者ID:ArturAmbartsumov,项目名称:TP_Cpp,代码行数:5,代码来源:HomeTask4V13.c
示例15: run_main
int
run_main (int argc, ACE_TCHAR *argv[])
{
ACE_START_TEST (ACE_TEXT ("Naming_Test"));
ACE_TCHAR temp_file [BUFSIZ];
ACE_Naming_Context *ns_context = 0;
ACE_NEW_RETURN (ns_context, ACE_Naming_Context, -1);
ACE_Name_Options *name_options = ns_context->name_options ();
name_options->parse_args (argc, argv);
/*
** NOTE! This is an experimental value and is not magic in any way. It
** works for me, on one system. It's needed because in the particular
** case here where the underlying mmap will allocate a small area and
** then try to grow it, it always moves it to a new location, which
** totally screws things up. I once tried forcing the realloc to do
** MAP_FIXED but that's not a good solution since it may overwrite other
** mapped areas of memory, like the heap, or the C library, and get very
** unexpected results. (Steve Huston, 24-August-2007)
*/
# if defined (linux) && defined (__x86_64__)
name_options->base_address ((char*)0x3c00000000);
#endif
bool unicode = false;
#if (defined (ACE_WIN32) && defined (ACE_USES_WCHAR))
unicode = true;
#endif /* ACE_WIN32 && ACE_USES_WCHAR */
if (unicode && name_options->use_registry () == 1)
{
name_options->namespace_dir (ACE_TEXT ("Software\\ACE\\Name Service"));
name_options->database (ACE_TEXT ("Version 1"));
}
else
{
const ACE_TCHAR* pname = ACE::basename (name_options->process_name (),
ACE_DIRECTORY_SEPARATOR_CHAR);
// Allow the user to determine where the context file will be
// located just in case the current directory is not suitable for
// locking. We don't just set namespace_dir () on name_options
// because that is not sufficient to work around locking problems
// for Tru64 when the current directory is NFS mounted from a
// system that does not properly support locking.
ACE_TCHAR temp_dir [MAXPATHLEN];
if (ACE::get_temp_dir (temp_dir, MAXPATHLEN - 15) == -1)
// -15 for ace-file-XXXXXX
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("Temporary path too long, ")
ACE_TEXT ("defaulting to current directory\n")),
-1);
}
else
{
ACE_OS::chdir (temp_dir);
}
ACE_OS::strcpy (temp_file, pname);
ACE_OS::strcat (temp_file, ACE_TEXT ("XXXXXX"));
// Set the database name using mktemp to generate a unique file name
name_options->database (ACE_OS::mktemp (temp_file));
}
if (ns_context->open (ACE_Naming_Context::PROC_LOCAL, 1) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("ns_context->open (PROC_LOCAL) %p\n"),
ACE_TEXT ("failed")),
-1);
}
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("time to test %d iterations using %s\n"),
ACE_NS_MAX_ENTRIES, name_options->use_registry () ?
ACE_TEXT ("Registry") : ACE_TEXT ("ACE")));
ACE_Profile_Timer timer;
timer.start ();
// Add some bindings to the database
test_bind (*ns_context);
print_time (timer, "Binds");
timer.start ();
// Should find the entries
test_find (*ns_context, 1, 0);
print_time (timer, "Successful Finds");
timer.start ();
// Rebind with negative values
test_rebind (*ns_context);
print_time (timer, "Rebinds");
timer.start ();
// Should find the entries
test_find (*ns_context, -1, 0);
print_time (timer, "Successful Finds");
timer.start ();
// Should not find the entries
test_find_failure (*ns_context);
//.........这里部分代码省略.........
开发者ID:helixum,项目名称:wow-cata,代码行数:101,代码来源:Naming_Test.cpp
示例16: a2dp_sig_thread
static void a2dp_sig_thread(void *d) {
struct bluetooth_data *data = d;
a2dp_state_t state = data->state;
int err = 0;
struct timeval tv;
struct timespec ts;
#ifdef ENABLE_TIMING
uint64_t begin, end;
begin = get_microseconds();
#endif
gettimeofday(&tv, (struct timezone *) NULL);
ts.tv_sec = tv.tv_sec + (WRITE_TIMEOUT / 1000);
ts.tv_nsec = (tv.tv_usec + (WRITE_TIMEOUT % 1000) * 1000L ) * 1000L;
pthread_mutex_lock(&data->mutex);
while (state != A2DP_STATE_STARTED) {
if (state == A2DP_STATE_NONE)
__set_command(data, A2DP_CMD_INIT);
else if (state == A2DP_STATE_INITIALIZED)
__set_command(data, A2DP_CMD_CONFIGURE);
else if (state == A2DP_STATE_CONFIGURED) {
__set_command(data, A2DP_CMD_START);
}
again:
err = pthread_cond_timedwait(&data->client_wait, &data->mutex, &ts);
if (err) {
/* don't timeout if we're done */
if (data->state == A2DP_STATE_STARTED) {
err = 0;
break;
}
if (err == ETIMEDOUT) {
DBG(" Time out");
break;
}
goto again;
}
if (state == data->state)
goto again;
state = data->state;
if (state == A2DP_STATE_NONE) {
err = ENODEV;
break;
}
}
pthread_mutex_unlock(&data->mutex);
#ifdef ENABLE_TIMING
end = get_microseconds();
print_time("signalling process took", begin, end);
#endif
data->signalling_thread = 0;
DBG("error returned is %d", err);
/* pthread_cond_timedwait returns positive errors */
return;
}
开发者ID:OmarBizreh,项目名称:Sliding_XZ,代码行数:61,代码来源:liba2dp.c
示例17: switch
bool SerialLineIn::dispatch(void)
{
bool handled = false;
DateTime now = RTC.nowDateTime();
switch (toupper(*buf))
{
case 'D':
// Dyymmdd: Set date
handled = true;
if ( strlen(buf) == 1 )
{
print_time();
break;
}
if ( strlen(buf) != 7 )
{
printf_P(PSTR("SERL Format: Dyymmdd\n\r"));
break;
}
now = DateTime(2000+conv2d(buf+1),conv2d(buf+3),conv2d(buf+5),now.hour(),now.minute(),now.second());
RTC.adjust(now);
print_time();
break;
case 'T':
// Thhmmss: Set time
handled = true;
if ( strlen(buf) != 7 )
{
printf_P(PSTR("SERL Format: Dyymmdd\n\r"));
break;
}
now = DateTime(now.year(),now.month(),now.day(),conv2d(buf+1),conv2d(buf+3),conv2d(buf+5));
RTC.adjust(now);
print_time();
break;
case '@':
handled = true;
// Special time values
if ( !strcmp(buf+1,"N") )
{
uint32_t when = events.whenNext();
#ifdef HAVE_FIRE_CAMERA
if ( fire_camera.is_valid() )
when = fire_camera.whenNext();
#endif
RTC.adjust(when);
print_time();
}
else if ( !strcmp(buf+1,"1") )
{
events.reset();
#ifdef HAVE_FIRE_CAMERA
fire_camera.invalidate();
#endif
RTC.adjust(events.whenNext());
print_time();
}
else if ( !strcmp(buf+1,"0") )
{
RTC.adjust(DateTime(2011,1,1,0,0,0).unixtime());
print_time();
}
else
printf_P(PSTR("SERL Error: Unknown @ value: %s"),buf+1);
break;
case 'E':
// E: Print EEPROM
handled = true;
logger.play();
break;
case 'F':
// F: Free memory
handled = true;
printf_P(PSTR("FREE %u\n\r"),freeMemory());
break;
}
return handled;
}
开发者ID:CNCBASHER,项目名称:TheCameraMachine,代码行数:81,代码来源:SerialLineIn.cpp
示例18: avdtp_write
static int avdtp_write(struct bluetooth_data *data)
{
int ret = 0;
struct rtp_header *header;
struct rtp_payload *payload;
uint64_t now;
long duration = data->frame_duration * data->frame_count;
#ifdef ENABLE_TIMING
uint64_t begin, end, begin2, end2;
begin = get_microseconds();
#endif
header = (struct rtp_header *)data->buffer;
payload = (struct rtp_payload *)(data->buffer + sizeof(*header) + data->sizeof_scms_t);
memset(data->buffer, 0, sizeof(*header) + sizeof(*payload) + data->sizeof_scms_t);
if (data->sizeof_scms_t) {
data->buffer[sizeof(*header)] = data->scms_t_cp_header;
}
payload->frame_count = data->frame_count;
header->v = 2;
header->pt = 1;
header->sequence_number = htons(data->seq_num);
header->timestamp = htonl(data->nsamples);
header->ssrc = htonl(1);
data->stream.revents = 0;
#ifdef ENABLE_TIMING
begin2 = get_microseconds();
#endif
ret = poll(&data->stream, 1, POLL_TIMEOUT);
#ifdef ENABLE_TIMING
end2 = get_microseconds();
print_time("poll", begin2, end2);
#endif
long ahead = 0;
now = get_microseconds();
if (data->next_write) {
ahead = data->next_write - now;
#ifdef EN
|
请发表评论