Exemplo n.º 1
0
/*
 *  Given a process id, iterate through all open files of that process
 *  looking for a match to the target file, and then determine how it
 *  is being used by that process.  This is quite different in QNX to
 *  UNIX, as chroot and chdir do not hold open a reference to the file.
 *  The iteration process attempts to dup each file descriptor into
 *  this process, so it can then be queried; attempt to skip things which
 *  aren't files (heuristic guess) and use a timeout as self-defence.
 */
int howused(pid_t pid, match_t *match)
{
struct _server_info	sinfo;
struct _fdinfo		finfo;
struct stat			st;
io_dup_t			msg;
uint64_t			to;
int					fd, coid, usage;

	usage = 0;
	for (fd = 0; (fd = ConnectServerInfo(pid, fd, &sinfo)) != -1; ++fd) {
		if ((pid != sinfo.pid || !(fd & _NTO_SIDE_CHANNEL)) && (coid = ConnectAttach(sinfo.nd, sinfo.pid, sinfo.chid, 0, _NTO_COF_CLOEXEC)) != -1) {
			msg.i.type = _IO_DUP;
			msg.i.combine_len = sizeof(msg.i);
			msg.i.info.nd = netmgr_remote_nd(sinfo.nd, ND_LOCAL_NODE);
			msg.i.info.pid = pid;
			msg.i.info.chid = sinfo.chid;
			msg.i.info.scoid = sinfo.scoid;
			msg.i.info.coid = fd;
			TimerTimeout(CLOCK_MONOTONIC, _NTO_TIMEOUT_SEND | _NTO_TIMEOUT_REPLY, NULL, (to = 1000000000LL, &to), NULL);
			if (MsgSend(coid, &msg.i, sizeof(msg.i), NULL, 0) == -1) {
				ConnectDetach(coid);
			}
			else {
				if (fstat(coid, &st) != -1 && ismatch(match, st.st_dev, st.st_ino)) {
					if (iofdinfo(coid, 0, &finfo, NULL, 0) == -1 || sinfo.pid != PATHMGR_PID || finfo.mode != 0)
						usage |= USED_OPEN;
				}
				close(coid);
			}
		}
	}
	return(usage);
}
Exemplo n.º 2
0
int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout) {
	int rc;

	if(timeout) {
		// Passing a NULL for event is the same as notify = SIGEV_UNBLOCK
		uint64_t	t = timespec2nsec(timeout);

		//POSIX 3.3.8.4 error checking
		if(!TIMESPEC_VALID(timeout)) {
			errno = EINVAL;
			return -1;
		}

		// Passing a NULL for event is the same as notify = SIGEV_UNBLOCK
		if(TimerTimeout(CLOCK_MONOTONIC, _NTO_TIMEOUT_SIGWAITINFO, 0, &t, 0) == -1) {
			return -1;
		}
	}
	
	// POSIX P1003.1-1996 Section 3.3.8.2 line 1995 says we have to do this
	if (((rc = SignalWaitinfo(set, info)) == -1) && (errno == ETIMEDOUT)) {
		errno = EAGAIN;
	}

	return rc;
}
int clsThread::WaitForEvent(uint64_t nsec)
{
	uint64_t nWait = nsec;

    TimerTimeout(CLOCK_REALTIME, _NTO_TIMEOUT_CONDVAR | _NTO_TIMEOUT_MUTEX, NULL, &nWait, NULL);
	int nReturn = pthread_cond_wait(&m_condThread, &m_mtxThread);

	return nReturn;
}
Exemplo n.º 4
0
int mq_timedsend_woption(mqd_t mq, const char *buff, size_t nbytes, 
           unsigned msgprio, const struct timespec *timeout, clockid_t clock_choice) {
	uint64_t	t = timespec2nsec(timeout);

	
	if(!TIMESPEC_VALID(timeout)) {
		errno = EINVAL;
		return -1;
	}
	if(TimerTimeout(clock_choice, TIMER_ABSTIME | _NTO_TIMEOUT_SEND | _NTO_TIMEOUT_REPLY, 0, &t, 0) == -1) {
		return -1;
	}
	return (_writex(mq, buff, nbytes, _IO_XTYPE_MQUEUE | (msgprio << 16), 0, 0) == -1) ? -1 : 0;
}
Exemplo n.º 5
0
int timer_timeout(clockid_t id, int flags, const struct sigevent *notify,
		const struct timespec *ntime, struct timespec *otime) {
	int				ret;
	uint64_t		o, n;

	if(ntime) {
		n = timespec2nsec(ntime);
	}

	ret = TimerTimeout(id, flags, notify, ntime ? &n : 0, otime ? &o : 0);

	if(otime) {
		nsec2timespec(otime, o);
	}

	return ret;
}
Exemplo n.º 6
0
int omap3530_wait(omap3530_spi_t *dev, int len)
{
	struct _pulse	 pulse;
	int rx_idx = dev->sdma_rx_chid;
	
	while (1) {
		if (len) {
			uint64_t	to = dev->dtime * 1000 * 50; /* 50 times for time out */
			to *= len ;	
			TimerTimeout(CLOCK_REALTIME, _NTO_TIMEOUT_RECEIVE, NULL, &to, NULL);
		}
		if (MsgReceivePulse(dev->chid, &pulse, sizeof(pulse), NULL) == -1){
			fprintf(stderr, "omap3530_wait: errono %s(%d), status %x\n", strerror(errno), errno, in32(dev->vbase+ OMAP3530_MCSPI_IRQ_STATUS_OFFSET));
			return -1;
		}

		switch (pulse.code) {
			case OMAP3530_SPI_EVENT:
					return 0;
			case OMAP3530_SDMA_EVENT:
				{
					/* Unmask the Interrupt */
					InterruptUnmask(dev->irq_sdma+rx_idx, dev->iid_sdma);
					if ((dev->dma4->channel[rx_idx].csr & DMA4_CSR_FRAME)){
						/* clear interrupt status line 0 for transmit channel */
						dev->dma4->channel[rx_idx].csr |= DMA4_CSR_FRAME;
						return 0;
					}else {
						  continue;
					}
				}
		}
	}

	return 0;
}
Exemplo n.º 7
0
int main( int argc, char *argv[] ) {
  
  int arg;
  
  int use_tracker = FALSE;
  int use_isense = FALSE;
  int use_udp = FALSE;
  int orientation_only = FALSE;

  IsenseDataPacket iSenseData;
  UDPDataPacket udpData;
  int data_available = NO;
  
  for ( arg = 1; arg < argc; arg++ ) {
    
    if ( !strcmp( argv[arg], "-full" ) ) {
      width = 640;
      height = 480;
      border = false;
      fullscreen = true;
      stereo = false;
    }
    else if ( !strcmp( argv[arg], "-hmd" ) ) {
      width = 1280;
      height = 480;
      border = false;
      fullscreen = true;
      stereo = true;
//       HMDScreen( HMD_STEREO );
    }
    else if ( !strcmp( argv[arg], "-svga" ) ) {
      width = 2048;
      height = 768;
      border = false;
      fullscreen = true;
      stereo = true;
      HMDScreen( HMD_STEREO );
    }
    else if ( !strcmp( argv[arg], "-nVisL" ) ) {
      fprintf( stderr, "LowRes nVis\n" );
      width = 2048;
      height = 768;
      border = false;
      fullscreen = true;
      stereo = true;
//      HMDScreen( HMD_STEREO );
    }
    else if ( !strcmp( argv[arg], "-nVis" ) ) {
      width = 2560;
      height = 1024;
      border = false;
      fullscreen = true;
      stereo = true;
//      HMDScreen( HMD_STEREO );
    }
    else if ( !strcmp( argv[arg], "-noborder" ) ) border = FALSE;
    else if ( !strcmp( argv[arg], "-tracker" ) ) use_tracker = TRUE;
    else if ( !strcmp( argv[arg], "-isense" ) ) use_isense = TRUE;
    else if ( !strcmp( argv[arg], "-udp" ) ) use_udp = TRUE;
    else if ( !strcmp( argv[arg], "-ori" ) ) orientation_only = TRUE;
    else if ( !strcmp( argv[arg], "-sensor" ) ) {
      arg++;
      if ( arg < argc ) sscanf( argv[arg], "%d", &viewpoint_sensor );
      fprintf( stderr, "Using sensor %d.\n", viewpoint_sensor );
    }
    else closure_record = argv[arg];

  }
  
  fprintf( stderr, "Closure record: %s\n", closure_record );
  
    
  /* Start up optical tracker. */
  if ( use_tracker ) {
    SetupTracker();
    SensorSetHysteresis( 1, 2.0, 0.5 ); // mm and degrees
    /*
    * The simulated tracker goes through 7 phases.
    * The first is stationary.
    * The next three are translation movements along X,Y and Z, respectively.
    * The last three are rotations around Z, Y and X, respectively.
    * The following sets the amplitude of each phase.
    * This call will have no effect on real tracker movements.
    */
    SimulateSetMovement( viewpoint_sensor, sim_translation, sim_rotation ); 
    
    /* Shift the nominal viewpoint up, then tilt the view back down to look at the target. */
    viewpoint_position[Y] = nominal_head_height;
    SimulateSetLocation( viewpoint_sensor, viewpoint_position );
    viewpoint_orientation[Y][Y] = viewpoint_orientation[Z][Z] = cos( radians( nominal_head_tilt ) );
    viewpoint_orientation[Y][Z] = sin( radians( nominal_head_tilt ) ) ;
    viewpoint_orientation[Z][Y] = - viewpoint_orientation[Y][Z];
    SimulateSetOrientation( viewpoint_sensor, viewpoint_orientation );

    SimulateSetLocation( object_sensor, object_position );
    SimulateSetMovement( object_sensor, sim_translation, sim_rotation ); 
  }
  
  if ( use_isense || use_udp ) {
    if ( UDPTrackerInitClient( &trkr, NULL, DEFAULT_PORT ) ) {
      MessageBox( NULL, "Error opening socket.", "Isense UDP", MB_OK );
      use_isense = NO;
    }
  }
    
 /* 
  * Define a viewing projection with:
  *  45° vertical field-of-view - horizontal fov will be determined by window aspect ratio.
  *  60 mm inter-pupilary distance - the units don't matter to OpenGL, but all the dimensions
  *      that I give for the model room here are in mm.
  *  100.0 to 10000.0  depth clipping planes - making this smaller would improve the depth resolution.
  */
  viewpoint = new Viewpoint( 6.0, 45.0, 10.0, 10000.0);
  
   
  int x = 100, y = 100;
  
  /*
  * Create window. 
  */
  window = new OpenGLWindow();
  window->Border = border; // Remove borders for an HMD display.
  window->FullScreen = fullscreen;

  if ( window->Create( NULL, argv[0], 0, 0, width, height ) ) {
		/*
    * Create sets the new window to be the active window.
    * Setup the lights and materials for that window.
    */
    glDefaultLighting();
    glDefaultMaterial();
//    wall_texture->Define();
  }  
  window->Activate();
  window->SetKeyboardCallback( keyboard_callback );

  // Shade model
	glEnable(GL_TEXTURE_2D);							// Enable Texture Mapping ( NEW )
  glEnable(GL_LIGHTING);
  glShadeModel(GL_SMOOTH);							// Enable Smooth Shading
	glClearDepth(1.0f);									// Depth Buffer Setup
	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing
	glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations

  create_objects();

  TimerSet( &frame_timer, 10.0 );
  frame_counter = 0;
  for ( double angle = 0.0; true; angle += 5.0 ) {

    if ( TimerTimeout( &frame_timer )) {
      fprintf( stderr, "Frame rate: %f\n", (double) frame_counter / TimerElapsedTime( &frame_timer ) );

      if ( use_isense ) {
        UDPTrackerGetIsenseData( &trkr, &iSenseData );
        printf("Isense Quarternion %7.3f %7.3f %7.3f %7.3f   %.3f\n",
        iSenseData.Station[0].orientation[0],
        iSenseData.Station[0].orientation[1],
        iSenseData.Station[0].orientation[2],
        iSenseData.Station[0].orientation[3],
        
        iSenseData.Station[0].timestamp );
      }

      TimerStart( &frame_timer );
      frame_counter = 0;
    }
  
    if ( use_tracker ) {
      data_available = !GetSensorPositionOrientation( viewpoint_sensor, YES, viewpoint_position, viewpoint_orientation );
      if ( data_available ) {
        if ( !orientation_only ) viewpoint->SetPosition( viewpoint_position );
        viewpoint->SetOrientation( viewpoint_orientation );
      }
    }
    else if ( use_isense ) {
      data_available = !( UDPTrackerGetIsenseData( &trkr, &iSenseData ));
      if ( data_available ) {
        isense_to_matrix( iSenseData.Station[0].orientation, viewpoint_orientation );
        isense_to_vector( iSenseData.Station[0].position, viewpoint_position );
        scale_vector( 10.0, viewpoint_position, viewpoint_position );
        if ( !orientation_only ) viewpoint->SetPosition( viewpoint_position );
        viewpoint->SetOrientation( viewpoint_orientation );
      }
    }
    else if ( use_udp ) {
      data_available = !( UDPTrackerGetData( &trkr, &udpData ));
      if ( data_available ) {
        quaternion_to_matrix( udpData.Station[0].orientation, viewpoint_orientation );
        copy_vector( udpData.Station[0].position, viewpoint_position );
        scale_vector( 10.0, viewpoint_position, viewpoint_position );
        if ( !orientation_only ) viewpoint->SetPosition( viewpoint_position );
        viewpoint->SetOrientation( viewpoint_orientation );
      }
    }
    else {
      data_available = data_available;
    }

    if ( use_tracker ) {
      data_available = !GetSensorPositionOrientation( object_sensor, YES, object_position, object_orientation );
        object->SetPosition( object_position );
        object->SetOrientation( object_orientation );
    }
    else if ( use_isense && data_available ) {
      isense_to_matrix( iSenseData.Station[1].orientation, object_orientation );
      isense_to_vector( iSenseData.Station[1].position, object_position );
      scale_vector( 10.0, object_position, object_position );
      object->SetOrientation( object_orientation );
      if ( !orientation_only ) object->SetPosition( object_position );
    }
    else {
      object->SetOrientation( angle, j_vector );
      object->SetPosition( object_position );
    }

    
    window->Clear();

    if ( stereo ) {
      viewpoint->Apply( window, LEFT_EYE );
      render();

      viewpoint->Apply( window, RIGHT_EYE );
      render();
    }
    else {
      viewpoint->Apply( window, CYCLOPS );
      render();
    }
    window->Swap();
    if ( ! window->RunOnce() ) break;
 

    frame_counter++;
    
  }
  
  window->Destroy();
  
  if ( use_tracker ) KillTracker();
  
  RevertScreen();
  
  return( 0 );
  
}
Exemplo n.º 8
0
Arquivo: main.c Projeto: jnbek/TekNap
void io (const char *what)
{
	static	int	first_time = 1;
		long	clock_timeout = 0, 
			timer_timeout = 0,
			real_timeout = 0; 
static	struct	timeval my_now,
			my_timer,
			*time_ptr = &my_timer;

	int		hold_over,
			rc;
	fd_set		rd, 
			wd;

	get_time(&my_now);
	now = my_now.tv_sec;
	
	/* CHECK FOR CPU SAVER MODE */
	if (!cpu_saver && get_int_var(CPU_SAVER_AFTER_VAR))
		if (now - idle_time > get_int_var(CPU_SAVER_AFTER_VAR) * 60)
			cpu_saver_on(0, NULL);

	rd = readables;
	wd = writables;
	FD_ZERO(&wd);
	FD_ZERO(&rd);

	set_screens(&rd, &wd);
	set_server_bits(&rd, &wd);
	set_process_bits(&rd);
	set_socket_read(&rd, &wd);
	icmp_sockets(&rd, &wd);
	
#if defined(WANT_THREAD)
#ifdef WANT_NSLOOKUP
	set_dns_output_fd(&rd);
#endif
#ifdef WANT_PTEST
	set_ptest_output_fd(&rd);
#endif
#ifdef WANT_MP3PLAYER
	set_mp3_output_fd(&rd);
#endif
	
# if defined(GTK)
	if (tgtk_okay())
		tgtk_set_output_fd(&rd);
# endif
#endif
	clock_timeout = (timeout_select - (my_now.tv_sec % timeout_select)) * 1000;
	if (cpu_saver && get_int_var(CPU_SAVER_EVERY_VAR))
		clock_timeout += (get_int_var(CPU_SAVER_EVERY_VAR) - 1) * 60000;

	timer_timeout = TimerTimeout();

	if ((hold_over = unhold_windows()))
		real_timeout = 0;
	else if (timer_timeout <= clock_timeout)
		real_timeout = timer_timeout;
	else
		real_timeout = clock_timeout;

	if (real_timeout == -1)
		time_ptr = NULL;
	else
	{
		time_ptr->tv_sec = real_timeout / 1000;
		time_ptr->tv_usec = ((real_timeout % 1000) * 1000);
	}
	
	/* GO AHEAD AND WAIT FOR SOME DATA TO COME IN */
	switch ((rc = new_select(&rd, &wd, time_ptr)))
	{
		case 0:
			break;
		case -1:
		{
			/* if we just got a sigint */
			first_time = 0;
			if (cntl_c_hit)
				edit_char('\003');
			else if (errno && errno != EINTR)
			{
				int ii = 0;
				fd_set rd1, wd1;
				char ii_buff_r[500];
				char ii_buff_w[500];
				int ii_r[FD_SETSIZE];
				int ii_w[FD_SETSIZE];
				yell("Select failed with [%d:%s]", errno, strerror(errno));
				/* Reseed fd_sets so we can dig further */
				yell("Packing fd_sets... Dump of fd's set in fd_set");
				ii_buff_r[0] = '\0';
				ii_buff_w[0] = '\0';
				for (ii = 0; ii < FD_SETSIZE; ii++) {
					ii_r[ii] = 0;
					ii_w[ii] = 0;
				}
				FD_ZERO(&wd1);
				FD_ZERO(&rd1);
				set_screens(&rd1, &wd1);
				set_server_bits(&rd1, &wd1);
				set_process_bits(&rd1);
				set_socket_read(&rd1, &wd1);
				icmp_sockets(&rd1, &wd1);
#if defined(WANT_THREAD)
#ifdef WANT_NSLOOKUP
				set_dns_output_fd(&rd1);
#endif
#ifdef WANT_PTEST
				set_ptest_output_fd(&rd1);
#endif
#ifdef WANT_MP3PLAYER
				set_mp3_output_fd(&rd1);
#endif
	
# if defined(GTK)
	if (tgtk_okay())
				tgtk_set_output_fd(&rd1);
# endif
#endif
				for (ii = 0; ii <= global_max_fd; ii++) {
					fd_set rblah, wblah;
					memcpy(&rblah, &rd1, sizeof(fd_set));
					FD_SET(ii, &rblah);
					if (memcmp(&rblah, &rd1, sizeof(fd_set)) == 0) {
						char blahblah[20];
						sprintf(blahblah, "%d ", ii);
						strcat(ii_buff_r, blahblah);
						ii_r[ii] = 1;
					}
					memcpy(&wblah, &wd1, sizeof(fd_set));
					FD_SET(ii, &wblah);
					if (memcmp(&wblah, &wd1, sizeof(fd_set)) == 0) {
						char blahblah[20];
						yell("blah");
						sprintf(blahblah, "%d ", ii);
						strcat(ii_buff_w, blahblah);
						ii_w[ii] = 1;
					}
				}
				yell("Read fd's in set: %s", (ii_buff_r[0] == '\0') ? "<NONE>" : ii_buff_r);
				for (ii = 0; ii <= global_max_fd; ii++) {
					if (ii_r[ii] == 1) {
						struct stat st;
						if (fstat(ii, &st) == -1) {
							yell("READ FD %d is causing the select failure!", ii);
						}
						else {
							if (S_ISSOCK(st.st_mode))
								yell("READ FD %d is a socket!", ii);
							else if (S_ISREG(st.st_mode))
								yell("READ FD %d is a regular file!", ii);
							else if (S_ISFIFO(st.st_mode))
								yell("READ FD %d is a FIFO!", ii);
							else ;
						}
					}
				}
				yell("Write fd's in set: %s", (ii_buff_w[0] == '\0') ? "<NONE>" : ii_buff_w);
				for (ii = 0; ii <= global_max_fd; ii++) {
					if (ii_w[ii] == 1) {
						struct stat st;
						if (fstat(ii, &st) == -1) {
							yell("WRITE FD %d is causing the select failure!", ii);
						}
						else {
							if (S_ISSOCK(st.st_mode))
								yell("WRITE FD %d is a socket!", ii);
							else if (S_ISREG(st.st_mode))
								yell("WRITE FD %d is a regular file!", ii);
							else if (S_ISFIFO(st.st_mode))
								yell("WRITE FD %d is a FIFO!", ii);
							else ;
						}
					}
				}
				sleep(10);
			}
			else 
			{
#if 0
				yell("errno 0 rc = -1, maybe it'll go away");
				sleep(10);
#endif
			}
			break;

		}

		/* we got something on one of the descriptors */
		default:
		{
			cntl_c_hit = 0;
			now = time(NULL);
			make_window_current(NULL);
			do_screens(&rd);
			check_icmpresult(&rd, &wd);
#if defined(WANT_THREAD)
#ifdef WANT_NSLOOKUP
			dns_check(&rd);
#endif
#ifdef WANT_PTEST
			ptest_check(&rd);
#endif
#ifdef WANT_MP3PLAYER
			mp3_check(&rd);
#endif
# if defined(GTK)
			if (tgtk_okay())
				tgtk_check(&rd);
# endif
#endif
			do_server(&rd, &wd);
			do_processes(&rd);
			scan_sockets(&rd, &wd);
			clean_sockets();
			break;
		} 
	}

	now = time(NULL);
	ExecuteTimers();

        get_child_exit(-1);
	if (update_refresh)
	{
		update_refresh = 0;
		refresh_screen(0, NULL);
	}
	if (!hold_over)
		cursor_to_input();


	if (update_clock(RESET_TIME))
	{
		if (get_int_var(CLOCK_VAR))
		{
			update_all_status(current_window, NULL, 0);
			cursor_to_input();
		}
		clean_queue(get_int_var(TRANSFER_TIMEOUT_VAR)); /* timeout if send time is greater than 5 minutes */
	}

	/* (set in term.c) -- we should redraw the screen here */
	if (need_redraw)
		refresh_screen(0, NULL);
#ifdef WANT_THREAD
	if (scan_done)
		scan_is_done();	
#endif
	alloca(0);
	return;
}
Exemplo n.º 9
0
int _waitfor( __const char *path, int delay_ms, int poll_ms, int (*checkfunc)(__const char *, void *), void *handle )
{
	int					notify_id = -1;
    struct sigevent     event;
    int                 chid = -1, coid = -1;
    struct _pulse       pulse;
	int					ret_val = -1;
	uint64_t			polltimeout = 100 * (uint64_t)1000000;
	uint64_t			timeout_nsec;

	timeout_nsec = _syspage_time(CLOCK_MONOTONIC);
	timeout_nsec += delay_ms * (uint64_t)1000000;

    /* Check to make sure we don't wait for something already there... */
    ret_val = checkfunc( path, handle );
	if ( ret_val >= 0 || ret_val == WAITFOR_CHECK_ABORT ) {
		return ret_val;
    }

	if ( poll_ms > 0 ) {
		polltimeout = poll_ms * (uint64_t)1000000;
	}

	/* 
	 * We make the channel fixed since we want to remain at the current
	 * thread's priority
	 */
    chid = ChannelCreate(_NTO_CHF_FIXED_PRIORITY);
	if ( chid == -1 ) {
		goto fail1;
	}
    coid = ConnectAttach( ND_LOCAL_NODE, 0, chid, _NTO_SIDE_CHANNEL, 0 );
	if ( coid == -1 ) {
		goto fail2;
	}

    SIGEV_PULSE_INIT( &event, coid, SIGEV_PULSE_PRIO_INHERIT, PULSE_CODE_PATHSPACE, 0 );
    notify_id = procmgr_event_notify_add( PROCMGR_EVENT_PATHSPACE, &event );
	if ( notify_id == -1 ) {
		goto fail3;
	}

    while(_syspage_time(CLOCK_MONOTONIC) < timeout_nsec) {

		/* we need to poll in case we are checking for a subdirectory/file,
		 * since we won't get a pathmgr event for those.
		 */
		SIGEV_UNBLOCK_INIT(&event);
		if ( TimerTimeout( CLOCK_MONOTONIC, _NTO_TIMEOUT_RECEIVE, &event, &polltimeout, NULL) == -1 ) {
			ret_val = -1;
			break;
		}
	   	if ( MsgReceivePulse( chid, &pulse, sizeof(pulse), NULL ) != -1 || errno == ETIMEDOUT ) {
			ret_val = checkfunc( path, handle );
			if ( ret_val >= 0 || ret_val == WAITFOR_CHECK_ABORT ) {
				break;
            }
		} else {
			break;
		}
    }

	(void)procmgr_event_notify_delete( notify_id );
fail3:
	(void)ConnectDetach(coid);
fail2:
	(void)ChannelDestroy(chid);
fail1:
    return ret_val;
}
Exemplo n.º 10
0
/****************************************************************************
*
*						Subroutine state_thread
*
*	Purpose: 	This is a thread that is used to trigger the various thread
*				states
*
*	Parameters:	None
*
*	Returns:	Nothing
*			
*
*****************************************************************************/
void * state_thread(void * arg)
{
	int rc,x,coid;
	sigset_t myset;
	uint64_t timeout;
	struct sigevent myevent;
	pthread_t mythread;
	char buf[100];
	while(1) {
		/* Syncronize with the main thread. */
		pthread_barrier_wait(&global_barrier);
		switch (cur_state) {
			case STATE_DEAD: 
				/* Start the logging */
				rc=TraceEvent(_NTO_TRACE_STARTNOSTATE);
				assert(rc!=-1);
				delay(10);
				/* Trigger the dead state by calling pthread_exit */
				pthread_exit(NULL);
				/* Should never get here */
				abort();
			case STATE_READY: 
				exit_now=0;
				for (x=0;x<_syspage_ptr->num_cpu;x++)
					pthread_create(NULL, NULL, ready_thread, NULL);
				/*  Let the new threads get started */
				sleep(1);
			case STATE_RUNNING: 
				/* Start the logging */
				rc=TraceEvent(_NTO_TRACE_STARTNOSTATE);
				assert(rc!=-1);
				delay(10);
				/* Trigger the running state by just doing some work. 
				 * this should also trigger a ready state before
				 * we are running
				 */
				x=0;
				while(x<10)
					x++;
				exit_now=1;
				while(x<1000)
					x++;
				exit_now=1;
				/* and unblock the parent */
				pthread_barrier_wait(&global_barrier);
				break;
			case STATE_STOPPED: 

				/* Start the logging */
				rc=TraceEvent(_NTO_TRACE_STARTNOSTATE);
				assert(rc!=-1);
				delay(100);
				kill (child_pid, SIGSTOP);
				delay(10);
				kill (child_pid, SIGCONT);
				delay(100);
				pthread_barrier_wait(&global_barrier);
				break;
			case STATE_SEND: 
			case STATE_REPLY: 
				coid=ConnectAttach(0, getpid(), chid, _NTO_SIDE_CHANNEL, 0);
				/* Start the logging */
				rc=TraceEvent(_NTO_TRACE_STARTNOSTATE);
				assert(rc!=-1);
				delay(10);
				/* Trigger the SEND/REPLY blocked states */
				MsgSend(coid, buf, 10, buf,10);
				pthread_barrier_wait(&global_barrier);
				break;
			case STATE_RECEIVE: 
				/* Start the logging */
				rc=TraceEvent(_NTO_TRACE_STARTNOSTATE);
				assert(rc!=-1);
				delay(10);
				/* Trigger a receive state  */
				rc=MsgReceive(chid, buf, sizeof(buf), NULL);
				MsgReply(rc, EOK, "ok", 3);
				pthread_barrier_wait(&global_barrier);
				break;
			case STATE_WAITTHREAD: 
				/* Start the logging */
				rc=TraceEvent(_NTO_TRACE_STARTNOSTATE);
				assert(rc!=-1);
				delay(10);
				/* Trigger a waitthread state  */
				pthread_create(NULL, NULL, nothing_thread, NULL);
				pthread_barrier_wait(&global_barrier);
				break;
			case STATE_SIGSUSPEND: 
				memset(&myevent, 0, sizeof(myevent));
				myevent.sigev_notify = SIGEV_UNBLOCK;
				timeout = 1*1000000000L;
	
				sigemptyset(&myset);
				sigaddset(&myset, SIGHUP);
				sigaddset(&myset, SIGBUS);
				sigaddset(&myset, SIGSEGV);
				sigaddset(&myset, SIGXCPU);
				sigaddset(&myset, SIGRTMIN);
				sigaddset(&myset, SIGRTMAX);
		
				/* Start logging */
				rc=TraceEvent(_NTO_TRACE_STARTNOSTATE);
				assert(rc!=-1);
				delay(10);
				TimerTimeout( CLOCK_REALTIME, _NTO_TIMEOUT_SIGSUSPEND,&myevent, &timeout, NULL );
				SignalSuspend(&myset);
				pthread_barrier_wait(&global_barrier);
				break;
			case STATE_SIGWAITINFO: 
				memset(&myevent, 0, sizeof(myevent));
				myevent.sigev_notify = SIGEV_UNBLOCK;
				timeout = 1*1000000000L;
	
				sigemptyset(&myset);
				sigaddset(&myset, SIGHUP);
				sigaddset(&myset, SIGBUS);
				sigaddset(&myset, SIGSEGV);
				sigaddset(&myset, SIGXCPU);
				sigaddset(&myset, SIGRTMIN);
				sigaddset(&myset, SIGRTMAX);
		
				/* Start logging */
				rc=TraceEvent(_NTO_TRACE_STARTNOSTATE);
				assert(rc!=-1);
				delay(10);
				TimerTimeout( CLOCK_REALTIME, _NTO_TIMEOUT_SIGWAITINFO,&myevent, &timeout, NULL );
				SignalWaitinfo(&myset,NULL);
				pthread_barrier_wait(&global_barrier);
				break;
			case STATE_NANOSLEEP:
				/* Start logging */
				rc=TraceEvent(_NTO_TRACE_STARTNOSTATE);
				assert(rc!=-1);
				sleep(1);
				sleep(1);
				pthread_barrier_wait(&global_barrier);
				break;
			case STATE_MUTEX:
				/* Start logging */
				rc=TraceEvent(_NTO_TRACE_STARTNOSTATE);
				assert(rc!=-1);
				sleep(1);
				pthread_mutex_lock(&mymutex);
				pthread_mutex_unlock(&mymutex);
				pthread_barrier_wait(&global_barrier);
				break;
			case STATE_CONDVAR:
				/* Start logging */
				rc=TraceEvent(_NTO_TRACE_STARTNOSTATE);
				assert(rc!=-1);
				sleep(1);
				pthread_mutex_lock(&mymutex);
				pthread_cond_wait(&mycondvar, &mymutex);
				pthread_mutex_unlock(&mymutex);
				pthread_barrier_wait(&global_barrier);
				break;
			case STATE_JOIN:
				pthread_create(&mythread, NULL, nothing_thread, NULL);
				/* Start logging */
				rc=TraceEvent(_NTO_TRACE_STARTNOSTATE);
				assert(rc!=-1);
				delay(10);
				pthread_join(mythread, NULL);
				pthread_barrier_wait(&global_barrier);
				break;
			case STATE_SEM:
				/* Start logging */
				rc=TraceEvent(_NTO_TRACE_STARTNOSTATE);
				assert(rc!=-1);
				sleep(1);
				sem_wait(&mysem);
				pthread_barrier_wait(&global_barrier);
				break;
			
		}
	}
	
}
Exemplo n.º 11
0
int main(int argc, char **argv) {
	if(argc != 2) {
		printf("Set client id\n");
		return EXIT_SUCCESS;
	}
	uint32_t cid = atoi(argv[1]);//!!
	struct timespec timeout, stime, etime;
	frame_t frame, rframe;
	char buf[BUFFER_SIZE], cmd[BUFFER_SIZE], param[BUFFER_SIZE];
	int itr = -1, n, k;
	FILE *pfile = 0;
	uint32_t itr_max = ITR;
	double_t *pfcn, *psig, init;
	uint64_t timeoutsend = 200000000;

//*****************************************************************************
	timeout.tv_nsec = 0;
	timeout.tv_sec = 1;

	strcpy(buf, CFGFILENAME);
	strcat(buf, argv[1]);
	pfile = fopen(buf, "r");
	if(NULL != pfile) {
		while(0 == feof(pfile)) {
			fscanf(pfile, "%s %s", cmd, param);
			if(0 == strcmp(cmd, "itr_max")) {
				itr_max = atoi(param);
			}
			else if(0 == strcmp(cmd, "timeoutsend")) {
				timeoutsend = atol(param);
			}
			else if(0 == strcmp(cmd, "timeout_sec")) {
				timeout.tv_sec = atol(param);
			}
			else if(0 == strcmp(cmd, "timeout_nsec")) {
				timeout.tv_nsec = atol(param);
			}
		}
		fclose(pfile);
	} else {
		perror(MSG_ERR_CFGFILE);
	}

	strcpy(buf, OUTFILENAME);
	strcat(buf, argv[1]);
	pfile = fopen(buf, "w");
	fprintf(pfile, "itr_max %i\ntimeoutsend   %llu\ntimeout %lu %lu\n",
			itr_max, timeoutsend,
			timeout.tv_sec, timeout.tv_nsec);

	pfcn = malloc(sizeof(double_t)*(SIZE*2));
	psig = malloc(sizeof(double_t)*((SIZE-1)*2));

	srand(time(NULL));
	for(size_t i = 0; i<SIZE; i++) {
		pfcn[i] = i*STEP;
		pfcn[i+SIZE] = sin(pfcn[i])+2;
	}

	for(size_t i = 0; i<SIZE-1; i++) {
		psig[i] = SHIFT + (rand()%SIZE)*STEP;
		psig[i+SIZE-1] = sin(psig[i])+2;
	}

	frame.cid = cid;
	frame.fid = 0;
	frame.size = 2;

//*****************************************************************************

	int srv_coid = name_open(SRV_NAME, NAME_FLAG_ATTACH_GLOBAL);
	__ERROR_EXIT(srv_coid, -1, SRV_NAME);
	frame.ptask = malloc(sizeof(task_t)*2);
	frame.ptask[0].cmd = SPLINE_INIT;
	frame.ptask[0].n = SIZE*2*sizeof(double_t);
	frame.ptask[0].px = (void*)pfcn;
	frame.timeout = timeout;
	frame.ptask[1].cmd = SPLINE_GETVAL;
	frame.ptask[1].n = 2*sizeof(double_t);
	frame.ptask[1].px = (void*)psig;
	frame_repinit(&frame, &rframe);

	__ERROR_CHECK(TimerTimeout(CLOCK_REALTIME, _NTO_TIMEOUT_SEND | _NTO_TIMEOUT_REPLY,
									NULL, &timeoutsend, NULL), -1, "TimerTimeout");
	// send init data about spline
	__ERROR_CHECK(frame_send(srv_coid, &frame, &rframe), -1, "sendv");
	frame_destroy(&rframe);
	free(frame.ptask);

	frame.ptask = malloc(sizeof(task_t));
	frame.ptask[0].cmd = SPLINE_GETVAL;
	frame.ptask[0].n = sizeof(double_t);
	frame.size = 1;
	frame_repinit(&frame, &rframe);
	k=0;
	for(uint32_t i=0; i<itr_max; ++i) {
		frame.fid = i;
		n = rand()%(SIZE-1);
		frame.ptask[0].px = (void*)&psig[n];
		trace_msg_start();
		// send tasks to server and wait for results
		__ERROR_CONT(frame_send(srv_coid, &frame, &rframe), -1, "sendv");
		trace_msg_stop();
		clock_gettime(CLOCK_MONOTONIC, &etime);
		 fprintf(pfile, "%f  %f  %u  %u\n", psig[n], *(double_t*)rframe.ptask->px,
				etime.tv_sec-stime.tv_sec, etime.tv_nsec-stime.tv_nsec);
		 printf("I receive data\n");
	}
	frame.ptask[0].cmd = SPLINE_DESTROY;
	frame.ptask[0].n = 0;
	frame.ptask[0].px = 0;
	frame.fid++;
	// say server to destroy our spline
	__ERROR_CHECK(frame_send(srv_coid, &frame, &rframe), -1, "sendv");
	fclose(pfile);
	frame_destroy(&rframe);
	free(pfcn);
	free(psig);

	__ERROR_CHECK(name_close(srv_coid), -1, "name_close");

	return EXIT_SUCCESS;
}