예제 #1
0
파일: lab5_1.c 프로젝트: kamocat/cs151
/*
 * This function counts between the first and second input.
 * If the first input is greater, it counts down.
 * If the first input is less, it counts up.
 */
void count_between( int input1, int input2 ) {
	if( input1 > input2 ) {
		count_down( input1, input2 );
	} else {
		count_up( input1, input2 );
	}
}
예제 #2
0
	// print the counting numbers to 0 from n.
	int count_down( int from )
	{
		cout << from << " ";

		return from == 1 ?
			0 : count_down( from - 1 );
	}
예제 #3
0
 /// Effect: Decrement the count is > 0. Unlocks the lock notify anyone waiting if we reached zero.
 /// Returns: true if count_ is 0.
 /// @ThreadSafe ensured by the @c lk parameter
 bool try_count_down(unique_lock<mutex> &lk)
 {
   if (count_ > 0)
   {
     return count_down(lk);
   }
   return true;
 }
예제 #4
0
 void Callback::transfer_ownership() {
   casadi_assert_message(!is_null(), "Null pointer.");
   casadi_assert_message(!(*this)->own_, "Ownership has already been transferred.");
   casadi_assert_message(getCount()>1, "There are no owning references");
   // Decrease the reference counter to offset the effect of the owning reference
   count_down();
   // Mark internal class as owning
   (*this)->own_ = true;
 }
예제 #5
0
SharedObject& SharedObject::operator=(const SharedObject& ref) {
  // quick return if the old and new pointers point to the same object
  if (node == ref.node) return *this;

  // decrease the counter and delete if this was the last pointer
  count_down();

  // save the new pointer
  node = ref.node;
  count_up();
  return *this;
}
예제 #6
0
파일: lab5_1.c 프로젝트: kamocat/cs151
int main( int argc, char **argv ) {
	int input1;
	int input2;
	do{
		get_inputs( &input1, &input2 );
		count_up( 0, input1 );
		count_down( input1, 0 );
		count_between( input1, input2 );
	} while( quit_or_rerun() );

	return 0;
}
예제 #7
0
파일: 416.cpp 프로젝트: ksyu/uvajudge
bool is_match(int n)
{
    int count = 9;

    while(n - 1 <= count)
    {
        if(count_down(n, count))
            return true;
        --count;
    }

    return false;
}
예제 #8
0
파일: lab4_4.c 프로젝트: kamocat/cs151
int main( int argc, char **argv ) {
	int input = get_input();
	count_up( MIN, input );
	count_down( input, "hello world" );
	return 0;
}
예제 #9
0
int main()
{
	init_sensors();

	int SET_POINT_VALUE = get_int_from_user("SetPnt=?", 20, 5);
	int END_POINT_VALUE = get_int_from_user("EndPnt=?", 145, 1);

	wait_with_message("Press B");
	count_down(2);

	
	int front = 0;
	int left = 0;
	int right = 0;
	int balance = 0;

	int left_speed = 0;
	int right_speed = 0;

	int set_point = 0;

	while(1)
	{
		left = analog_read(6);
		right = analog_read(5);
		front = analog_read(7);
		
		balance = 0;
		if (left > 20 || right > 20)
		{
			balance = right - left - 20;
		}

		if(front < SET_POINT_VALUE)
		{
			left_speed = 110 - (1.0 * 0.54838709677419354838709677419355 * front);
			right_speed = 110 - (1.0 * 0.54838709677419354838709677419355 * front);
		}
		else
		{
			while(left_speed > 25 || right_speed > 25)
			{
				left_speed--;
				right_speed--;
				set_motors(left_speed + balance,right_speed - balance);
				play_frequency(200, 50, 14);
			}

		}

		if (set_point == 0 && front > END_POINT_VALUE)
		{
			set_point = 1;
			set_motors(25,25);
			
		}
		else
		{
			set_motors(left_speed + balance,right_speed - balance);
		}

		if (set_point == 1 && front < END_POINT_VALUE)
		{
			break;
		}


	}


	halt();

	clear();
	print("f=");
	print_long(front);

	// end
	while(1);
}
예제 #10
0
파일: Job_i.cpp 프로젝트: DOCGroup/ACE_TAO
void
Job_i::work (CORBA::ULong work,
       CORBA::Short importance)
{
  static CORBA::ULong prime_number = 9619;

  if (TAO_debug_level > 0)
    ACE_DEBUG ((LM_DEBUG,
    "Job_i::work: %d units of work\n",
    work));

  CORBA::Object_var object =
    this->dt_creator_->orb ()->resolve_initial_references (
                                         "RTScheduler_Current");

  RTScheduling::Current_var current =
    RTScheduling::Current::_narrow (object.in ());
  RTScheduling::Current::IdType_var guid = current->id ();

  if (guid_ == 0)
    ACE_OS::memcpy (&guid_,
                    guid->get_buffer (),
                    sizeof (guid->length ()));

  if (TAO_debug_level > 0)
    ACE_DEBUG ((LM_DEBUG,
    "%t Guid is %d, Importance is %d\n",
    guid_,
    importance));

  ACE_TCHAR msg [BUFSIZ];
  ACE_OS::sprintf (msg,
                   ACE_TEXT("Guid is ")
                   ACE_SIZE_T_FORMAT_SPECIFIER
                   ACE_TEXT("\n"), guid_);

  dt_creator_->log_msg (ACE_TEXT_ALWAYS_CHAR(msg));

  for (; work != 0; work--)
    {
      //    ACE_hrtime_t now = ACE_OS::gethrtime ();

      ACE_Time_Value *base_time = dt_creator_->base_time ();
      if (base_time == 0)
        return;

      ACE_Time_Value run_time = ACE_OS::gettimeofday () - *(base_time);
      TASK_STATS::instance ()->sample (run_time.sec (), guid_);

      ACE_Time_Value count_down_time (1);
      ACE_Countdown_Time count_down (&count_down_time);

      while (count_down_time > ACE_Time_Value::zero)
        {
          ACE::is_prime (prime_number,
            2,
            prime_number / 2);
          count_down.update ();
        }

      run_time = ACE_OS::gettimeofday () - *(dt_creator_->base_time ());
      TASK_STATS::instance ()->sample (run_time.sec (), guid_);

      CORBA::Policy_var sched_param;
      sched_param = dt_creator_->sched_param (importance);
      const char * name = 0;
      current->update_scheduling_segment (name,
                sched_param.in (),
                sched_param.in ());
    }
}
예제 #11
0
int main( void )
{
    count_down();
    return 0;
}
예제 #12
0
void SharedObject::assignNode(SharedObjectNode* node_) {
  count_down();
  node = node_;
  count_up();
}
예제 #13
0
SharedObject::~SharedObject() {
  count_down();
}
예제 #14
0
파일: FP_Task.cpp 프로젝트: CCJY/ATCD
int
FP_Task::perform_task (void)
{
  static CORBA::ULong prime_number = 9619;

  for (int j = 0; j < this->iter_; j++)
    {
      ACE_Time_Value run_time = ACE_OS::gettimeofday () - *base_time_;
      TASK_STATS::instance ()->sample (run_time.sec (), count_);

      ACE_Time_Value count_down_time (1);
      ACE_Countdown_Time count_down (&count_down_time);

      while (count_down_time > ACE_Time_Value::zero)
        {
          ACE::is_prime (prime_number,
                         2,
                         prime_number / 2);

          count_down.update ();
        }
    }

  if (TAO_debug_level > 0)
    ACE_DEBUG ((LM_DEBUG,
                "%d\n",
                count_));

  if (this->dist_)
    {
      job_->work (this->load_, this->importance_);


      for (int j = 0; j < this->iter_; j++)
        {
          ACE_Time_Value run_time = ACE_OS::gettimeofday () - *base_time_;
          TASK_STATS::instance ()->sample (run_time.sec (), count_);

          ACE_Time_Value count_down_time (1);
          ACE_Countdown_Time count_down (&count_down_time);

          while (count_down_time > ACE_Time_Value::zero)
            {
              if (TAO_debug_level > 0)
                ACE_DEBUG ((LM_DEBUG,
                            "Waiting on count down\n"));


              ACE::is_prime (prime_number,
                             2,
                             prime_number / 2);
              count_down.update ();
            }
        }

      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    "%d\n",
                    count_));
    }

  if (dist_)
    job_->shutdown ();
  return 0;
}
예제 #15
0
int
MIF_Task::perform_task (void)
{
  try
    {

      ACE_TCHAR msg [BUFSIZ];
      ACE_OS::sprintf (msg,
                       ACE_TEXT("MIF_Task::perform_task ")
                       ACE_SIZE_T_FORMAT_SPECIFIER
                       ACE_TEXT("\n"),
                       count_);
      dt_creator_->log_msg (ACE_TEXT_ALWAYS_CHAR(msg));

      static CORBA::ULong prime_number = 9619;
      CORBA::Policy_var sched_param;
      sched_param = dt_creator_->sched_param (this->importance_);
      const char * name = 0;

      for (int i = 0; i < this->iter_; i++)
        {
          ACE_Time_Value run_time = ACE_OS::gettimeofday () - *base_time_;
          TASK_STATS::instance ()->sample (run_time.sec (), count_);

          ACE_Time_Value count_down_time (1);
          ACE_Countdown_Time count_down (&count_down_time);

          while (count_down_time > ACE_Time_Value::zero)
            {
              ACE::is_prime (prime_number,
                             2,
                             prime_number / 2);

              count_down.update ();
            }

          current_->update_scheduling_segment (name,
                                               sched_param.in (),
                                               sched_param.in ());
        }

      if (this->dist_)
        {
          this->job_->work (this->load_,
                            this->importance_);

          for (int j = 0; j < this->iter_; j++)
            {
              ACE_Time_Value run_time = ACE_OS::gettimeofday () - *base_time_;
              TASK_STATS::instance ()->sample (run_time.sec (), count_);

              ACE_Time_Value count_down_time (1);
              ACE_Countdown_Time count_down (&count_down_time);

              while (count_down_time > ACE_Time_Value::zero)
                {

                  ACE::is_prime (prime_number,
                                 2,
                                 prime_number / 2);
                  count_down.update ();
                }

              current_->update_scheduling_segment (name,
                                                   sched_param.in (),
                                                   sched_param.in ());

            }

        }

    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught exception:");
      return -1;
    }

  if (TAO_debug_level > 0)
    ACE_DEBUG ((LM_DEBUG,
    "Thread %d\n",
    this->count_));

  if (dist_)
    job_->shutdown ();

  return 0;
}