Пример #1
0
int main() {
	sleep_for();
	
	sleep_until();
	
	return 0;
}
Пример #2
0
void displaytext_delay(std::ifstream& File)
{
    std::string Lines = "";
    int j=0;
    sleep_for(seconds(3));
    if (File)
    {
		while (File.good ())
		{
			std::string TempLines;
			std::getline (File , TempLines);
			TempLines += "\n";
			char myArray[TempLines.size()+1];
			strcpy(myArray, TempLines.c_str());
				for (int i=0; i<TempLines.size();i++)
				{
				mvaddch(j,(40+i),myArray[i]);
				refresh();
				sleep_for(milliseconds(50));
				}
			j=j+1;
			refresh();
			sleep_until(system_clock::now() + seconds(1));
		}
		printw("###################$$$$$$$$$$$$$$$$###################\n");
		printw("                   WELCOME TO DORK\n");
		printw("###################$$$$$$$$$$$$$$$$###################\n");
    }
    else                           //Return error
    {
	cout<< "ERROR File does not exist.";
    }
}
Пример #3
0
static void system_monitor_thread(void *arg)
{
  (void)arg;
  chRegSetThreadName("system monitor");

  systime_t time = chVTGetSystemTime();

  bool ant_status = 0;

  while (TRUE) {

    if (ant_status != frontend_ant_status()) {
      ant_status = frontend_ant_status();
      if (ant_status && frontend_ant_setting() == AUTO) {
        log_info("Now using external antenna.");
      }
      else if (frontend_ant_setting() == AUTO) {
        log_info("Now using patch antenna.");
      }
    }
    u32 status_flags = ant_status << 31 | SBP_MAJOR_VERSION << 16 | SBP_MINOR_VERSION << 8;
    sbp_send_msg(SBP_MSG_HEARTBEAT, sizeof(status_flags), (u8 *)&status_flags);

    /* If we are in base station mode then broadcast our known location. */
    if (broadcast_surveyed_position && position_quality == POSITION_FIX) {
      double tmp[3];
      double base_ecef[3];
      double base_distance;

      llhdeg2rad(base_llh, tmp);
      wgsllh2ecef(tmp, base_ecef);

      vector_subtract(3, base_ecef, position_solution.pos_ecef, tmp);
      base_distance = vector_norm(3, tmp);

      if (base_distance > BASE_STATION_DISTANCE_THRESHOLD) {
        log_warn("Invalid surveyed position coordinates\n");
      } else {
        sbp_send_msg(SBP_MSG_BASE_POS_ECEF, sizeof(msg_base_pos_ecef_t), (u8 *)&base_ecef);
      }
    }

    msg_iar_state_t iar_state;
    if (simulation_enabled_for(SIMULATION_MODE_RTK)) {
      iar_state.num_hyps = 1;
    } else {
      iar_state.num_hyps = dgnss_iar_num_hyps();
    }
    sbp_send_msg(SBP_MSG_IAR_STATE, sizeof(msg_iar_state_t), (u8 *)&iar_state);
    
    DO_EVERY(2, 
     send_thread_states(); 
    );

    sleep_until(&time, MS2ST(heartbeat_period_milliseconds));
  }
Пример #4
0
void task_body (void *cookie)
{
    struct timespec ts;
    unsigned int delay = 1000*1000; // Note: Delay in ns
    FILE *pin0 = init_gpio(18);
    FILE *pin1 = init_gpio(23);
    FILE *pin2 = init_gpio(24);
    FILE *pin3 = init_gpio(25);

    signal(SIGINT, dumptimestamps);
    clock_gettime(CLOCK_MONOTONIC, &ts);

    // Lock memory to ensure no swapping is done.
    if(mlockall(MCL_FUTURE|MCL_CURRENT)) {
        fprintf(stderr,"WARNING: Failed to lock memory\n");
    }

    // Set our thread to real time priority
//       struct sched_param sp;
//       sp.sched_priority = 30;
//       if(pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp)){
//                fprintf(stderr,"WARNING: Failed to set stepper thread"
//                       "to real-time priority\n");
//       }

    while(1) {

        sleep_until(&ts,delay);
        logtimestamp();
        setiopin(pin0,1);
        sleep_until(&ts,delay);
        logtimestamp();
        setiopin(pin3,0);
        sleep_until(&ts,delay);
        logtimestamp();
        setiopin(pin1,1);
        sleep_until(&ts,delay);
        logtimestamp();
        setiopin(pin0,0);
        sleep_until(&ts,delay);
        logtimestamp();
        setiopin(pin2,1);
        sleep_until(&ts,delay);
        logtimestamp();
        setiopin(pin1,0);
        sleep_until(&ts,delay);
        logtimestamp();
        setiopin(pin3,1);
        sleep_until(&ts,delay);
        logtimestamp();
        setiopin(pin2,0);
    }
}
Пример #5
0
int main()
{
    auto now = Clock::now();
    auto start_time = now;
    auto should_wakeup_time = now + std::chrono::milliseconds(1);
    auto actual_wakeup_time = sleep_until(now, should_wakeup_time);
    auto time_slept = std::chrono::duration_cast<std::chrono::nanoseconds>(actual_wakeup_time - start_time).count();
    auto error = std::chrono::duration_cast<std::chrono::nanoseconds>(actual_wakeup_time - should_wakeup_time).count();
    std::cout << "Woke up after " << time_slept << " nanoseconds. This is " << error << " ns too late";;
}
static int wait_for_next_period( void )
{
    if( sleep_until( next_period ) )
    {
        fprintf( stderr, "error in sleep_until\n" );
        exit( 1 );
    }

    next_period += us_period;
    return( 0 );
}
Пример #7
0
struct chirp_file * chirp_reli_open( const char *host, const char *path, INT64_T flags, INT64_T mode, time_t stoptime )
{
	struct chirp_file *file;
	int     delay=0;
	time_t  nexttry;
	INT64_T result;
	struct chirp_stat buf;
	time_t current;

	while(1) {
		struct chirp_client *client = connect_to_host(host,stoptime);
		if(client) {
			result = chirp_client_open(client,path,flags,mode,&buf,stoptime);
			if(result>=0) {
				file = xxmalloc(sizeof(*file));
				strcpy(file->host,host);
				strcpy(file->path,path);
				memcpy(&file->info,&buf,sizeof(buf));
				file->fd = result;
				file->flags = flags & ~(O_CREAT|O_TRUNC);
				file->mode = mode;
				file->serial = chirp_client_serial(client);
				file->stale = 0;
				file->buffer = malloc(chirp_reli_blocksize);
				file->buffer_offset = 0;
				file->buffer_valid = 0;
				file->buffer_dirty = 0;
				return file;
			} else {
				if(errno!=ECONNRESET) return 0;
			}
	 		invalidate_host(host);
		} else {
			if(errno==ENOENT) return 0;
		}
		if(time(0)>=stoptime) {
			errno = ECONNRESET;
			return 0;
		}
		if(delay>=2) debug(D_NOTICE,"couldn't connect to %s: still trying...\n",host);
		debug(D_CHIRP,"couldn't talk to %s: %s\n",host,strerror(errno));
		current = time(0);
		nexttry = MIN(stoptime,current+delay);
		debug(D_CHIRP,"try again in %d seconds\n",(int)(nexttry-current));
		sleep_until(nexttry);
		if(delay==0) {
			delay = 1;
		} else {
			delay = MIN(delay*2,MAX_DELAY);
		}
	}
}
Пример #8
0
static void xtest_a(void * data, char * name) {
	fs_node_t * tty = data;

	fprintf(tty, "[%s] Hello world.\n", name);

	while (1) {
		fprintf(tty, "[%s] Ping.\n", name);
		unsigned long s, ss;
		relative_time(1, 0, &s, &ss);
		sleep_until((process_t *)current_process, s, ss);
		switch_task(0);
	}
}
Пример #9
0
void print_hours(event prev, event next) {
	int hour;
	double len = difftime(next.stamp, prev.stamp) / HOURS;
	time_t stamp;
	
	for (hour = 0; hour < HOURS; hour++) {
		stamp = prev.stamp + (time_t)(hour * len);
		if (is_old(stamp))
			continue;

		sleep_until(stamp);
		puts(MESSAGES[hour + prev.type * HOURS]);
		fflush(stdout);
	}
}
Пример #10
0
bool8
S9xDeinitUpdate (int Width, int Height, bool8 sixteen_bit)
{
	if(settings.ui.s9x_vsync)
		BScreen().WaitForRetrace();
	switch(settings.ui.s9x_drawmode) {
		case DIRECT:
			s9x->DrawDirect(Width, Height);
			break;
		case OVERLAY:
			s9x->DrawOverlay(Width, Height);
			break;
		case BITMAP:
			s9x->DrawStandard(Width, Height);
			break;
	}
	if(settings.ui.s9x_snooze)
		sleep_until();
	asm("emms");
	return (true);
}
Пример #11
0
int main(int argc, char *argv[])
{
	int rv;
	struct pktbuf *p;
	cat_time_t pts, now, next, nnext, start_time, start_ts = { 0 };
	struct xpkt_tag_ts *ts;
	int infd = 0;
	int outfd = 1;
	ulong bits;

	pkb_init_pools(1);

	parse_args(argc, argv, &infd, &outfd);

	now = tm_uget();
	if (g_start_delay > 0) {
		next = tm_add(now, tm_dset(g_start_delay));
		sleep_until(&next, &now);
	}
	start_time = now;
	next = now;


	while ((rv = pkb_fd_read_a(&p, infd, NULL, NULL)) > 0) {
		now = tm_uget();
		++g_npkts;

		if (g_interval > 0.0) {
			nnext = tm_add(next, tm_dset(g_interval));
			sleep_until(&next, &now);
			next = nnext;
		} else if (g_bps > 1.0) {
			bits = pkb_get_len(p) * 8;
			nnext = tm_add(next, tm_dset(bits / g_bps));
			sleep_until(&next, &now);
			next = nnext;
		} else {
			ts = (struct xpkt_tag_ts *)
				pkb_find_tag(p, XPKT_TAG_TIMESTAMP, 0);

			if ( ts == NULL ) {
				fprintf(stderr,
					"no timestamp on packet %lu: sending\n",
					g_npkts);
				goto send;
			}

			pts = tm_lset(ts->sec, ts->nsec);
			if (tm_ltz(pts)) {
				fprintf(stderr,
					"Invalid timestamp on packet %lu "
					"(%ld,%ld)\n",
					g_npkts, tm_sec(pts), tm_nsec(pts));
				pkb_free(p);
				continue;
			}

			if (g_npkts == 1)
				start_ts = pts;

			next = tm_add(tm_sub(pts, start_ts), start_time);
			sleep_until(&next, &now);
		}

send:
		rv = pkb_pack(p);
		abort_unless(rv == 0);
		if (pkb_fd_write(p, outfd) < 0)
			errsys("Error writing packet %lu", g_npkts);
		pkb_free(p);
	}
	if (rv < 0)
		errsys("Error reading packet %lu: ", g_npkts + 1);

	return 0;
}
Пример #12
0
void *stepperThread(void *arg) {
	struct stepper *step = (struct stepper *)arg;
        struct timespec ts;
        struct sched_param sp;
	// local variables
	struct stepperMessage *sm;
	int smPriority;
	unsigned int pulseLen = 0, pulseLenTarget = 0;
	int stepCurrent = 0, stepTarget = 0;
	uint8_t homed[2] = { 0, 0 };
	unsigned int limit[2] = { 0, 0 }, center = 0;
	int seqIndex = 0;
	uint8_t moveInProgress = 0;

	// enable real time priority for this thread
        sp.sched_priority = 30;
        if(pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp)){
		warning("unable to set stepper thread to realtime priority\n");
        }

	// initialize monotonically increasing clock
        clock_gettime(CLOCK_MONOTONIC, &ts);
        ts.tv_nsec = 0;

	// start in the powered down state
	printf("stepper alive: %d - %d - %d - %d\n", step->pins[0], step->pins[1], step->pins[2], step->pins[3]);
	stepperPowerDown(step);

	// notify core we are ready
	sem_post(&step->semRT);
	
        while(1) {
		pthread_mutex_lock(&step->msgQueueMutex);
		sm = priq_top(step->msgQueue, &smPriority);
		// if there is a message and it is high priority or we have no move in progress then
		// pop it and prepare to process it
		if (sm && (smPriority == PRIQ_HIGH || !moveInProgress))
			sm = priq_pop(step->msgQueue, &smPriority);
		else
			sm = NULL;
		pthread_mutex_unlock(&step->msgQueueMutex);

		// nothing to do	
		if (!sm) {
			sleep_until(&ts, DEFAULT_SLEEP);
			continue;
		}	

		switch (sm->msg) {
			case STEPPER_EXIT:
				stepperPowerDown(step);
				stepperCleanup(step);
				pthread_exit(0);
				break;
			case STEPPER_MSG_QUEUE_FLUSH:{
				int i;
				struct stepperMessage sm;
				for (i = 0; sm != NULL; ++i) {
					sm = priq_pop(step->msgQueue, 0);
					if (sm != NULL)
						free(sm);
				}
				printf("flushed %d messages from queue\n", i);
				}
				break;
			case STEPPER_STATUS:
				pthread_mutex_lock(&step->mutex);
				step->stepCurrent = stepCurrent;
				step->stepTarget = stepTarget;
				step->pulseLen = pulseLen;
				step->pulseLenTarget = pulseLenTarget;
				step->homed[0] = homed[0];
				step->homed[1] = homed[1];
				step->limit[0] = limit[0];
				step->limit[1] = limit[1];
				step->center = center;
				pthread_mutex_unlock(&step->mutex);
				// ack
                        	sem_post(&step->semRT);
				break;
			case STEPPER_STOP:
				stepTarget = stepCurrent;
				pulseLen = 0;
				break;
			case STEPPER_PWR_DN:
				stepperPowerDown(step);
				break;
			case STEPPER_MOVE_TO:
				pthread_mutex_lock(&step->mutex);
				pulseLenTarget = step->pulseLenTarget;
				printf("move_to\t%d\t%d\t%d\n", step->index, step->stepTarget, step->pulseLenTarget);
				if (homed[0] && homed[1]) {
					if (step->stepTarget >= limit[0] && step->stepTarget <= limit[1])
						stepTarget = step->stepTarget;
					else {
						if (step->stepTarget < limit[0]) {
							stepTarget = limit[0];
							warning("request for position less than homed range (%d)\n", step->stepTarget);
						} else {
							stepTarget = limit[1];
							warning("request for position larger than homed range (%d)\n", step->stepTarget);
						}
					}
				} else {
					stepTarget = step->stepTarget;
					warning("moving on unhomed axis to %d\n", stepTarget);
				}
				pthread_mutex_unlock(&step->mutex);
				coreIncrementMovesInProgress(step->index);
				moveInProgress = 1;
				break;
			case STEPPER_UNHOME:
				homed[0] = 0;
				homed[1] = 0;
				limit[0] = 0;
				limit[1] = 0;
				break;
			case STEPPER_HOME_MIN:
				stepperPowerDown(step);
				coreDecrementMovesInProgress(step->index);
				homed[0] = 1;
				limit[0] = 0;
				stepCurrent = 0;
				stepTarget = 0;
				command = STEPPER_PWR_DN;
				printf("stepper homed min (pins %d - %d - %d - %d)\n", step->pins[0], step->pins[1], step->pins[2], step->pins[3]);
				break;
			case STEPPER_HOME_MAX:
				stepperPowerDown(step);
				coreDecrementMovesInProgress(step->index);
				if (homed[0]) {
					homed[1] = 1;
					limit[1] = stepCurrent;
					center = (limit[1] - limit[0]) / 2;
					pthread_mutex_lock(&step->mutex);
					step->center = center;
					pthread_mutex_unlock(&step->mutex);
					stepTarget = 0;
					printf("stepper homed max at %d steps (pins %d - %d - %d - %d)\n", stepCurrent, step->pins[0], step->pins[1], step->pins[2], step->pins[3]);
				} else {
					warning("cannot home max before homing min!\n");
				}
				command = STEPPER_PWR_DN;
				break;
			default:
				fatal_error("unexpected message for stepper thread\n");
				break;
			};
		}
		if (moveInProgress) {
#ifdef SPEED_RAMP
			// accelerate or deccelerate
			if (pulseLen == 0)
				pulseLen = pulseLenTarget;
			if (pulseLenTarget < pulseLen) {
				pulseLen -= 1000;
				if (pulseLen < pulseLenTarget)
					pulseLen = pulseLenTarget;
			} else if (pulseLenTarget > pulseLen) {
				pulseLen += 1000;
				if (pulseLen > pulseLenTarget)
					pulseLen = pulseLenTarget;
			}
#else
			pulseLen = pulseLenTarget;
#endif
			if (stepTarget < stepCurrent) {
				seqIndex--;
				if (seqIndex < 0)
					seqIndex = STEPPER_SEQUENCE_N - 1;
				stepCurrent--;
			} else if (stepTarget > stepCurrent) {
				seqIndex++;
				if (seqIndex > STEPPER_SEQUENCE_N - 1)
					seqIndex = 0;
				stepCurrent++;
			} else {
				printf("stepper %d reached target step %d\n", step->index, stepTarget);
				moveInProgress = 0;
#warning "do we really want to power down?"
#warning "this only works because core is the only thread updating this?"
				stepperPowerDown(step);
				coreDecrementMovesInProgress(step->index);
			}
			if (moveInProgress) {
				for (int i = 0; i < 4; ++i) {
					gpio_write(step->pins[i], stepSequence[seqIndex][i]);
				}
				sleep_until(&ts, pulseLen);
			} else
				sleep_until(&ts, DEFAULT_SLEEP);
		} else {
			sleep_until(&ts, DEFAULT_SLEEP);
		}
        }
Пример #13
0
void sleep_for(time_t interval)
{
	return sleep_until(time(0) + interval);
}
Пример #14
0
TEST(TimeUtils, SleepUntil) {
  Time start = now();
  sleep_until(start + .5 * s);
  ASSERT_NEAR(now().to(s), start.to(s) + .5, .01);
}
Пример #15
0
int main(int argc, char** argv) {
  width = 12, depth = 8, height = 60;
  xd = (width - 1) / 2.4;
  yd = (depth - 1) / 1.6;
  zd = (height - 1) / 2.0;
  xl = (width - 1) / xd;
  yl = (depth - 1) / yd;
  zl = (height - 1) / zd;
  total_leds = width * depth * height;
  channel = 0;

  fps = 60;
  period_x = xl / (2 * M_PI);
  speed_x = 1.0 / fps;
  period_y = yl / (2 * M_PI);
  speed_y = 0.9 / fps;
  period_z = zl / (2 * M_PI);
  speed_z = 0.8 / fps;

  sphere_r = .3;
  spheres = sqrt(pow(xl/2, 2) + pow(yl/2, 2) + pow(zl/2, 2)) / sphere_r;
  spheres += 2;
  frames_per_layer = fps / 2;
  pixel l_sphere_colors[spheres];
  sphere_colors = l_sphere_colors;
  int i;
  for (i = 0; i < spheres; i++) {
    sphere_colors[i] = randcolor();
  }

  pixel pixels[total_leds + 1];
  opc_sink s;

  if (argc < 2) {
    fprintf(stderr, "Usage: %s <server>[:<port>]\n", argv[0]);
    return 1;
  }

  s = opc_new_sink(argv[1]);

  int64_t frame_index = 0;
  int64_t start = now();
  struct fps_queue fpsq;
  int64_t frames[total_leds];
  fpsq.samples = fps;
  fpsq.pos = 0;
  fpsq.frames = frames;
  while (1) {
    sleep_until(start + 1000000 * frame_index / fps);
    render_frame(pixels, frame_index);
    if (!opc_put_pixels(s, channel, total_leds, pixels)) {
      break;
    }
    record_frame(&fpsq);
    if (fpsq.pos == 0) {
      double cur_fps = (fpsq.samples - 1) / (get_elapsed(&fpsq) / 1000000.0);
      printf("fps: %.2f  (%.2f Mbps)\n",
	     cur_fps, total_leds * 24 * cur_fps / 1000000.0);
    }
    frame_index++;
  }
  printf("fps: %f\n", frame_index / 5.0);
}
Пример #16
0
int
main(int argc, char *argv[])
{
	int		c;
	int		i, j;		/* Generic counters */
	int		nentities_found;
	int		linesout = 0;	/* Keeps track of lines printed */
	int		printhdr = 0;	/* Print a header?  0 = no, 1 = yes */
	int		nfstypes;	/* Number of fstypes */
	int		dispflag = 0;	/* Flags for display control */
	long		count = 0;	/* Number of iterations for display */
	int		forever; 	/* Run forever */
	long		interval = 0;
	boolean_t	fstypes_only = B_FALSE;	/* Display fstypes only */
	char		**fstypes;	/* Array of names of all fstypes */
	int		nentities;	/* Number of stat-able entities */
	entity_t	*entities;	/* Array of stat-able entities */
	kstat_ctl_t	*kc;
	void (*dfunc)(char *, vopstats_t *, vopstats_t *, int) = dflt_display;
	hrtime_t	start_n;	/* Start time */
	hrtime_t	period_n;	/* Interval in nanoseconds */

	extern int	optind;

	(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
#define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it weren't */
#endif
	(void) textdomain(TEXT_DOMAIN);

	/* Don't let buffering interfere with piped output. */
	(void) setvbuf(stdout, NULL, _IOLBF, 0);

	cmdname = argv[0];
	while ((c = getopt(argc, argv, OPTIONS)) != EOF) {
		switch (c) {

		default:
			usage();
			break;

		case 'F':	/* Only display available FStypes */
			fstypes_only = B_TRUE;
			break;

#if PARSABLE_OUTPUT
		case 'P':	/* Parsable output */
			dispflag |= DISP_RAW;
			break;
#endif /* PARSABLE_OUTPUT */

		case 'T':	/* Timestamp */
			if (optarg) {
				if (strcmp(optarg, "u") == 0) {
					timestamp_fmt = UDATE;
				} else if (strcmp(optarg, "d") == 0) {
					timestamp_fmt = DDATE;
				}
			}

			/* If it was never set properly... */
			if (timestamp_fmt == NODATE) {
				(void) fprintf(stderr, gettext("%s: -T option "
				    "requires either 'u' or 'd'\n"), cmdname);
				usage();
			}
			break;

		case 'a':
			set_dispfunc(&dfunc, attr_display);
			break;

		case 'f':
			set_dispfunc(&dfunc, vop_display);
			break;

		case 'i':
			set_dispfunc(&dfunc, io_display);
			break;

		case 'n':
			set_dispfunc(&dfunc, naming_display);
			break;

		case 'v':
			set_dispfunc(&dfunc, vm_display);
			break;
		}
	}

#if PARSABLE_OUTPUT
	if ((dispflag & DISP_RAW) && (timestamp_fmt != NODATE)) {
		(void) fprintf(stderr, gettext(
		    "-P and -T options are mutually exclusive\n"));
		usage();
	}
#endif /* PARSABLE_OUTPUT */

	/* Gather the list of filesystem types */
	if ((nfstypes = build_fstype_list(&fstypes)) == 0) {
		(void) fprintf(stderr,
		    gettext("Can't build list of fstypes\n"));
		exit(1);
	}

	nentities = parse_operands(
	    argc, argv, optind, &interval, &count, &entities);
	forever = count == MAXLONG;
	period_n = (hrtime_t)interval * NANOSEC;

	if (nentities == -1)	/* Set of operands didn't parse properly  */
		usage();

	if ((nentities == 0) && (fstypes_only == B_FALSE)) {
		(void) fprintf(stderr, gettext(
		    "Must specify -F or at least one fstype or mount point\n"));
		usage();
	}

	if ((nentities > 0) && (fstypes_only == B_TRUE)) {
		(void) fprintf(stderr, gettext(
		    "Cannot use -F with fstypes or mount points\n"));
		usage();
	}

	/*
	 * If we had no operands (except for interval/count) and we
	 * requested FStypes only (-F), then fill in the entities[]
	 * array with all available fstypes.
	 */
	if ((nentities == 0) && (fstypes_only == B_TRUE)) {
		if ((entities = calloc(nfstypes, sizeof (entity_t))) == NULL) {
			perror("calloc() fstype stats");
			exit(1);
		}

		for (i = 1; i < nfstypes; i++) {
			if (fstypes[i]) {
				entities[nentities].e_name = strdup(fstypes[i]);
				nentities++;
			}
		}
	}

	set_ksnames(entities, nentities, fstypes, nfstypes);

	if ((kc = kstat_open()) == NULL) {
		perror("kstat_open");
		exit(1);
	}

	/* Set start time */
	start_n = gethrtime();

	/* Initial timestamp */
	if (timestamp_fmt != NODATE) {
		print_timestamp(timestamp_fmt);
		linesout++;
	}

	/*
	 * The following loop walks through the entities[] list to "prime
	 * the pump"
	 */
	for (j = 0, printhdr = 1; j < nentities; j++) {
		entity_t *ent = &entities[j];
		vopstats_t *vsp = &ent->e_vs[CUR_INDEX];
		kstat_t *ksp = NULL;

		if (get_vopstats(kc, ent->e_ksname, vsp, &ksp) == 0) {
			(*dfunc)(ent->e_name, NULL, vsp,
			    dispflag_policy(printhdr, dispflag));
			linesout++;
		} else {
			/*
			 * If we can't find it the first time through, then
			 * get rid of it.
			 */
			entities[j].e_ksname[0] = 0;

			/*
			 * If we're only displaying FStypes (-F) then don't
			 * complain about any file systems that might not
			 * be loaded.  Otherwise, let the user know that
			 * they chose poorly.
			 */
			if (fstypes_only == B_FALSE) {
				(void) fprintf(stderr, gettext(
				    "No statistics available for %s\n"),
				    entities[j].e_name);
			}
		}
		printhdr = 0;
	}

	if (count > 1)
		/* Set up signal handler for SIGCONT */
		if (signal(SIGCONT, cont_handler) == SIG_ERR)
			fail(1, "signal failed");


	BUMP_INDEX();	/* Swap the previous/current indices */
	i = 1;
	while (forever || i++ <= count) {
		/*
		 * No telling how many lines will be printed in any interval.
		 * There should be a minimum of HEADERLINES between any
		 * header.  If we exceed that, no big deal.
		 */
		if (linesout > HEADERLINES) {
			linesout = 0;
			printhdr = 1;
		}
		/* Have a kip */
		sleep_until(&start_n, period_n, forever, &caught_cont);

		if (timestamp_fmt != NODATE) {
			print_timestamp(timestamp_fmt);
			linesout++;
		}

		for (j = 0, nentities_found = 0; j < nentities; j++) {
			entity_t *ent = &entities[j];

			/*
			 * If this entry has been cleared, don't attempt
			 * to process it.
			 */
			if (ent->e_ksname[0] == 0) {
				continue;
			}

			if (get_vopstats(kc, ent->e_ksname,
			    &ent->e_vs[CUR_INDEX], NULL) == 0) {
				(*dfunc)(ent->e_name, &ent->e_vs[PREV_INDEX],
				    &ent->e_vs[CUR_INDEX],
				    dispflag_policy(printhdr, dispflag));
				linesout++;
				nentities_found++;
			} else {
				if (ent->e_type == ENTYPE_MNTPT) {
					(void) printf(gettext(
					    "<<mount point no longer "
					    "available: %s>>\n"), ent->e_name);
				} else if (ent->e_type == ENTYPE_FSTYPE) {
					(void) printf(gettext(
					    "<<file system module no longer "
					    "loaded: %s>>\n"), ent->e_name);
				} else {
					(void) printf(gettext(
					    "<<%s no longer available>>\n"),
					    ent->e_name);
				}
				/* Disable this so it doesn't print again */
				ent->e_ksname[0] = 0;
			}
			printhdr = 0;	/* Always shut this off */
		}
		BUMP_INDEX();	/* Bump the previous/current indices */

		/*
		 * If the entities we were observing are no longer there
		 * (file system modules unloaded, file systems unmounted)
		 * then we're done.
		 */
		if (nentities_found == 0)
			break;
	}

	return (0);
}
Пример #17
0
void sleep_for( chrono::duration< Rep, Period > const& timeout_duration)
{ sleep_until( chrono::high_resolution_clock::now() + timeout_duration); }