本文整理汇总了C++中spin函数的典型用法代码示例。如果您正苦于以下问题:C++ spin函数的具体用法?C++ spin怎么用?C++ spin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int
main(int argc, char *argv[])
{
struct pstat st;
int highpriority = 0;
int pid = getpid();
int defaultpriorityrun = 0;
spin();
check(getpinfo(&st) == 0, "getpinfo");
int i;
printf(1, "\n **** PInfo **** \n");
for(i = 0; i < NPROC; i++) {
if (st.inuse[i]) {
if(st.hticks[i] != 0)
highpriority++;
if(st.pid[i] == pid && st.lticks[i] > 20)
defaultpriorityrun = 1;
printf(1, "pid: %d hticks: %d lticks: %d\n", st.pid[i], st.hticks[i], st.lticks[i]);
}
}
check(highpriority == 0, "getpinfo shouldn't return any process with hticks not equal to 0, default priority should be low(1) ");
check(defaultpriorityrun == 1, "getpinfo should return a process having run with default priority");
printf(1, "Should print 1 then 2");
exit();
}
示例2: main
int main(int argc, char **argv)
{
if (argc < 2)
return usage();
const char *cmd = argv[1];
perish_if(libusb_init(NULL) < 0, "Couldn't init libusb");
libusb_device_handle *h = libusb_open_device_with_vid_pid(NULL,
VENDOR_ID,
PRODUCT_ID);
perish_if(h == NULL, "couldn't find or open device. check permissions?");
perish_if(0 != libusb_claim_interface(h, 0), "couldn't claim interface");
printf("device opened successfully.\n");
signal(SIGINT, signal_handler);
if (!strcmp(cmd, "stream"))
stream(h);
else if (!strcmp(cmd, "blink"))
blink(h);
else if (!strcmp(cmd, "spin"))
spin(h);
else if (!strcmp(cmd, "listen"))
{
ros::init(argc, argv, "roscar_driver");
roscar_listen(h);
}
libusb_exit(NULL);
return 0;
}
示例3: while
void SlotMachine::play(Player &player)
{
int menuSelect = 0;
bool continueLoop = true;
int bet = 0;
static int run = 0;
while (continueLoop)
{
if (run++ == 0)
{
buildMachine(player); // just for show to build display
}
if (processInput(bet))
{
spin(bet, player);
}
else
{
continueLoop = false;
run = 0;
}
}
}
示例4: test_cv_thread
static void
test_cv_thread(unsigned long num)
{
int i;
struct timeval start, end, diff;
for (i = 0; i < LOOPS; i++) {
lock_acquire(testlock);
while (testval1 != num) {
gettimeofday(&start, NULL);
cv_wait(testcv, testlock);
gettimeofday(&end, NULL);
timersub(&end, &start, &diff);
/* cv_wait should wait at least 4-5 ms */
if (diff.tv_sec == 0 && diff.tv_usec < 4000) {
unintr_printf("%s took %ld us. That's too fast."
" You must be busy looping\n",
__FUNCTION__, diff.tv_usec);
goto out;
}
}
unintr_printf("%d: thread %3d passes\n", i, num);
testval1 = (testval1 + NTHREADS - 1) % NTHREADS;
/* spin for 5 ms */
spin(5000);
cv_broadcast(testcv, testlock);
lock_release(testlock);
}
out:
__sync_fetch_and_add(&done, 1);
}
示例5: redDevansh
void redDevansh() // Places preload (1-2) + 2 buckies (2-4) + TURN LEFT Knocks buckies (1-6)
{
deploy();
intake(1);
wait10Msec(10);
moveStraight(1, 0, 455); //picks up
wait10Msec(50);
moveStraight(-1, 0, 475);//comes back
intake(0);
// end part 1: prepare dump
waitForButton();
lift(BUMP);
holdArm();
intake(-1);
resetValues(1200);
// end part 2: dump
waitForButton();
liftDown();
wait10Msec(100);
moveStraight(1, 0, 700);
// end part 3: prepare hit
spin(-1, 0, 200);
intake(-1);
lift(BUMP);
holdArm();
noRamp(1, 250);
resetValues(0);
// end part 4: hit
}
示例6: main
int main(void) {
/* Initialize and clear the display */
gfxInit();
gdispClear(White);
/* Create the 3D window */
{
GWindowInit wi;
gwinClearInit(&wi);
wi.show = TRUE; wi.x = (gdispGetWidth()-GL3D_WINDOW_SIZE)/2; wi.y = (gdispGetHeight()-GL3D_WINDOW_SIZE)/2; wi.width = GL3D_WINDOW_SIZE; wi.height = GL3D_WINDOW_SIZE;
gh = gwinGL3DCreate(0, &wi);
}
/* Init the 3D stuff */
setup();
init();
while(TRUE) {
// rate control
gfxSleepMilliseconds(FRAME_DELAY);
// move and redraw
spin();
}
}
示例7: arp_layer_receive
void arp_layer_receive( struct sk_buff *comer_skb ){
assert(comer_skb->pkgsize = 14 + 28);
struct arphdr *arphdr = (void *)(comer_skb->ethhdr + 1);
comer_skb->arphdr = arphdr;
////////////Entry here !!
///////////network byte order to host order, only performed on arp header
BYTE_ENDIAN_FLIP2(arphdr->hardware);
BYTE_ENDIAN_FLIP2(arphdr->protocol);
BYTE_ENDIAN_FLIP2(arphdr->operation);
BYTE_ENDIAN_FLIP4(arphdr->myip);
BYTE_ENDIAN_FLIP4(arphdr->yourip);
//////////done
//u8 *mac = arphdr->mymac;
//oprintf("arp layer receive: operation=%u, from mac(%x %x %x %x %x %x)", arphdr->operation, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
if(arphdr->operation == 1){ /* it's an inquiry */
arp_respond(comer_skb);
}
else if(arphdr->operation == 2){ /* it's a REPLY */
arp_act(comer_skb);
}
else spin("unknown operation");
//oprintf(" ARP layer exit\n");
}
示例8: main
int
main(int argc, char *argv[])
{
if (argc < 3) {
printf(1, "Usage: usage ticks tickets1 [tickets2]...\n\n");
printf(1, "Spawns subprocesses, each of which will run for \n"
"approximately the given number of ticks. For each ticket\n"
"ammount given, a child process will spawn and request that\n"
"number of tickets.\n");
exit();
}
int total = 0;
int i;
for (i = 0; i < argc - 2; i++) {
total += atoi(argv[i+2]);
}
int ret = settickets(total);
if (ret < 0) {
printf(1, "settickets failed\n");
exit();
}
// pids of children
int pids[NPROC];
// spawn children
for (i = 0; i < argc - 2; i++) {
pids[i] = fork();
if (pids[i] == 0) {
int ret = settickets(atoi(argv[i + 2]));
if (ret < 0) {
printf(1, "settickets failed\n");
exit();
}
// spin so we get scheduled
while(1) {
spin();
}
}
}
// print usage info
int ticks = atoi(argv[1]);
int start = uptime();
while(uptime() < start + ticks) {
sleep(100);
printf(1, "time: %d\n", uptime() - start);
printinfo();
}
// kill children
for (i = 0; i < argc - 2; i++) {
kill(pids[i]);
wait();
}
exit();
}
示例9: assertion_failure
void assertion_failure(char *exp, char *file, char * base_file, int line)
{
printl("%c assert(%s) failed: file: %s, base_file: %s,ln%d",MAG_CH_ASSERT,exp, file, base_file, line);
spin("assertion_failure()");
__asm__ __volatile__("ud2");
}
示例10: ASSERT
void
QueueCommands::MakeSpace(uint32 size)
{
ASSERT((size & 1) == 0);
size *= sizeof(uint32);
bigtime_t start = system_time();
while (fRingBuffer.space_left < size) {
// wait until more space is free
uint32 head = read32(fRingBuffer.register_base + RING_BUFFER_HEAD)
& INTEL_RING_BUFFER_HEAD_MASK;
if (head <= fRingBuffer.position)
head += fRingBuffer.size;
fRingBuffer.space_left = head - fRingBuffer.position;
if (fRingBuffer.space_left < size) {
if (system_time() > start + 1000000LL) {
TRACE(("intel_extreme: engine stalled, head %lx\n", head));
break;
}
spin(10);
}
}
fRingBuffer.space_left -= size;
}
示例11: TestA
/*======================================================================*
TestA
*======================================================================*/
void TestA()
{
int fd;
int i, n;
char filename[MAX_FILENAME_LEN+1] = "blah";
const char bufw[] = "abcde";
const int rd_bytes = 3;
char bufr[rd_bytes];
assert(rd_bytes <= strlen(bufw));
/* create */
fd = open(filename, O_CREAT | O_RDWR);
assert(fd != -1);
printf("File created: %s (fd %d)\n", filename, fd);
/* write */
n = write(fd, bufw, strlen(bufw));
assert(n == strlen(bufw));
/* close */
close(fd);
/* open */
fd = open(filename, O_RDWR);
assert(fd != -1);
printf("File opened. fd: %d\n", fd);
/* read */
n = read(fd, bufr, rd_bytes);
assert(n == rd_bytes);
bufr[n] = 0;
printf("%d bytes read: %s\n", n, bufr);
/* close */
close(fd);
char * filenames[] = {"/foo", "/bar", "/baz"};
/* create files */
for (i = 0; i < sizeof(filenames) / sizeof(filenames[0]); i++) {
fd = open(filenames[i], O_CREAT | O_RDWR);
assert(fd != -1);
printf("File created: %s (fd %d)\n", filenames[i], fd);
close(fd);
}
char * rfilenames[] = {"/bar", "/foo", "/baz", "/dev_tty0"};
/* remove files */
for (i = 0; i < sizeof(rfilenames) / sizeof(rfilenames[0]); i++) {
if (unlink(rfilenames[i]) == 0)
printf("File removed: %s\n", rfilenames[i]);
else
printf("Failed to remove file: %s\n", rfilenames[i]);
}
spin("TestA");
}
示例12: check_service_req
bool
check_service_req(ide_device_info *device)
{
ide_bus_info *bus = device->bus;
int status;
// fast bailout if there is no request pending
if (device->num_running_reqs == 0)
return false;
if (bus->active_device != device) {
// don't apply any precautions in terms of IRQ
// -> the bus is in accessing state, so IRQs are ignored anyway
if (bus->controller->write_command_block_regs(bus->channel_cookie,
&device->tf, ide_mask_device_head) != B_OK)
// on error, pretend that this device asks for service
// -> the disappeared controller will be recognized soon ;)
return true;
bus->active_device = device;
// give one clock (400 ns) to take notice
spin(1);
}
status = bus->controller->get_altstatus(bus->channel_cookie);
return (status & ide_status_service) != 0;
}
示例13: ioremap
void * ioremap(unsigned phys_addr, int size, unsigned flags){
if(phys_addr >> 30) {
oprintf(" %x ", phys_addr);
spin("too big IO physical address");
}
return (void *)(phys_addr + PAGE_OFFSET);
}
示例14: rem_init
void rem_init()
{
PMC_PCER = US0_PID;
US0_CR = RXDIS | TXDIS | RSTRX | RSTTX | RSTSTA;
USART0(PTCR) = RXTDIS | TXTDIS;
nextbyte = &ubuf[0];
nextbuf = &ubuf[0]; // Both buffers are already attached now
USART0(RPR) = (u_long) &ubuf[0];
USART0(RCR) = (u_long) UBUFLEN;
USART0(RNPR) = (u_long) &ubuf[UBUFLEN];
USART0(RNCR) = (u_long) UBUFLEN;
USART0(PTCR) = RXTEN;
US0_BRGR = BAUD_115200;
US0_RTOR = 18; // bit times of delay before timeout
US0_MR = PAR_NONE | CHMODE_NORMAL | USCLKS_MCK | CHRL_8 | NBSTOP_1 | STTTO;
spin(1000);
US0_CR = RXEN | TXEN;
// junk = (u_char)US0_RHR; // Junk leftover from break
// junk = (u_char)US0_RHR;
}
示例15: task_hd
/**
* Main loop of HD driver.
*
*****************************************************************************/
PUBLIC void task_hd()
{
MESSAGE msg;
init_hd();
while (1) {
send_recv(RECEIVE, ANY, &msg);
int src = msg.source;
switch (msg.type) {
case DEV_OPEN:
hd_open(msg.DEVICE);
break;
case DEV_CLOSE:
hd_close(msg.DEVICE);
break;
case DEV_READ:
case DEV_WRITE:
hd_rdwt(&msg);
break;
case DEV_IOCTL:
hd_ioctl(&msg);
break;
default:
dump_msg("HD driver::unknown msg", &msg);
spin("FS::main_loop (invalid msg.type)");
break;
}
send_recv(SEND, src, &msg);
}
}