예제 #1
0
 void speech_processor::process(sample_ptr samples,std::size_t count)
 {
   sample_ptr start=samples;
   sample_ptr end=start+count;
   while(fill_input_buffer(start,end))
     {
       on_input();
       input.clear();
       if(is_stopped())
         return;
       on_output();
       if(is_stopped())
         return;
       if(!next)
         continue;
       if(!insertion.empty())
         {
           next->insert(&insertion[0],insertion.size());
           insertion.clear();
           if(is_stopped())
             {
               output.clear();
               return;
             }
         }
       if(output.empty())
         continue;
       next->process(&output[0],output.size());
       output.clear();
       if(is_stopped())
         return;
     }
 }
예제 #2
0
파일: Main.cpp 프로젝트: lordmulder/INetGet
	virtual uint32_t main(void)
	{
		bool eof_flag = false, abort_flag = false;

		while(!(eof_flag || (abort_flag = is_stopped())))
		{
			size_t bytes_read = 0;
			if(!m_client->read_data(m_buffer, BUFF_SIZE, bytes_read, eof_flag))
			{
				set_error_text(m_client->get_error_text());
				return TRANSFER_ERR_INET;
			}

			if(bytes_read > 0)
			{
				m_transferred_bytes.add(bytes_read);
				if(!(abort_flag = is_stopped()))
				{
					if(!m_sink->write(m_buffer, bytes_read))
					{
						return TRANSFER_ERR_SINK;
					}
				}
			}
		}

		return abort_flag ? TRANSFER_ERR_ABRT : TRANSFER_COMPLETE;
	}
예제 #3
0
struct kinfo_proc2 *
cmp_procs(struct kinfo_proc2 *p1, struct kinfo_proc2 *p2)
{
    if (is_runnable(p1) && !is_runnable(p2))
        return (p1);
    if (!is_runnable(p1) && is_runnable(p2))
        return (p2);

    if (is_stopped(p1) && !is_stopped(p2))
        return (p1);
    if (!is_stopped(p1) && is_stopped(p2))
        return (p2);

    if (p1->p_estcpu > p2->p_estcpu)
        return (p1);
    if (p1->p_estcpu < p2->p_estcpu)
        return (p2);

    if (p1->p_slptime < p2->p_slptime)
        return (p1);
    if (p1->p_slptime > p2->p_slptime)
        return (p2);

    if (p1->p_pid > p2->p_pid)
        return (p1);
    return (p2);
}
예제 #4
0
static void
mi_cmd_var_update_iter (struct varobj *var, void *data_pointer)
{
  struct mi_cmd_var_update *data = data_pointer;
  int thread_id, thread_stopped;

  thread_id = varobj_get_thread_id (var);

  if (thread_id == -1
      && (ptid_equal (inferior_ptid, null_ptid)
	  || is_stopped (inferior_ptid)))
    thread_stopped = 1;
  else
    {
      struct thread_info *tp = find_thread_id (thread_id);

      if (tp)
	thread_stopped = is_stopped (tp->ptid);
      else
	thread_stopped = 1;
    }

  if (thread_stopped
      && (!data->only_floating || varobj_floating_p (var)))
    varobj_update_one (var, data->print_values, 0 /* implicit */);
}
예제 #5
0
파일: osdep-freebsd.c 프로젝트: Darkoe/tmux
struct kinfo_proc *
cmp_procs(struct kinfo_proc *p1, struct kinfo_proc *p2)
{
	if (is_runnable(p1) && !is_runnable(p2))
		return (p1);
	if (!is_runnable(p1) && is_runnable(p2))
		return (p2);

	if (is_stopped(p1) && !is_stopped(p2))
		return (p1);
	if (!is_stopped(p1) && is_stopped(p2))
		return (p2);

	if (p1->ki_estcpu > p2->ki_estcpu)
		return (p1);
	if (p1->ki_estcpu < p2->ki_estcpu)
		return (p2);

	if (p1->ki_slptime < p2->ki_slptime)
		return (p1);
	if (p1->ki_slptime > p2->ki_slptime)
		return (p2);

	if (strcmp(p1->ki_comm, p2->ki_comm) < 0)
		return (p1);
	if (strcmp(p1->ki_comm, p2->ki_comm) > 0)
		return (p2);

	if (p1->ki_pid > p2->ki_pid)
		return (p1);
	return (p2);
}
예제 #6
0
/**
 * Main loop of the DrawThread
 */
void
DrawThread::run()
{
  set_low_priority();

  // bounds_dirty maintains the status of whether the map
  // bounds have changed and there are pending idle calls
  // to be run in the map.

  // wait until the startup is finished
  running.wait();

  // Get data from the DeviceBlackboard
  map.ExchangeBlackboard();

  bool bounds_dirty = true;

  // circle until application is closed
  while (true) {
    if (!bounds_dirty)
      trigger.wait();

    if (!bounds_dirty || trigger.wait(MIN_WAIT_TIME)) {
      // take control (or wait for the resume())
      running.wait();

      /* got the "stop" trigger? */
      if (is_stopped())
        break;

      trigger.reset();

      // Get data from the DeviceBlackboard
      map.ExchangeBlackboard();

      // Draw the moving map
      map.repaint();

      if (trigger.test()) {
        // interrupt re-calculation of bounds if there was a 
        // request made.  Since we will re-enter, we know the remainder
        // of this code will be called anyway.
        continue;
      }

      bounds_dirty = map.Idle();
    } else if (bounds_dirty) {
      // take control (or wait for the resume())
      running.wait();

      /* got the "stop" trigger? */
      if (is_stopped())
        break;

      bounds_dirty = map.Idle();
    }
  }
}
예제 #7
0
void AmRtpReceiverThread::stop_and_wait()
{
    if(!is_stopped()) {
        stop();

        while(!is_stopped())
            usleep(10000);
    }
}
예제 #8
0
파일: consumer_multi.c 프로젝트: Enlik/mlt
static void *consumer_thread( void *arg )
{
    mlt_consumer consumer = arg;
    mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
    mlt_frame frame = NULL;

    // Determine whether to stop at end-of-media
    int terminate_on_pause = mlt_properties_get_int( properties, "terminate_on_pause" );
    int terminated = 0;

    // Loop while running
    while ( !terminated && !is_stopped( consumer ) )
    {
        // Get the next frame
        frame = mlt_consumer_rt_frame( consumer );

        // Check for termination
        if ( terminate_on_pause && frame )
            terminated = mlt_properties_get_double( MLT_FRAME_PROPERTIES( frame ), "_speed" ) == 0.0;

        // Check that we have a frame to work with
        if ( frame && !terminated && !is_stopped( consumer ) )
        {
            if ( mlt_properties_get_int( MLT_FRAME_PROPERTIES(frame), "rendered" ) )
            {
                if ( mlt_properties_get_int( MLT_FRAME_PROPERTIES(frame), "_speed" ) == 0 )
                    foreach_consumer_refresh( consumer );
                foreach_consumer_put( consumer, frame );
            }
            else
            {
                int dropped = mlt_properties_get_int( properties, "_dropped" );
                mlt_log_info( MLT_CONSUMER_SERVICE(consumer), "dropped frame %d\n", ++dropped );
                mlt_properties_set_int( properties, "_dropped", dropped );
            }
            mlt_frame_close( frame );
        }
        else
        {
            if ( frame && terminated )
            {
                // Send this termination frame to nested consumers for their cancellation
                foreach_consumer_put( consumer, frame );
            }
            if ( frame )
                mlt_frame_close( frame );
            terminated = 1;
        }
    }

    // Indicate that the consumer is stopped
    mlt_consumer_stopped( consumer );

    return NULL;
}
예제 #9
0
void CAnimationThread::calculate_frame(bool zoom)
{
    current_thread = dialog->NewCalculationThread();
    current_thread->start();
    current_thread->wait();
    if( !is_stopped() )
        dialog->PostReadAndWait();
    delete current_thread;
    current_thread = NULL;
    if( !is_stopped() )
		dialog->PostUpdateDataAndWait();
    if( !is_stopped() && zoom )
        dialog->PostZoomAndWait(zoom_in);
}
예제 #10
0
/**
 * @brief Makes the movement restart after a delay when it is finished.
 * @param delay the movement will restart after this delay in milliseconds (0 to avoid this)
 */
void CircleMovement::set_loop(uint32_t delay) {

  this->loop_delay = delay;
  if (delay != 0 && is_stopped()) {
    this->restart_date = System::now() + delay;
  }
}
예제 #11
0
파일: timer.cpp 프로젝트: shiver/shooter
std::uint32_t Timer::get_ticks() {
    if (is_stopped()) {
        return _ticks - _start_ticks;
    }

    return SDL_GetTicks() - _start_ticks;
}
예제 #12
0
void Timer::stop() noexcept
{
	if (is_stopped())
		return;
	stop_point = clock::now();
	stopped = true;
}
예제 #13
0
bool CPUThread::check_status()
{
    std::unique_lock<std::mutex> lock(mutex, std::defer_lock);

    while (true)
    {
        CHECK_EMU_STATUS; // check at least once

        if (!is_paused()) break;

        if (!lock)
        {
            lock.lock();
            continue;
        }

        cv.wait(lock);
    }

    if (m_state.load() & CPU_STATE_RETURN || is_stopped())
    {
        return true;
    }

    if (m_state.load() & CPU_STATE_STEP)
    {
        // set PAUSE, but allow to execute once
        m_state |= CPU_STATE_PAUSED;
        m_state &= ~CPU_STATE_STEP;
    }

    return false;
}
예제 #14
0
CPUThread::CPUThread(CPUThreadType type, const std::string& name, std::function<std::string()> thread_name)
	: m_id(idm::get_last_id())
	, m_type(type)
	, m_name(name)
{
	start(std::move(thread_name), [this]
	{
		g_tls_current_cpu_thread = this;

		Emu.SendDbgCommand(DID_CREATE_THREAD, this);

		std::unique_lock<std::mutex> lock(mutex);

		// check thread status
		while (joinable() && is_alive())
		{
			CHECK_EMU_STATUS;

			// check stop status
			if (!is_stopped())
			{
				if (lock) lock.unlock();

				try
				{
					task();
				}
				catch (CPUThreadReturn)
				{
					;
				}
				catch (CPUThreadStop)
				{
					m_state |= CPU_STATE_STOPPED;
				}
				catch (CPUThreadExit)
				{
					m_state |= CPU_STATE_DEAD;
					break;
				}
				catch (...)
				{
					dump_info();
					throw;
				}

				m_state &= ~CPU_STATE_RETURN;
				continue;
			}

			if (!lock)
			{
				lock.lock();
				continue;
			}

			cv.wait(lock);
		}
	});
}
예제 #15
0
파일: consumer_multi.c 프로젝트: Enlik/mlt
static int start( mlt_consumer consumer )
{
    // Check that we're not already running
    if ( is_stopped( consumer ) )
    {
        mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
        pthread_t *thread = calloc( 1, sizeof( pthread_t ) );

        // Assign the thread to properties with automatic dealloc
        mlt_properties_set_data( properties, "thread", thread, sizeof( pthread_t ), free, NULL );

        // Set the running state
        mlt_properties_set_int( properties, "running", 1 );
        mlt_properties_set_int( properties, "joined", 0 );

        // Construct and start nested consumers
        if ( !mlt_properties_get_data( properties, "0.consumer", NULL ) )
            foreach_consumer_init( consumer );
        foreach_consumer_start( consumer );

        // Create the thread
        pthread_create( thread, NULL, consumer_thread, consumer );
    }
    return 0;
}
예제 #16
0
long worker_thread::execute(void *arg)
{
#ifdef DEBUG_PRINTS
    cout << "worker_thread::execute = " + get_name() << endl;
#endif

    // Make GCC happy (-Wextra)
    if (arg) {
        return THREAD_INTERNAL_ERROR;
    }

    // Get pointer to thread's data
    volatile WORKER_DATA *data =
        (WORKER_DATA *) (m_data_base_addr + (m_work_id) * sizeof(WORKER_DATA));

    *data = 0;

    // Produce data
    while ( !is_stopped() ) {

        *data += 1;

        update_exe_cnt();

        sleep(1);
    }

    return THREAD_SUCCESS;
}
예제 #17
0
struct proc *
cmp_procs(struct proc *p1, struct proc *p2)
{
	void	*ptr1, *ptr2;

	if (is_runnable(p1) && !is_runnable(p2))
		return (p1);
	if (!is_runnable(p1) && is_runnable(p2))
		return (p2);

	if (is_stopped(p1) && !is_stopped(p2))
		return (p1);
	if (!is_stopped(p1) && is_stopped(p2))
		return (p2);

	if (p1->p_estcpu > p2->p_estcpu)
		return (p1);
	if (p1->p_estcpu < p2->p_estcpu)
		return (p2);

	if (p1->p_slptime < p2->p_slptime)
		return (p1);
	if (p1->p_slptime > p2->p_slptime)
		return (p2);

	if ((p1->p_flag & P_SINTR) && !(p2->p_flag & P_SINTR))
		return (p1);
	if (!(p1->p_flag & P_SINTR) && (p2->p_flag & P_SINTR))
		return (p2);

	ptr1 = LIST_FIRST(&p1->p_children);
	ptr2 = LIST_FIRST(&p2->p_children);
	if (ptr1 == NULL && ptr2 != NULL)
		return (p1);
	if (ptr1 != NULL && ptr2 == NULL)
		return (p2);

	if (strcmp(p1->p_comm, p2->p_comm) < 0)
		return (p1);
	if (strcmp(p1->p_comm, p2->p_comm) > 0)
		return (p2);

	if (p1->p_pid > p2->p_pid)
		return (p1);
	return (p2);
}
예제 #18
0
    LatencyCounter& check_and_stop()
    {
        if (!is_stopped()) {
            return stop();
        }

        return *this;
    }
예제 #19
0
파일: Arrow.cpp 프로젝트: Arseth/solarus
/**
 * \brief This function is called when a switch detects a collision with this entity.
 * \param sw the switch
 * \param collision_mode the collision mode that detected the event
 */
void Arrow::notify_collision_with_switch(Switch& sw, CollisionMode collision_mode) {

  if (sw.is_arrow_target() && is_stopped()) {
    sw.try_activate(*this);
  }
  else if (sw.is_solid() && is_flying()) {
    sw.try_activate();
    attach_to(sw);
  }
}
예제 #20
0
파일: Main.cpp 프로젝트: lordmulder/INetGet
	virtual uint32_t main(void)
	{
		if(!m_client->open(m_verb, m_url, m_post_data, m_referrer, m_timestamp))
		{
			set_error_text(m_client->get_error_text());
			return CONNECTION_ERR_INET;
		}

		return is_stopped() ? CONNECTION_ERR_ABRT : CONNECTION_COMPLETE;
	}
예제 #21
0
 duration elapsed(void)
 {
     if (is_stopped())
         return duration::zero();
     else
     if (is_paused<N>())
         return (points_[N].second - points_[N].first);
     else
         return ClockT::now() - points_[N].first;
 }
예제 #22
0
void COutputHandleTask::exec()
{
	while(!is_stopped())
	{
		///
		if (m_pIoEvtNotifier->exec() < 0)
		{
			break;
		}
	}
}
예제 #23
0
/**
 * @brief Changes the direction of the movement vector, keeping the same speed.
 *
 * x_speed and y_speed are recomputed so that the total speed is unchanged.
 * Warning: if x_speed and y_speed are both equal to zero, this function
 * stops the program on an error message.
 *
 * @param angle the new movement direction in radians
 */
void StraightMovement::set_angle(double angle) {

  if (!is_stopped()) {
    double speed = get_speed();
    set_x_speed(speed * std::cos(angle));
    set_y_speed(-speed * std::sin(angle));
  }
  this->angle = angle;

  notify_movement_changed();
}
예제 #24
0
void DialerThread::run() {
	sleep(15); // wait for sems to completely start up
	while (!is_stopped()) {		
		DBG("dialing...");
		AmUAC::dialout("blibla", "announce_auth", 
					   r_uri, from, from_uri, to);
		// every 10 minutes
		sleep(100);

	} 
}
예제 #25
0
void CInputHandleTask::exec()
{
	CMN_ASSERT(NULL != m_pIoEvtNotifier);

	///main logic circle
	while (!is_stopped())
	{
		///
		if (m_pIoEvtNotifier->exec() < 0)
		{
			break;
		}
	}
}
예제 #26
0
struct kinfo_proc2 *
cmp_procs(struct kinfo_proc2 *p1, struct kinfo_proc2 *p2)
{
	if (is_runnable(p1) && !is_runnable(p2))
		return (p1);
	if (!is_runnable(p1) && is_runnable(p2))
		return (p2);

	if (is_stopped(p1) && !is_stopped(p2))
		return (p1);
	if (!is_stopped(p1) && is_stopped(p2))
		return (p2);

	if (p1->p_estcpu > p2->p_estcpu)
		return (p1);
	if (p1->p_estcpu < p2->p_estcpu)
		return (p2);

	if (p1->p_slptime < p2->p_slptime)
		return (p1);
	if (p1->p_slptime > p2->p_slptime)
		return (p2);

	if ((p1->p_flag & P_SINTR) && !(p2->p_flag & P_SINTR))
		return (p1);
	if (!(p1->p_flag & P_SINTR) && (p2->p_flag & P_SINTR))
		return (p2);

	if (strcmp(p1->p_comm, p2->p_comm) < 0)
		return (p1);
	if (strcmp(p1->p_comm, p2->p_comm) > 0)
		return (p2);

	if (p1->p_pid > p2->p_pid)
		return (p1);
	return (p2);
}
예제 #27
0
/**
 * \brief Starts the next 8-pixel trajectory of the path movement.
 *
 * This function is called when an 8-pixel trajectory of the movement is finished,
 * or when the movement is restarted.
 * Before starting the 8-pixel move, if the property must_be_aligned is true,
 * the entity's top-left corner tries to get aligned with the 8*8 squares of the grid.
 */
void PathMovement::start_next_elementary_move() {

  Entity* entity = get_entity();

  // don't move while the entity is unknown
  if (entity == nullptr) {
    return;
  }

  // before starting the move, check that the entity is aligned with the 8*8 squares grid if necessary
  if (snap_to_grid && !entity->is_aligned_to_grid()) {

    // the entity has to be aligned but is not
    snap();
  }

  // start the next step if we are ready
  if (!snap_to_grid || entity->is_aligned_to_grid()) {

    snapping = false;

    if (remaining_path.empty()) {
      // the path is finished
      if (loop) {
        // if the property 'loop' is true, repeat the same path again
        remaining_path = initial_path;
      }
      else if (!is_stopped()) {
        // the movement is finished: stop the entity
        stop();
      }
    }

    if (!remaining_path.empty()) {
      // normal case: there is a next trajectory to do

      current_direction = remaining_path[0] - '0';
      Debug::check_assertion(current_direction >= 0 && current_direction < 8,
          std::string("Invalid path '") + initial_path + "' (bad direction '"
          + remaining_path[0] + "')"
      );

      PixelMovement::set_delay(speed_to_delay(speed, current_direction));
      PixelMovement::set_trajectory(elementary_moves[current_direction]);
      remaining_path = remaining_path.substr(1);
    }
  }
}
예제 #28
0
 clock_t elapsed(void)
 {
     if (is_stopped()) return 0;
     else
     if (is_paused())  return pause_elap_;
     else
     {
         clock_t now = ModelT::clock();
         if (start_time_ > now)
         {
             stop();
             return 0;
         }
         return now - start_time_;
     }
 }
예제 #29
0
void
WorkerThread::run()
{
  while (true) {
    /* wait for work */
    event_trigger.wait();

    /* paused? */
    running.wait();

    /* got the "stop" trigger? */
    if (is_stopped())
      break;

    /* do the actual work */
    tick();
  }
}
예제 #30
0
long cyclic_thread::execute(void *arg)
{
  const float delay_interval = 1.0 / m_frequency;

  struct timespec t1;
  struct timespec t2; 

  // Make GCC happy (-Wextra)
  if (arg) {
    return THREAD_INTERNAL_ERROR;
  }

  // Prepare first run
  if ( clock_gettime(get_clock_id(), &t1) ) {
    return THREAD_TIME_ERROR;
  }
  if ( get_new_time(&t1, delay_interval, &t2) != DELAY_SUCCESS ) {
    return THREAD_TIME_ERROR;
  }
  if ( delay_until(&t2) != DELAY_SUCCESS) {
    return THREAD_TIME_ERROR;
  }

  while ( !is_stopped() ) {

    // Do cyclic work
    if ( cyclic_execute() != THREAD_SUCCESS ) {
      return THREAD_INTERNAL_ERROR;
    }

    // Calculate next interval
    if ( get_new_time(&t2, delay_interval, &t2) != DELAY_SUCCESS ) {
      return THREAD_TIME_ERROR;
    }
    if ( delay_until(&t2) != DELAY_SUCCESS) {
      return THREAD_TIME_ERROR;
    }

    update_exe_cnt();
  }

  return THREAD_SUCCESS;
}