예제 #1
0
void function(void) 
{
		key_diy();
		switch(key_status)
		{
			case 1:
				function1();
				break;
			case 2:
				function2();
				break;
			case 3:
				function3();
				break;
			case 4:
				function4();
				break;
			case 5:
				function5();
				break;
			case 6:
				function6();
				break;
			case 7:
				function7();
				break;
			default:
				function0();
				break;
		}
	
	
}
예제 #2
0
double call_function(int function,double arg){
	if(function==1){return function1(arg);}
	if(function==2){return function2(arg);}
	if(function==3){return function3(arg,0.5);}//using 0.5 for the elliptic modulous
	//should never get here
	printf("Unsupported function number: %d\n",function);
	exit(2);
}
예제 #3
0
int main(int argc, char *argv[]) {

    // Call the functions

    function1();
    printf("Function 2: %d\n", function2());
    printf("Function 3: %d\n", function3(2, 3));

    return 0;
}
예제 #4
0
파일: fuzzy_db.cpp 프로젝트: lysevi/concret
  MyuFunctions make_myu_functions(const Concrete::CData&cdata,const ivector&numbers,const MinMax&minmax)
  {
    const int x_length=minmax.max_x.size();

    Function*y_function=function3(coord(minmax.min_y,0),
				  coord((minmax.max_y+minmax.min_y)/2.0,1.0),
				  coord(minmax.max_y,0));
    
    MyuFunctions result={fvector(0),y_function};
    
    for(int i=0;i<numbers.size();++i){
      for(int j=0;j<x_length;++j){
	Function*max_f=function3(coord(minmax.min_x[i],0),coord(cdata[numbers[i]]->at(j),1.0),
				 coord(minmax.max_x[i],0));
	result.x_funcs.push_back(max_f);
      }
    }
    return result;
  }
예제 #5
0
int main()
{
	int a;
	float b;

	function1('c', 1);
	a=function2(1, 1);
	b=function3('c', 'c');

	return 0;
}
예제 #6
0
int main(){
	
	int num[10]={0};
	int next_number[10] = {0};
	int temp;
	int user_num, range;
	int i,remainder;
	int number;
	
	printf("Hi,Enter any number you want : ");
	scanf("%d",&user_num);
	
	//whole number is separated
	temp = user_num;
	i = 9;
	while(temp != 0){
		remainder = temp % 10;
		temp = temp/10;
		num[i] = remainder;
		i--;
	}
/*	range = i;
	//printf("%d",range);
	
	for(i = 0; i < range ; i++)
	{
		next_number[i] = num[(range-1)-i];
	}
*/	

	//printing in words
	for(i = 0 ; i < 10; i++)
	{
		
		
		if(i == 0 || i == 2 || i == 3 || i == 5)
		{
			printf("%s ",function1(i));
		}
		
		else if(i == 1){
			printf("%s",function3(i));
		}
		
		else if(i== 2|| i == 4 || i == 6)
		{
			printf("%s",function2(i));
		}
		
	}
		
	return 0;	
}
예제 #7
0
static void function4 (struct _file_ * port, char const * units, unsigned wait)

{
	signed value;
	for (value = 0; value < 128; value++)
	{
		function2 (port, units, wait, (value << 8) | (value << 1) | 1);
		function3 (port, units, wait);
		SLEEP (wait);
	}
	return;
}
예제 #8
0
int main(){
        #pragma omp sections 
	{
                #pragma omp section
                    function1();
                
                #pragma omp section
                	function2();
               
                #pragma omp section
                  	function3();
    }
	return 0;
}
예제 #9
0
파일: main.c 프로젝트: rishik1/reposi
int main(void){
	rod sample;													//Sample to type rod
	float diameter = 2;												// diameter as float intialized to value =2 for function 1
	float P;													// Load  "P" as float for function 1
	float Force; 													// Force as float to catch return value of function 2
	float Pressure;													// Pressure as float to catch return value of function 3
	float depth = 30;												// depth as float for function 3
	int distance;													// distance for function 2

	while(diameter <=10)												//Loop till diameter is smaller than or equals to 10 & starts from diameter = 2
		           {
				        for(P = 50000; P <= 200000 ; P = P+25000)					//Loop till Load "p" <=200000 with increment of 25000 and starts from P = 50000
					{
						 sample = function1(diameter,P);					// function1 called and returned value  catched in sample
						 printf(" %f,%f\t",sample.stress,sample.strain);			// STRESS and STRAIN printed 
					}
			    printf("\n");
			    diameter = diameter + 0.5;									//diameter  incremeted by 0.5
		          }		
	
	for(distance = 10; distance <= 100 ; distance = distance+10)							// Loop from distance =10 till distance smaller than or equals to 100 with increment of 10
	{
		 Force = function2(distance);										// function2 called and return value stored in Force
		 printf("\n\t %f",Force);										// Force printed
	}

	printf("\n\n");

	do{														// Loop from depth =30 til depth smaller than or equals to 150

		Pressure = function3(depth);										//function3 called and returned value stored in Pressure										
		printf("%f\n", Pressure);									
		depth = depth + 10;											// loop incremented by 10

	  }while(depth <= 150);													
			
return 0;

}
예제 #10
0
int main() {
	int sel = -1;
	char buffer[INPUT_LENGTH];
	int isInputValid = INPUT_INVALID;
	Num Num1;
	Num Num2;
	Num NumResult[5];

	for(;;) {
		display_menu();
		fflush(stdin);		
		
		while(1) {
			isInputValid = getTwoInput(&Num1, &Num2);			
			
			if(isInputValid == INPUT_INVALID) {
				printf("Please input again...\n");
			} else {
				break;
			}
			
		}
		function1(&Num1, &Num2,	&(NumResult[0]));
		function2(&Num1, &Num2,	&(NumResult[1]));
		function3(&Num1, &Num2,	&(NumResult[2]));
		function4(&Num1, &Num2,	&(NumResult[3]));
		function5(&Num1, &Num2,	&(NumResult[4]));
		
		printResult(&Num1, &Num2, NumResult);
		
	}
	printf("종료합니다.\n");
	getchar();

	return 0;
}
예제 #11
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::thread_pool pool;

  std::experimental::dispatch(std::experimental::wrap(pool, function1), handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, function1), &handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, function1), handler2());
  std::experimental::dispatch(std::experimental::wrap(pool, function1), h2);
  std::experimental::dispatch(std::experimental::wrap(pool, function1), ch2);
  std::experimental::dispatch(std::experimental::wrap(pool, function1), handler3());
  std::experimental::dispatch(std::experimental::wrap(pool, function1), std::move(h3));
  std::future<void> fut1 = std::experimental::dispatch(std::experimental::wrap(pool, function1), std::experimental::use_future);
  fut1.get();

  std::experimental::dispatch(std::experimental::wrap(pool, &function1), handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, &function1), &handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, &function1), handler2());
  std::experimental::dispatch(std::experimental::wrap(pool, &function1), h2);
  std::experimental::dispatch(std::experimental::wrap(pool, &function1), ch2);
  std::experimental::dispatch(std::experimental::wrap(pool, &function1), handler3());
  std::experimental::dispatch(std::experimental::wrap(pool, &function1), std::move(h3));
  std::future<void> fut2 = std::experimental::dispatch(std::experimental::wrap(pool, &function1), std::experimental::use_future);
  fut2.get();

  std::experimental::dispatch(std::experimental::wrap(pool, function2()), handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, function2()), &handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, function2()), handler2());
  std::experimental::dispatch(std::experimental::wrap(pool, function2()), h2);
  std::experimental::dispatch(std::experimental::wrap(pool, function2()), ch2);
  std::experimental::dispatch(std::experimental::wrap(pool, function2()), handler3());
  std::experimental::dispatch(std::experimental::wrap(pool, function2()), std::move(h3));
  std::future<void> fut3 = std::experimental::dispatch(std::experimental::wrap(pool, function2()), std::experimental::use_future);
  fut3.get();

  std::experimental::dispatch(std::experimental::wrap(pool, f2), handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, f2), &handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, f2), handler2());
  std::experimental::dispatch(std::experimental::wrap(pool, f2), h2);
  std::experimental::dispatch(std::experimental::wrap(pool, f2), ch2);
  std::experimental::dispatch(std::experimental::wrap(pool, f2), handler3());
  std::experimental::dispatch(std::experimental::wrap(pool, f2), std::move(h3));
  std::future<void> fut4 = std::experimental::dispatch(std::experimental::wrap(pool, f2), std::experimental::use_future);
  fut4.get();

  std::experimental::dispatch(std::experimental::wrap(pool, cf2), handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, cf2), &handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, cf2), handler2());
  std::experimental::dispatch(std::experimental::wrap(pool, cf2), h2);
  std::experimental::dispatch(std::experimental::wrap(pool, cf2), ch2);
  std::experimental::dispatch(std::experimental::wrap(pool, cf2), handler3());
  std::experimental::dispatch(std::experimental::wrap(pool, cf2), std::move(h3));
  std::future<void> fut5 = std::experimental::dispatch(std::experimental::wrap(pool, cf2), std::experimental::use_future);
  fut5.get();

  std::experimental::dispatch(std::experimental::wrap(pool, function3()), handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, function3()), &handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, function3()), handler2());
  std::experimental::dispatch(std::experimental::wrap(pool, function3()), h2);
  std::experimental::dispatch(std::experimental::wrap(pool, function3()), ch2);
  std::experimental::dispatch(std::experimental::wrap(pool, function3()), handler3());
  std::experimental::dispatch(std::experimental::wrap(pool, function3()), std::move(h3));
  std::future<void> fut6 = std::experimental::dispatch(std::experimental::wrap(pool, function3()), std::experimental::use_future);
  fut6.get();

  std::experimental::dispatch(std::experimental::wrap(pool, std::move(f3)), handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, std::move(f3)), &handler1);
  std::experimental::dispatch(std::experimental::wrap(pool, std::move(f3)), handler2());
  std::experimental::dispatch(std::experimental::wrap(pool, std::move(f3)), h2);
  std::experimental::dispatch(std::experimental::wrap(pool, std::move(f3)), ch2);
  std::experimental::dispatch(std::experimental::wrap(pool, std::move(f3)), handler3());
  std::experimental::dispatch(std::experimental::wrap(pool, std::move(f3)), std::move(h3));
  std::future<void> fut7 = std::experimental::dispatch(std::experimental::wrap(pool, std::move(f3)), std::experimental::use_future);
  fut7.get();

  pool.join();
  assert(function_count == 56);
  assert(handler_count == 49);
}
예제 #12
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::system_executor ex;

  std::experimental::dispatch(ex.wrap(function1), handler1);
  std::experimental::dispatch(ex.wrap(function1), &handler1);
  std::experimental::dispatch(ex.wrap(function1), handler2());
  std::experimental::dispatch(ex.wrap(function1), h2);
  std::experimental::dispatch(ex.wrap(function1), ch2);
  std::experimental::dispatch(ex.wrap(function1), handler3());
  std::experimental::dispatch(ex.wrap(function1), std::move(h3));
  std::future<void> fut1 = std::experimental::dispatch(ex.wrap(function1), std::experimental::use_future);
  fut1.get();

  std::experimental::dispatch(ex.wrap(&function1), handler1);
  std::experimental::dispatch(ex.wrap(&function1), &handler1);
  std::experimental::dispatch(ex.wrap(&function1), handler2());
  std::experimental::dispatch(ex.wrap(&function1), h2);
  std::experimental::dispatch(ex.wrap(&function1), ch2);
  std::experimental::dispatch(ex.wrap(&function1), handler3());
  std::experimental::dispatch(ex.wrap(&function1), std::move(h3));
  std::future<void> fut2 = std::experimental::dispatch(ex.wrap(&function1), std::experimental::use_future);
  fut2.get();

  std::experimental::dispatch(ex.wrap(function2()), handler1);
  std::experimental::dispatch(ex.wrap(function2()), &handler1);
  std::experimental::dispatch(ex.wrap(function2()), handler2());
  std::experimental::dispatch(ex.wrap(function2()), h2);
  std::experimental::dispatch(ex.wrap(function2()), ch2);
  std::experimental::dispatch(ex.wrap(function2()), handler3());
  std::experimental::dispatch(ex.wrap(function2()), std::move(h3));
  std::future<void> fut3 = std::experimental::dispatch(ex.wrap(function2()), std::experimental::use_future);
  fut3.get();

  std::experimental::dispatch(ex.wrap(f2), handler1);
  std::experimental::dispatch(ex.wrap(f2), &handler1);
  std::experimental::dispatch(ex.wrap(f2), handler2());
  std::experimental::dispatch(ex.wrap(f2), h2);
  std::experimental::dispatch(ex.wrap(f2), ch2);
  std::experimental::dispatch(ex.wrap(f2), handler3());
  std::experimental::dispatch(ex.wrap(f2), std::move(h3));
  std::future<void> fut4 = std::experimental::dispatch(ex.wrap(f2), std::experimental::use_future);
  fut4.get();

  std::experimental::dispatch(ex.wrap(cf2), handler1);
  std::experimental::dispatch(ex.wrap(cf2), &handler1);
  std::experimental::dispatch(ex.wrap(cf2), handler2());
  std::experimental::dispatch(ex.wrap(cf2), h2);
  std::experimental::dispatch(ex.wrap(cf2), ch2);
  std::experimental::dispatch(ex.wrap(cf2), handler3());
  std::experimental::dispatch(ex.wrap(cf2), std::move(h3));
  std::future<void> fut5 = std::experimental::dispatch(ex.wrap(cf2), std::experimental::use_future);
  fut5.get();

  std::experimental::dispatch(ex.wrap(function3()), handler1);
  std::experimental::dispatch(ex.wrap(function3()), &handler1);
  std::experimental::dispatch(ex.wrap(function3()), handler2());
  std::experimental::dispatch(ex.wrap(function3()), h2);
  std::experimental::dispatch(ex.wrap(function3()), ch2);
  std::experimental::dispatch(ex.wrap(function3()), handler3());
  std::experimental::dispatch(ex.wrap(function3()), std::move(h3));
  std::future<void> fut6 = std::experimental::dispatch(ex.wrap(function3()), std::experimental::use_future);
  fut6.get();

  std::experimental::dispatch(ex.wrap(std::move(f3)), handler1);
  std::experimental::dispatch(ex.wrap(std::move(f3)), &handler1);
  std::experimental::dispatch(ex.wrap(std::move(f3)), handler2());
  std::experimental::dispatch(ex.wrap(std::move(f3)), h2);
  std::experimental::dispatch(ex.wrap(std::move(f3)), ch2);
  std::experimental::dispatch(ex.wrap(std::move(f3)), handler3());
  std::experimental::dispatch(ex.wrap(std::move(f3)), std::move(h3));
  std::future<void> fut7 = std::experimental::dispatch(ex.wrap(std::move(f3)), std::experimental::use_future);
  fut7.get();

  assert(function_count == 56);
  assert(handler_count == 49);
}
예제 #13
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  invoke(std::experimental::chain(function1));
  invoke(std::experimental::chain(function1, handler1));
  invoke(std::experimental::chain(function1, &handler1));
  invoke(std::experimental::chain(function1, handler2()));
  invoke(std::experimental::chain(function1, h2));
  invoke(std::experimental::chain(function1, ch2));
  invoke(std::experimental::chain(function1, handler3()));
  invoke(std::experimental::chain(function1, std::move(h3)));

  invoke(std::experimental::chain(&function1));
  invoke(std::experimental::chain(&function1, handler1));
  invoke(std::experimental::chain(&function1, &handler1));
  invoke(std::experimental::chain(&function1, handler2()));
  invoke(std::experimental::chain(&function1, h2));
  invoke(std::experimental::chain(&function1, ch2));
  invoke(std::experimental::chain(&function1, handler3()));
  invoke(std::experimental::chain(&function1, std::move(h3)));

  invoke(std::experimental::chain(function2()));
  invoke(std::experimental::chain(function2(), handler1));
  invoke(std::experimental::chain(function2(), &handler1));
  invoke(std::experimental::chain(function2(), handler2()));
  invoke(std::experimental::chain(function2(), h2));
  invoke(std::experimental::chain(function2(), ch2));
  invoke(std::experimental::chain(function2(), handler3()));
  invoke(std::experimental::chain(function2(), std::move(h3)));

  invoke(std::experimental::chain(f2));
  invoke(std::experimental::chain(f2, handler1));
  invoke(std::experimental::chain(f2, &handler1));
  invoke(std::experimental::chain(f2, handler2()));
  invoke(std::experimental::chain(f2, h2));
  invoke(std::experimental::chain(f2, ch2));
  invoke(std::experimental::chain(f2, handler3()));
  invoke(std::experimental::chain(f2, std::move(h3)));

  invoke(std::experimental::chain(cf2));
  invoke(std::experimental::chain(cf2, handler1));
  invoke(std::experimental::chain(cf2, &handler1));
  invoke(std::experimental::chain(cf2, handler2()));
  invoke(std::experimental::chain(cf2, h2));
  invoke(std::experimental::chain(cf2, ch2));
  invoke(std::experimental::chain(cf2, handler3()));
  invoke(std::experimental::chain(cf2, std::move(h3)));

  invoke(std::experimental::chain(function3()));
  invoke(std::experimental::chain(function3(), handler1));
  invoke(std::experimental::chain(function3(), &handler1));
  invoke(std::experimental::chain(function3(), handler2()));
  invoke(std::experimental::chain(function3(), h2));
  invoke(std::experimental::chain(function3(), ch2));
  invoke(std::experimental::chain(function3(), handler3()));
  invoke(std::experimental::chain(function3(), std::move(h3)));

  invoke(std::experimental::chain(std::move(f3)));
  invoke(std::experimental::chain(std::move(f3), handler1));
  invoke(std::experimental::chain(std::move(f3), &handler1));
  invoke(std::experimental::chain(std::move(f3), handler2()));
  invoke(std::experimental::chain(std::move(f3), h2));
  invoke(std::experimental::chain(std::move(f3), ch2));
  invoke(std::experimental::chain(std::move(f3), handler3()));
  invoke(std::experimental::chain(std::move(f3), std::move(h3)));

  assert(function_count == 56);
  assert(handler_count == 49);
}
예제 #14
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::loop_scheduler scheduler;
  auto ex = scheduler.get_executor();
  std::experimental::executor_work<decltype(ex)> w(ex);
  std::thread t([&](){ scheduler.run(); });

  std::experimental::dispatch(ex.wrap(function1), handler1);
  std::experimental::dispatch(ex.wrap(function1), &handler1);
  std::experimental::dispatch(ex.wrap(function1), handler2());
  std::experimental::dispatch(ex.wrap(function1), h2);
  std::experimental::dispatch(ex.wrap(function1), ch2);
  std::experimental::dispatch(ex.wrap(function1), handler3());
  std::experimental::dispatch(ex.wrap(function1), std::move(h3));
  std::future<void> fut1 = std::experimental::dispatch(ex.wrap(function1), std::experimental::use_future);
  fut1.get();

  std::experimental::dispatch(ex.wrap(&function1), handler1);
  std::experimental::dispatch(ex.wrap(&function1), &handler1);
  std::experimental::dispatch(ex.wrap(&function1), handler2());
  std::experimental::dispatch(ex.wrap(&function1), h2);
  std::experimental::dispatch(ex.wrap(&function1), ch2);
  std::experimental::dispatch(ex.wrap(&function1), handler3());
  std::experimental::dispatch(ex.wrap(&function1), std::move(h3));
  std::future<void> fut2 = std::experimental::dispatch(ex.wrap(&function1), std::experimental::use_future);
  fut2.get();

  std::experimental::dispatch(ex.wrap(function2()), handler1);
  std::experimental::dispatch(ex.wrap(function2()), &handler1);
  std::experimental::dispatch(ex.wrap(function2()), handler2());
  std::experimental::dispatch(ex.wrap(function2()), h2);
  std::experimental::dispatch(ex.wrap(function2()), ch2);
  std::experimental::dispatch(ex.wrap(function2()), handler3());
  std::experimental::dispatch(ex.wrap(function2()), std::move(h3));
  std::future<void> fut3 = std::experimental::dispatch(ex.wrap(function2()), std::experimental::use_future);
  fut3.get();

  std::experimental::dispatch(ex.wrap(f2), handler1);
  std::experimental::dispatch(ex.wrap(f2), &handler1);
  std::experimental::dispatch(ex.wrap(f2), handler2());
  std::experimental::dispatch(ex.wrap(f2), h2);
  std::experimental::dispatch(ex.wrap(f2), ch2);
  std::experimental::dispatch(ex.wrap(f2), handler3());
  std::experimental::dispatch(ex.wrap(f2), std::move(h3));
  std::future<void> fut4 = std::experimental::dispatch(ex.wrap(f2), std::experimental::use_future);
  fut4.get();

  std::experimental::dispatch(ex.wrap(cf2), handler1);
  std::experimental::dispatch(ex.wrap(cf2), &handler1);
  std::experimental::dispatch(ex.wrap(cf2), handler2());
  std::experimental::dispatch(ex.wrap(cf2), h2);
  std::experimental::dispatch(ex.wrap(cf2), ch2);
  std::experimental::dispatch(ex.wrap(cf2), handler3());
  std::experimental::dispatch(ex.wrap(cf2), std::move(h3));
  std::future<void> fut5 = std::experimental::dispatch(ex.wrap(cf2), std::experimental::use_future);
  fut5.get();

  std::experimental::dispatch(ex.wrap(function3()), handler1);
  std::experimental::dispatch(ex.wrap(function3()), &handler1);
  std::experimental::dispatch(ex.wrap(function3()), handler2());
  std::experimental::dispatch(ex.wrap(function3()), h2);
  std::experimental::dispatch(ex.wrap(function3()), ch2);
  std::experimental::dispatch(ex.wrap(function3()), handler3());
  std::experimental::dispatch(ex.wrap(function3()), std::move(h3));
  std::future<void> fut6 = std::experimental::dispatch(ex.wrap(function3()), std::experimental::use_future);
  fut6.get();

  std::experimental::dispatch(ex.wrap(std::move(f3)), handler1);
  std::experimental::dispatch(ex.wrap(std::move(f3)), &handler1);
  std::experimental::dispatch(ex.wrap(std::move(f3)), handler2());
  std::experimental::dispatch(ex.wrap(std::move(f3)), h2);
  std::experimental::dispatch(ex.wrap(std::move(f3)), ch2);
  std::experimental::dispatch(ex.wrap(std::move(f3)), handler3());
  std::experimental::dispatch(ex.wrap(std::move(f3)), std::move(h3));
  std::future<void> fut7 = std::experimental::dispatch(ex.wrap(std::move(f3)), std::experimental::use_future);
  fut7.get();

  w.reset();
  t.join();

  assert(function_count == 56);
  assert(handler_count == 49);
}
예제 #15
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::loop_scheduler scheduler;
  std::experimental::executor ex = make_executor(scheduler);

  ex = std::experimental::system_executor();
  assert(&ex.context() == &std::experimental::system_executor().context());

  std::experimental::post(ex.wrap(function1), handler1);
  std::experimental::post(ex.wrap(function1), &handler1);
  std::experimental::post(ex.wrap(function1), handler2());
  std::experimental::post(ex.wrap(function1), h2);
  std::experimental::post(ex.wrap(function1), ch2);
  std::experimental::post(ex.wrap(function1), handler3());
  std::experimental::post(ex.wrap(function1), std::move(h3));
  std::future<void> fut1 = std::experimental::post(ex.wrap(function1), std::experimental::use_future);
  fut1.get();

  std::experimental::post(ex.wrap(&function1), handler1);
  std::experimental::post(ex.wrap(&function1), &handler1);
  std::experimental::post(ex.wrap(&function1), handler2());
  std::experimental::post(ex.wrap(&function1), h2);
  std::experimental::post(ex.wrap(&function1), ch2);
  std::experimental::post(ex.wrap(&function1), handler3());
  std::experimental::post(ex.wrap(&function1), std::move(h3));
  std::future<void> fut2 = std::experimental::post(ex.wrap(&function1), std::experimental::use_future);
  fut2.get();

  std::experimental::post(ex.wrap(function2()), handler1);
  std::experimental::post(ex.wrap(function2()), &handler1);
  std::experimental::post(ex.wrap(function2()), handler2());
  std::experimental::post(ex.wrap(function2()), h2);
  std::experimental::post(ex.wrap(function2()), ch2);
  std::experimental::post(ex.wrap(function2()), handler3());
  std::experimental::post(ex.wrap(function2()), std::move(h3));
  std::future<void> fut3 = std::experimental::post(ex.wrap(function2()), std::experimental::use_future);
  fut3.get();

  std::experimental::post(ex.wrap(f2), handler1);
  std::experimental::post(ex.wrap(f2), &handler1);
  std::experimental::post(ex.wrap(f2), handler2());
  std::experimental::post(ex.wrap(f2), h2);
  std::experimental::post(ex.wrap(f2), ch2);
  std::experimental::post(ex.wrap(f2), handler3());
  std::experimental::post(ex.wrap(f2), std::move(h3));
  std::future<void> fut4 = std::experimental::post(ex.wrap(f2), std::experimental::use_future);
  fut4.get();

  std::experimental::post(ex.wrap(cf2), handler1);
  std::experimental::post(ex.wrap(cf2), &handler1);
  std::experimental::post(ex.wrap(cf2), handler2());
  std::experimental::post(ex.wrap(cf2), h2);
  std::experimental::post(ex.wrap(cf2), ch2);
  std::experimental::post(ex.wrap(cf2), handler3());
  std::experimental::post(ex.wrap(cf2), std::move(h3));
  std::future<void> fut5 = std::experimental::post(ex.wrap(cf2), std::experimental::use_future);
  fut5.get();

  std::experimental::post(ex.wrap(function3()), handler1);
  std::experimental::post(ex.wrap(function3()), &handler1);
  std::experimental::post(ex.wrap(function3()), handler2());
  std::experimental::post(ex.wrap(function3()), h2);
  std::experimental::post(ex.wrap(function3()), ch2);
  std::experimental::post(ex.wrap(function3()), handler3());
  std::experimental::post(ex.wrap(function3()), std::move(h3));
  std::future<void> fut6 = std::experimental::post(ex.wrap(function3()), std::experimental::use_future);
  fut6.get();

  std::experimental::post(ex.wrap(std::move(f3)), handler1);
  std::experimental::post(ex.wrap(std::move(f3)), &handler1);
  std::experimental::post(ex.wrap(std::move(f3)), handler2());
  std::experimental::post(ex.wrap(std::move(f3)), h2);
  std::experimental::post(ex.wrap(std::move(f3)), ch2);
  std::experimental::post(ex.wrap(std::move(f3)), handler3());
  std::experimental::post(ex.wrap(std::move(f3)), std::move(h3));
  std::future<void> fut7 = std::experimental::post(ex.wrap(std::move(f3)), std::experimental::use_future);
  fut7.get();

  std::this_thread::sleep_for(std::chrono::seconds(1));
  assert(function_count == 56);
  assert(handler_count == 49);
}
예제 #16
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::thread_pool pool;
  auto ex = make_executor(pool);

  std::experimental::dispatch(ex, function1, handler1);
  std::experimental::dispatch(ex, function1, &handler1);
  std::experimental::dispatch(ex, function1, handler2());
  std::experimental::dispatch(ex, function1, h2);
  std::experimental::dispatch(ex, function1, ch2);
  std::experimental::dispatch(ex, function1, handler3());
  std::experimental::dispatch(ex, function1, std::move(h3));
  std::future<int> fut1 = std::experimental::dispatch(ex, function1, std::experimental::use_future);
  fut1.get();

  std::experimental::dispatch(ex, &function1, handler1);
  std::experimental::dispatch(ex, &function1, &handler1);
  std::experimental::dispatch(ex, &function1, handler2());
  std::experimental::dispatch(ex, &function1, h2);
  std::experimental::dispatch(ex, &function1, ch2);
  std::experimental::dispatch(ex, &function1, handler3());
  std::experimental::dispatch(ex, &function1, std::move(h3));
  std::future<int> fut2 = std::experimental::dispatch(ex, &function1, std::experimental::use_future);
  fut2.get();

  std::experimental::dispatch(ex, function2(), handler1);
  std::experimental::dispatch(ex, function2(), &handler1);
  std::experimental::dispatch(ex, function2(), handler2());
  std::experimental::dispatch(ex, function2(), h2);
  std::experimental::dispatch(ex, function2(), ch2);
  std::experimental::dispatch(ex, function2(), handler3());
  std::experimental::dispatch(ex, function2(), std::move(h3));
  std::future<int> fut3 = std::experimental::dispatch(ex, function2(), std::experimental::use_future);
  fut3.get();

  std::experimental::dispatch(ex, f2, handler1);
  std::experimental::dispatch(ex, f2, &handler1);
  std::experimental::dispatch(ex, f2, handler2());
  std::experimental::dispatch(ex, f2, h2);
  std::experimental::dispatch(ex, f2, ch2);
  std::experimental::dispatch(ex, f2, handler3());
  std::experimental::dispatch(ex, f2, std::move(h3));
  std::future<int> fut4 = std::experimental::dispatch(ex, f2, std::experimental::use_future);
  fut4.get();

  std::experimental::dispatch(ex, cf2, handler1);
  std::experimental::dispatch(ex, cf2, &handler1);
  std::experimental::dispatch(ex, cf2, handler2());
  std::experimental::dispatch(ex, cf2, h2);
  std::experimental::dispatch(ex, cf2, ch2);
  std::experimental::dispatch(ex, cf2, handler3());
  std::experimental::dispatch(ex, cf2, std::move(h3));
  std::future<int> fut5 = std::experimental::dispatch(ex, cf2, std::experimental::use_future);
  fut5.get();

  std::experimental::dispatch(ex, function3(), handler1);
  std::experimental::dispatch(ex, function3(), &handler1);
  std::experimental::dispatch(ex, function3(), handler2());
  std::experimental::dispatch(ex, function3(), h2);
  std::experimental::dispatch(ex, function3(), ch2);
  std::experimental::dispatch(ex, function3(), handler3());
  std::experimental::dispatch(ex, function3(), std::move(h3));
  std::future<int> fut6 = std::experimental::dispatch(ex, function3(), std::experimental::use_future);
  fut6.get();

  std::experimental::dispatch(ex, std::move(f3), handler1);
  std::experimental::dispatch(ex, std::move(f3), &handler1);
  std::experimental::dispatch(ex, std::move(f3), handler2());
  std::experimental::dispatch(ex, std::move(f3), h2);
  std::experimental::dispatch(ex, std::move(f3), ch2);
  std::experimental::dispatch(ex, std::move(f3), handler3());
  std::experimental::dispatch(ex, std::move(f3), std::move(h3));
  std::future<int> fut7 = std::experimental::dispatch(ex, std::move(f3), std::experimental::use_future);
  fut7.get();

  pool.join();
  assert(function_count == 56);
  assert(handler_count == 49);
}
예제 #17
0
int main (int argc, char const * argv []) 

{
	static char const * optv [] = 
	{
		"e:m:o:p:iqrvw:",
		"",
		"Weeder Solid State Relay Module Controller",
		"e n\techo is (n) [" LITERAL (WEEDER_ECHO) "]",
		"m n\tmode is (n) [" LITERAL (WEEDER_MODE) "]",
		"o s\tunit order is (s) [" WEEDER_UNITS "]",
		"p f\tport is (f) [" WEEDER_PORT "]",
		"q\tquiet mode",
		"r\tread attenuator value",
		"v\tverbose mode",
		"w n\twait (n) millseconds [" LITERAL (WEEDER_WAIT) "]",
		(char const *) (0)
	};
	struct _file_ port = 
	{
		-1,
		WEEDER_PORT
	};

#if defined (WIN32)

	HANDLE hSerial;
	DCB dcbSerial = 
	{
		0
	};

#else

	struct termios termios;

#endif

	char const * units = WEEDER_UNITS;
	unsigned wait = WEEDER_WAIT;
	unsigned echo = WEEDER_ECHO;
	unsigned mode = WEEDER_MODE;
	unsigned data = 0;
	flag_t flags = (flag_t)(0);
	signed c;
	optind = 1;
	if (getenv ("WEEDER")) 
	{
		port.name = strdup (getenv ("WEEDER"));
	}
	while ((c = getoptv (argc, argv, optv)) != -1) 
	{
		switch (c) 
		{
		case 'e':
			echo = (unsigned)(uintspec (synonym (optarg, modes, SIZEOF (modes)), 0, 1));
			break;
		case 'm':
			mode = (unsigned)(uintspec (synonym (optarg, modes, SIZEOF (modes)), 0, 1));
			break;
		case 'n':
			_setbits (flags, WEEDER_NEWLINE);
			break;
		case 'o':
			units = optarg;
			break;
		case 'p':
			port.name = optarg;
			break;
		case 'w':
			wait = (unsigned)(uintspec (optarg, 5, 100));
			break;
		case 'q':
			_setbits (flags, WEEDER_SILENCE);
			break;
		case 'r':
			_setbits (flags, WEEDER_DISPLAY);
			break;
		case 'v':
			_setbits (flags, WEEDER_VERBOSE);
			break;
		default:
			break;
		}
	}
	argc -= optind;
	argv += optind;
	if ((argc) && (* argv)) 
	{
		data = (unsigned)(uintspec (* argv, 0, 0x7F));
	}

#if defined (WIN32)

	hSerial = CreateFile (port.name, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
	if (hSerial == INVALID_HANDLE_VALUE) 
	{
		error (1, errno, FILE_CANTOPEN, port.name);
	}
	dcbSerial.DCBlength = sizeof (dcbSerial);
	if (!GetCommState (hSerial, &dcbSerial)) 
	{
		error (1, 0, FILE_CANTREAD " state", port.name);
	}
	dcbSerial.BaudRate = CBR_9600;
	dcbSerial.ByteSize = 8;
	dcbSerial.StopBits = ONESTOPBIT;
	dcbSerial.Parity = NOPARITY;
	if (!SetCommState (hSerial, &dcbSerial)) 
	{
		error (1, 0, FILE_CANTSAVE, port.name);
	}
	CloseHandle (hSerial);
	if ((port.file = open (port.name, O_BINARY | O_RDWR)) == -1) 
	{
		error (1, errno, FILE_CANTOPEN " state", port.name);
	}

#else

	if ((port.file = open (port.name, O_RDWR|O_NOCTTY|O_NDELAY)) == -1) 
	{
		error (1, 0, FILE_CANTOPEN, port.name);
	}
	tcgetattr (port.file, &termios);
	termios.c_cflag = CS8;
	cfsetospeed (&termios, B9600);
	tcsetattr (port.file, TCSANOW, &termios);

#endif

	function1 (&port, units, wait, echo);
	if ((argc) && (* argv)) 
	{
		function2 (&port, units, wait, mode, data);
	}
	if (_anyset (flags, WEEDER_DISPLAY)) 
	{
		function3 (&port, units, wait);
	}
	close (port.file);
	exit (0);
}
예제 #18
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::loop_scheduler scheduler;
  auto ex = make_strand(scheduler.get_executor());
  std::experimental::executor_work<decltype(ex)> w(ex);
  std::thread t([&](){ scheduler.run(); });

  std::experimental::post(ex, function1, handler1);
  std::experimental::post(ex, function1, &handler1);
  std::experimental::post(ex, function1, handler2());
  std::experimental::post(ex, function1, h2);
  std::experimental::post(ex, function1, ch2);
  std::experimental::post(ex, function1, handler3());
  std::experimental::post(ex, function1, std::move(h3));
  std::future<int> fut1 = std::experimental::post(ex, function1, std::experimental::use_future);
  fut1.get();

  std::experimental::post(ex, &function1, handler1);
  std::experimental::post(ex, &function1, &handler1);
  std::experimental::post(ex, &function1, handler2());
  std::experimental::post(ex, &function1, h2);
  std::experimental::post(ex, &function1, ch2);
  std::experimental::post(ex, &function1, handler3());
  std::experimental::post(ex, &function1, std::move(h3));
  std::future<int> fut2 = std::experimental::post(ex, &function1, std::experimental::use_future);
  fut2.get();

  std::experimental::post(ex, function2(), handler1);
  std::experimental::post(ex, function2(), &handler1);
  std::experimental::post(ex, function2(), handler2());
  std::experimental::post(ex, function2(), h2);
  std::experimental::post(ex, function2(), ch2);
  std::experimental::post(ex, function2(), handler3());
  std::experimental::post(ex, function2(), std::move(h3));
  std::future<int> fut3 = std::experimental::post(ex, function2(), std::experimental::use_future);
  fut3.get();

  std::experimental::post(ex, f2, handler1);
  std::experimental::post(ex, f2, &handler1);
  std::experimental::post(ex, f2, handler2());
  std::experimental::post(ex, f2, h2);
  std::experimental::post(ex, f2, ch2);
  std::experimental::post(ex, f2, handler3());
  std::experimental::post(ex, f2, std::move(h3));
  std::future<int> fut4 = std::experimental::post(ex, f2, std::experimental::use_future);
  fut4.get();

  std::experimental::post(ex, cf2, handler1);
  std::experimental::post(ex, cf2, &handler1);
  std::experimental::post(ex, cf2, handler2());
  std::experimental::post(ex, cf2, h2);
  std::experimental::post(ex, cf2, ch2);
  std::experimental::post(ex, cf2, handler3());
  std::experimental::post(ex, cf2, std::move(h3));
  std::future<int> fut5 = std::experimental::post(ex, cf2, std::experimental::use_future);
  fut5.get();

  std::experimental::post(ex, function3(), handler1);
  std::experimental::post(ex, function3(), &handler1);
  std::experimental::post(ex, function3(), handler2());
  std::experimental::post(ex, function3(), h2);
  std::experimental::post(ex, function3(), ch2);
  std::experimental::post(ex, function3(), handler3());
  std::experimental::post(ex, function3(), std::move(h3));
  std::future<int> fut6 = std::experimental::post(ex, function3(), std::experimental::use_future);
  fut6.get();

  std::experimental::post(ex, std::move(f3), handler1);
  std::experimental::post(ex, std::move(f3), &handler1);
  std::experimental::post(ex, std::move(f3), handler2());
  std::experimental::post(ex, std::move(f3), h2);
  std::experimental::post(ex, std::move(f3), ch2);
  std::experimental::post(ex, std::move(f3), handler3());
  std::experimental::post(ex, std::move(f3), std::move(h3));
  std::future<int> fut7 = std::experimental::post(ex, std::move(f3), std::experimental::use_future);
  fut7.get();

  w.reset();
  t.join();

  assert(function_count == 56);
  assert(handler_count == 49);
}
예제 #19
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::thread_pool pool;
  auto ex = make_executor(pool);

  std::experimental::post(ex.wrap(function1), handler1);
  std::experimental::post(ex.wrap(function1), &handler1);
  std::experimental::post(ex.wrap(function1), handler2());
  std::experimental::post(ex.wrap(function1), h2);
  std::experimental::post(ex.wrap(function1), ch2);
  std::experimental::post(ex.wrap(function1), handler3());
  std::experimental::post(ex.wrap(function1), std::move(h3));
  std::future<void> fut1 = std::experimental::post(ex.wrap(function1), std::experimental::use_future);
  fut1.get();

  std::experimental::post(ex.wrap(&function1), handler1);
  std::experimental::post(ex.wrap(&function1), &handler1);
  std::experimental::post(ex.wrap(&function1), handler2());
  std::experimental::post(ex.wrap(&function1), h2);
  std::experimental::post(ex.wrap(&function1), ch2);
  std::experimental::post(ex.wrap(&function1), handler3());
  std::experimental::post(ex.wrap(&function1), std::move(h3));
  std::future<void> fut2 = std::experimental::post(ex.wrap(&function1), std::experimental::use_future);
  fut2.get();

  std::experimental::post(ex.wrap(function2()), handler1);
  std::experimental::post(ex.wrap(function2()), &handler1);
  std::experimental::post(ex.wrap(function2()), handler2());
  std::experimental::post(ex.wrap(function2()), h2);
  std::experimental::post(ex.wrap(function2()), ch2);
  std::experimental::post(ex.wrap(function2()), handler3());
  std::experimental::post(ex.wrap(function2()), std::move(h3));
  std::future<void> fut3 = std::experimental::post(ex.wrap(function2()), std::experimental::use_future);
  fut3.get();

  std::experimental::post(ex.wrap(f2), handler1);
  std::experimental::post(ex.wrap(f2), &handler1);
  std::experimental::post(ex.wrap(f2), handler2());
  std::experimental::post(ex.wrap(f2), h2);
  std::experimental::post(ex.wrap(f2), ch2);
  std::experimental::post(ex.wrap(f2), handler3());
  std::experimental::post(ex.wrap(f2), std::move(h3));
  std::future<void> fut4 = std::experimental::post(ex.wrap(f2), std::experimental::use_future);
  fut4.get();

  std::experimental::post(ex.wrap(cf2), handler1);
  std::experimental::post(ex.wrap(cf2), &handler1);
  std::experimental::post(ex.wrap(cf2), handler2());
  std::experimental::post(ex.wrap(cf2), h2);
  std::experimental::post(ex.wrap(cf2), ch2);
  std::experimental::post(ex.wrap(cf2), handler3());
  std::experimental::post(ex.wrap(cf2), std::move(h3));
  std::future<void> fut5 = std::experimental::post(ex.wrap(cf2), std::experimental::use_future);
  fut5.get();

  std::experimental::post(ex.wrap(function3()), handler1);
  std::experimental::post(ex.wrap(function3()), &handler1);
  std::experimental::post(ex.wrap(function3()), handler2());
  std::experimental::post(ex.wrap(function3()), h2);
  std::experimental::post(ex.wrap(function3()), ch2);
  std::experimental::post(ex.wrap(function3()), handler3());
  std::experimental::post(ex.wrap(function3()), std::move(h3));
  std::future<void> fut6 = std::experimental::post(ex.wrap(function3()), std::experimental::use_future);
  fut6.get();

  std::experimental::post(ex.wrap(std::move(f3)), handler1);
  std::experimental::post(ex.wrap(std::move(f3)), &handler1);
  std::experimental::post(ex.wrap(std::move(f3)), handler2());
  std::experimental::post(ex.wrap(std::move(f3)), h2);
  std::experimental::post(ex.wrap(std::move(f3)), ch2);
  std::experimental::post(ex.wrap(std::move(f3)), handler3());
  std::experimental::post(ex.wrap(std::move(f3)), std::move(h3));
  std::future<void> fut7 = std::experimental::post(ex.wrap(std::move(f3)), std::experimental::use_future);
  fut7.get();

  pool.join();
  assert(function_count == 56);
  assert(handler_count == 49);
}
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::loop_scheduler scheduler;
  std::experimental::executor ex = scheduler.get_executor();

  ex = std::experimental::system_executor();
  assert(&ex.context() == &std::experimental::system_executor().context());

  auto rel_time = std::chrono::milliseconds(100);

  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function1), handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function1), &handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function1), handler2());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function1), h2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function1), ch2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function1), handler3());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function1), std::move(h3));
  std::future<void> fut1 = std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function1), std::experimental::use_future);
  fut1.get();

  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, &function1), handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, &function1), &handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, &function1), handler2());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, &function1), h2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, &function1), ch2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, &function1), handler3());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, &function1), std::move(h3));
  std::future<void> fut2 = std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, &function1), std::experimental::use_future);
  fut2.get();

  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function2()), handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function2()), &handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function2()), handler2());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function2()), h2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function2()), ch2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function2()), handler3());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function2()), std::move(h3));
  std::future<void> fut3 = std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function2()), std::experimental::use_future);
  fut3.get();

  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, f2), handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, f2), &handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, f2), handler2());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, f2), h2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, f2), ch2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, f2), handler3());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, f2), std::move(h3));
  std::future<void> fut4 = std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, f2), std::experimental::use_future);
  fut4.get();

  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, cf2), handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, cf2), &handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, cf2), handler2());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, cf2), h2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, cf2), ch2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, cf2), handler3());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, cf2), std::move(h3));
  std::future<void> fut5 = std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, cf2), std::experimental::use_future);
  fut5.get();

  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function3()), handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function3()), &handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function3()), handler2());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function3()), h2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function3()), ch2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function3()), handler3());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function3()), std::move(h3));
  std::future<void> fut6 = std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, function3()), std::experimental::use_future);
  fut6.get();

  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, std::move(f3)), handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, std::move(f3)), &handler1);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, std::move(f3)), handler2());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, std::move(f3)), h2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, std::move(f3)), ch2);
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, std::move(f3)), handler3());
  std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, std::move(f3)), std::move(h3));
  std::future<void> fut7 = std::experimental::dispatch_after(rel_time, std::experimental::wrap(ex, std::move(f3)), std::experimental::use_future);
  fut7.get();

  std::this_thread::sleep_for(std::chrono::seconds(1));
  assert(function_count == 56);
  assert(handler_count == 49);
}
예제 #21
0
int main(int argc, char **argv) 
{
	//SCENARIO 0
	//Passing a primitive by value. arg0 should NOT be put on the heap.
	int arg0 = 32;
    arg0 = function2(arg0);

    //SCENARIO 1
	//Passing a local via address. arg1 should be put on the heap.
    int arg1 = 7;
    function1(&arg1);

    //SCENARIO 2
    //Passing a pointer to a local variable. arg2 should be put on the heap. arg3 should NOT.
    int arg2 = 4;
    int *arg3 = &arg2;
    function1(arg3);

    //SCENARIO 3
    //Passing a pointer to a heap address. arg4 should NOT be put on the heap.
    int * arg4 = (int *) malloc(sizeof(int));
    (*arg4) = 3;
    function1(arg4);

    //SCENARIO 4
    //Passing a pointer to a heap address that turns into a local address. arg6 should be put on the heap.
    //arg5 should NOT.
    int * arg5 = (int *) malloc(sizeof(int));
    (*arg5) = 56;
    int arg6 = 5;
    arg5 = &arg6;
    function1(arg5);

    //SCENARIO 5
    //Passing a pointer by address that points to dynamically allocated memory. arg7 should be put on the heap.
    int * arg7 = (int *) malloc(sizeof(int));
    function3(&arg7);

    //SCENARIO 6
    //Passing a pointer that points to a pointer to a pointer.
    //arg9 and 8 should be put on the heap. arg10 should NOT.
    int arg8 = 34;
    int * arg9 = &arg8;
    int ** arg10 = &arg9;
    function3(arg10);

    //SCENARIO 7
    //Passing a pointer that points to a pointer to a malloc.
    //arg11 should be placed on the heap.
    int * arg11 = (int *) malloc(sizeof(int));
    int ** arg12 = &arg11;
    function3(arg12);

    //SCENARIO 8
    //Passing a pointer that points to a value onto the heap.
    //arg13 and arg14 should be placed on the heap.
    int arg13 = 35;
    int * arg14 = &arg13;
    function3(&arg14);

    //SCENARIO 9
    //Passing a pointer to the address of a local stored in an intermediate value.
    //Only arg15 should be put on the heap.
    int arg15 = 34;
    int * arg16 = &arg15;
    int ** arg17 = (int **) malloc(sizeof(int*));
    (*arg17) = arg16;
    function3(arg17);

    int arg18 = 34;

    //PHI: Simple conditional.
    //arg18 should be placed in the heap.
    if (arg15 > 10)
    {
	function1(&arg18);
    }
    else
    {
	arg18 *= 2;
    }

    int count = 0;
    for (count = 0; count < arg18; count++)
    {
       int blahblah = 34;
       blahblah *= arg15;
       printf("%d\n", blahblah);
       arg15 += 34;
    }


	return 0;
}
예제 #22
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::post(function1);
  std::experimental::post(function1, handler1);
  std::experimental::post(function1, &handler1);
  std::experimental::post(function1, handler2());
  std::experimental::post(function1, h2);
  std::experimental::post(function1, ch2);
  std::experimental::post(function1, handler3());
  std::experimental::post(function1, std::move(h3));
  std::future<int> fut1 = std::experimental::post(function1, std::experimental::use_future);
  fut1.get();

  std::experimental::post(&function1);
  std::experimental::post(&function1, handler1);
  std::experimental::post(&function1, &handler1);
  std::experimental::post(&function1, handler2());
  std::experimental::post(&function1, h2);
  std::experimental::post(&function1, ch2);
  std::experimental::post(&function1, handler3());
  std::experimental::post(&function1, std::move(h3));
  std::future<int> fut2 = std::experimental::post(&function1, std::experimental::use_future);
  fut2.get();

  std::experimental::post(function2());
  std::experimental::post(function2(), handler1);
  std::experimental::post(function2(), &handler1);
  std::experimental::post(function2(), handler2());
  std::experimental::post(function2(), h2);
  std::experimental::post(function2(), ch2);
  std::experimental::post(function2(), handler3());
  std::experimental::post(function2(), std::move(h3));
  std::future<int> fut3 = std::experimental::post(function2(), std::experimental::use_future);
  fut3.get();

  std::experimental::post(f2);
  std::experimental::post(f2, handler1);
  std::experimental::post(f2, &handler1);
  std::experimental::post(f2, handler2());
  std::experimental::post(f2, h2);
  std::experimental::post(f2, ch2);
  std::experimental::post(f2, handler3());
  std::experimental::post(f2, std::move(h3));
  std::future<int> fut4 = std::experimental::post(f2, std::experimental::use_future);
  fut4.get();

  std::experimental::post(cf2);
  std::experimental::post(cf2, handler1);
  std::experimental::post(cf2, &handler1);
  std::experimental::post(cf2, handler2());
  std::experimental::post(cf2, h2);
  std::experimental::post(cf2, ch2);
  std::experimental::post(cf2, handler3());
  std::experimental::post(cf2, std::move(h3));
  std::future<int> fut5 = std::experimental::post(cf2, std::experimental::use_future);
  fut5.get();

  std::experimental::post(function3());
  std::experimental::post(function3(), handler1);
  std::experimental::post(function3(), &handler1);
  std::experimental::post(function3(), handler2());
  std::experimental::post(function3(), h2);
  std::experimental::post(function3(), ch2);
  std::experimental::post(function3(), handler3());
  std::experimental::post(function3(), std::move(h3));
  std::future<int> fut6 = std::experimental::post(function3(), std::experimental::use_future);
  fut6.get();

  std::experimental::post(std::move(f3));
  std::experimental::post(std::move(f3), handler1);
  std::experimental::post(std::move(f3), &handler1);
  std::experimental::post(std::move(f3), handler2());
  std::experimental::post(std::move(f3), h2);
  std::experimental::post(std::move(f3), ch2);
  std::experimental::post(std::move(f3), handler3());
  std::experimental::post(std::move(f3), std::move(h3));
  std::future<int> fut7 = std::experimental::post(std::move(f3), std::experimental::use_future);
  fut7.get();

  std::this_thread::sleep_for(std::chrono::seconds(1));
  assert(function_count == 63);
  assert(handler_count == 49);

  std::future<int> fut8 = std::experimental::post(function_throw, std::experimental::use_future);
  try
  {
    fut8.get();
    assert(0);
  }
  catch (std::exception& e)
  {
    assert(e.what() == std::string("oops"));
  }

  std::future<int> fut9 = std::experimental::post(std::experimental::package(function_throw));
  try
  {
    fut9.get();
    assert(0);
  }
  catch (std::exception& e)
  {
    assert(e.what() == std::string("oops"));
  }
}
예제 #23
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::loop_scheduler scheduler;
  auto ex = make_executor(scheduler);
  std::experimental::executor::work w = ex.make_work();
  std::thread t([&](){ scheduler.run(); });

  std::experimental::post(ex, function1, handler1);
  std::experimental::post(ex, function1, &handler1);
  std::experimental::post(ex, function1, handler2());
  std::experimental::post(ex, function1, h2);
  std::experimental::post(ex, function1, ch2);
  std::experimental::post(ex, function1, handler3());
  std::experimental::post(ex, function1, std::move(h3));
  std::future<void> fut1 = std::experimental::post(ex, function1, std::experimental::use_future);
  fut1.get();

  std::experimental::post(ex, &function1, handler1);
  std::experimental::post(ex, &function1, &handler1);
  std::experimental::post(ex, &function1, handler2());
  std::experimental::post(ex, &function1, h2);
  std::experimental::post(ex, &function1, ch2);
  std::experimental::post(ex, &function1, handler3());
  std::experimental::post(ex, &function1, std::move(h3));
  std::future<void> fut2 = std::experimental::post(ex, &function1, std::experimental::use_future);
  fut2.get();

  std::experimental::post(ex, function2(), handler1);
  std::experimental::post(ex, function2(), &handler1);
  std::experimental::post(ex, function2(), handler2());
  std::experimental::post(ex, function2(), h2);
  std::experimental::post(ex, function2(), ch2);
  std::experimental::post(ex, function2(), handler3());
  std::experimental::post(ex, function2(), std::move(h3));
  std::future<void> fut3 = std::experimental::post(ex, function2(), std::experimental::use_future);
  fut3.get();

  std::experimental::post(ex, f2, handler1);
  std::experimental::post(ex, f2, &handler1);
  std::experimental::post(ex, f2, handler2());
  std::experimental::post(ex, f2, h2);
  std::experimental::post(ex, f2, ch2);
  std::experimental::post(ex, f2, handler3());
  std::experimental::post(ex, f2, std::move(h3));
  std::future<void> fut4 = std::experimental::post(ex, f2, std::experimental::use_future);
  fut4.get();

  std::experimental::post(ex, cf2, handler1);
  std::experimental::post(ex, cf2, &handler1);
  std::experimental::post(ex, cf2, handler2());
  std::experimental::post(ex, cf2, h2);
  std::experimental::post(ex, cf2, ch2);
  std::experimental::post(ex, cf2, handler3());
  std::experimental::post(ex, cf2, std::move(h3));
  std::future<void> fut5 = std::experimental::post(ex, cf2, std::experimental::use_future);
  fut5.get();

  std::experimental::post(ex, function3(), handler1);
  std::experimental::post(ex, function3(), &handler1);
  std::experimental::post(ex, function3(), handler2());
  std::experimental::post(ex, function3(), h2);
  std::experimental::post(ex, function3(), ch2);
  std::experimental::post(ex, function3(), handler3());
  std::experimental::post(ex, function3(), std::move(h3));
  std::future<void> fut6 = std::experimental::post(ex, function3(), std::experimental::use_future);
  fut6.get();

  std::experimental::post(ex, std::move(f3), handler1);
  std::experimental::post(ex, std::move(f3), &handler1);
  std::experimental::post(ex, std::move(f3), handler2());
  std::experimental::post(ex, std::move(f3), h2);
  std::experimental::post(ex, std::move(f3), ch2);
  std::experimental::post(ex, std::move(f3), handler3());
  std::experimental::post(ex, std::move(f3), std::move(h3));
  std::future<void> fut7 = std::experimental::post(ex, std::move(f3), std::experimental::use_future);
  fut7.get();

  w = nullptr;
  assert(!w);
  assert(w == nullptr);
  assert(nullptr == w);
  assert(!(w != nullptr));
  assert(!(nullptr != w));

  t.join();

  assert(function_count == 56);
  assert(handler_count == 49);
}
예제 #24
0
파일: Mduffing1.c 프로젝트: 1014511134/src
int main(int argc,char *argv[])
{
    float x0,y0,x00,y00,t0,d1,d2,d3,o1,o2,o3,k11,k21,k31,k41,k12,k22,k32,k42;
    float kxi,gamma,omega,phi;/*parameter define*/
    int i,j,k,n1,n2,n3,sn1,pow1,pow2;
    double h;
    float  *inpsg,*xt,*xt1,*re;
    sf_complex *out1;
    sf_file in, out, restor=NULL;
    bool verb,cosine;
    
    sf_init (argc, argv); 
    in = sf_input("in");
    out = sf_output("out");

    if (NULL != sf_getstring ("restor")) {
        restor = sf_input("restor");
    } else {
	restor = NULL;
	sn1=1;
    }
    
   
    sf_setformat(out,"native_complex");
    
    if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input");
    if (!sf_histfloat(in,"d1",&d1)) sf_error("No d1= in input");
    if (!sf_histfloat(in,"o1",&o1)) sf_error("No o1= in input");
    if (!sf_histint(in,"n2",&n2)) n2=1;
    if (!sf_histfloat(in,"d2",&d2)) d2=1;
    if (!sf_histfloat(in,"o2",&o2)) o2=1;
    if (!sf_histint(in,"n3",&n3)) n3=1;
    if (!sf_histfloat(in,"d3",&d3)) d3=1;
    if (!sf_histfloat(in,"o3",&o3)) o3=1;
    
    if(!sf_getfloat("gamma",&gamma)) gamma=0.75;
    /*strength of external force*/
    if(!sf_getfloat("omega",&omega)) omega=1;
    /*angular frequence of external force*/
    if(!sf_getfloat("kxi",&kxi)) kxi=1;
    /*adjustment for input signal*/
    if(!sf_getfloat("x0",&x0)) x0=0;
    /*initial value of x0*/
    if(!sf_getfloat("y0",&y0)) y0=0;
    /*initial value of y0*/
    if(!sf_getint("pow1",&pow1)) pow1=1;
    /*power of first non-linear restitution term*/
    if(!sf_getint("pow2",&pow2)) pow2=3;
    /*power of second non-linear restitution term*/
    if(!sf_getfloat("phi",&phi)) phi=0.;
    /*phase of cosine signal unit=pi*/
    if(!sf_getbool("verb",&verb)) verb = false;
    /* verbosity flag */
    if(!sf_getbool("cosine",&cosine)) cosine = true;
    /* if n need extenal input for periodic restoring force */
    
    if (NULL != restor){
	
	if (!sf_histint(restor,"n1",&sn1)) sf_error("No n1= in s");
	if (n1>sn1) sf_error("insufficient lenth of external force");
    }
    
    
    h=d1;
    /*step lenth of R-K4*/
    
    re = sf_floatalloc(sn1);
    inpsg = sf_floatalloc(n1*n2);
    xt = sf_floatalloc(n1*n2);
    xt1 = sf_floatalloc(n1*n2);
    out1 = sf_complexalloc(n1*n2);
    
    
    if (NULL != restor) {
	sf_floatread(re,sn1,restor);
    }else {
	for (i=0;i<sn1; i++)
	    re[i] = 0;
    }

    
    if(cosine) {
	for(k = 0; k < n3 ; k++) {
	    sf_floatread(inpsg,n1*n2,in);
	    x00=x0,y00=y0;
	    t0=0;
	    if(verb) sf_warning("step %d of %d;",k,n3);
	    for(j = 0;j < n2;j++) {
		x00=x0,y00=y0;
		t0=0;
		for(i = 0;i < n1;i++){
		    
		    k11 = function1(t0,x00,y00,omega);
		    k12 = function2(t0,x00,y00,inpsg[i+j*n1],kxi,
				    gamma,omega,pow1,pow2,phi);
		    k21 = function1(t0+h/2,x00+k11*h/2,y00+k12*h/2,omega);
		    k22 = function2(t0+h/2,x00+k11*h/2,
				    y00+k12*h/2,inpsg[i+j*n1],kxi,
				    gamma,omega,pow1,pow2,phi);
		    k31 = function1(t0+h/2,x00+k21*h/2,y00+k22*h/2,omega);
		    k32 = function2(t0+h/2,x00+k21*h/2,
				    y00+k22*h/2,inpsg[i+j*n1],kxi,
				    gamma,omega,pow1,pow2,phi);
		    k41 = function1(t0+h,x00+k31*h,y00+k32*h,omega);
		    k42 = function2(t0+h,x00+k31*h,y00+k32*h,inpsg[i+j*n1],
				    kxi,gamma,omega,pow1,pow2,phi);
		    
		    x00+= h*(k11+2*k21+2*k31+k41)/6;
		    y00+= h*(k12+2*k22+2*k32+k42)/6;
		    t0+= h;
		    
		    xt[i+j*n1]=x00,xt1[i+j*n1]=y00;
		}	
	    }
	    for(i=0;i < n1*n2;i++) {
		out1[i] = sf_cmplx(xt[i],xt1[i]);
	    }
	    sf_complexwrite(out1,n1*n2,out);
	}
    }else {
	for(k = 0; k < n3 ; k++) {
	    sf_floatread(inpsg,n1*n2,in);
	    x00=x0,y00=y0;
	    t0=0;
	    if(verb) sf_warning("step %d of %d;",k,n3);
	    for(j = 0;j < n2;j++) {
		x00=x0,y00=y0;
		t0=0;
		for(i = 0;i < n1;i++) {
		    	    
		    k11 = function1(t0,x00,y00,omega);
		    k12 = function3(t0,x00,y00,inpsg[i+j*n1],kxi,
				    gamma,omega,pow1,pow2,re[i]);
		    k21 = function1(t0+h/2,x00+k11*h/2,y00+k12*h/2,omega);
		    k22 = function3(t0+h/2,x00+k11*h/2,
				    y00+k12*h/2,inpsg[i+j*n1],kxi,
				    gamma,omega,pow1,pow2,re[i]);
		    k31 = function1(t0+h/2,x00+k21*h/2,y00+k22*h/2,omega);
		    k32 = function3(t0+h/2,x00+k21*h/2,
				    y00+k22*h/2,inpsg[i+j*n1],kxi,
				    gamma,omega,pow1,pow2,re[i]);
		    k41 = function1(t0+h,x00+k31*h,y00+k32*h,omega);
		    k42 = function3(t0+h,x00+k31*h,y00+k32*h,inpsg[i+j*n1],
				    kxi,gamma,omega,pow1,pow2,re[i]);
		    
		    x00+= h*(k11+2*k21+2*k31+k41)/6;
		    y00+= h*(k12+2*k22+2*k32+k42)/6;
		    t0+= h;
		    
		    
		    xt[i+j*n1]=x00,xt1[i+j*n1]=y00;
		}
	    }
	    for(i=0;i < n1*n2;i++) {
		out1[i] = sf_cmplx(xt[i],xt1[i]);
	    }
	    sf_complexwrite(out1,n1*n2,out);
	}
    }
    
    exit(0);
}
예제 #25
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::loop_scheduler scheduler;
  std::experimental::executor ex = scheduler.get_executor();

  ex = std::experimental::system_executor();
  assert(&ex.context() == &std::experimental::system_executor().context());

  auto abs_time = std::chrono::steady_clock::now() + std::chrono::milliseconds(100);

  std::experimental::dispatch_at(abs_time, ex, function1, handler1);
  std::experimental::dispatch_at(abs_time, ex, function1, &handler1);
  std::experimental::dispatch_at(abs_time, ex, function1, handler2());
  std::experimental::dispatch_at(abs_time, ex, function1, h2);
  std::experimental::dispatch_at(abs_time, ex, function1, ch2);
  std::experimental::dispatch_at(abs_time, ex, function1, handler3());
  std::experimental::dispatch_at(abs_time, ex, function1, std::move(h3));
  std::future<void> fut1 = std::experimental::dispatch_at(abs_time, ex, function1, std::experimental::use_future);
  fut1.get();

  std::experimental::dispatch_at(abs_time, ex, &function1, handler1);
  std::experimental::dispatch_at(abs_time, ex, &function1, &handler1);
  std::experimental::dispatch_at(abs_time, ex, &function1, handler2());
  std::experimental::dispatch_at(abs_time, ex, &function1, h2);
  std::experimental::dispatch_at(abs_time, ex, &function1, ch2);
  std::experimental::dispatch_at(abs_time, ex, &function1, handler3());
  std::experimental::dispatch_at(abs_time, ex, &function1, std::move(h3));
  std::future<void> fut2 = std::experimental::dispatch_at(abs_time, ex, &function1, std::experimental::use_future);
  fut2.get();

  std::experimental::dispatch_at(abs_time, ex, function2(), handler1);
  std::experimental::dispatch_at(abs_time, ex, function2(), &handler1);
  std::experimental::dispatch_at(abs_time, ex, function2(), handler2());
  std::experimental::dispatch_at(abs_time, ex, function2(), h2);
  std::experimental::dispatch_at(abs_time, ex, function2(), ch2);
  std::experimental::dispatch_at(abs_time, ex, function2(), handler3());
  std::experimental::dispatch_at(abs_time, ex, function2(), std::move(h3));
  std::future<void> fut3 = std::experimental::dispatch_at(abs_time, ex, function2(), std::experimental::use_future);
  fut3.get();

  std::experimental::dispatch_at(abs_time, ex, f2, handler1);
  std::experimental::dispatch_at(abs_time, ex, f2, &handler1);
  std::experimental::dispatch_at(abs_time, ex, f2, handler2());
  std::experimental::dispatch_at(abs_time, ex, f2, h2);
  std::experimental::dispatch_at(abs_time, ex, f2, ch2);
  std::experimental::dispatch_at(abs_time, ex, f2, handler3());
  std::experimental::dispatch_at(abs_time, ex, f2, std::move(h3));
  std::future<void> fut4 = std::experimental::dispatch_at(abs_time, ex, f2, std::experimental::use_future);
  fut4.get();

  std::experimental::dispatch_at(abs_time, ex, cf2, handler1);
  std::experimental::dispatch_at(abs_time, ex, cf2, &handler1);
  std::experimental::dispatch_at(abs_time, ex, cf2, handler2());
  std::experimental::dispatch_at(abs_time, ex, cf2, h2);
  std::experimental::dispatch_at(abs_time, ex, cf2, ch2);
  std::experimental::dispatch_at(abs_time, ex, cf2, handler3());
  std::experimental::dispatch_at(abs_time, ex, cf2, std::move(h3));
  std::future<void> fut5 = std::experimental::dispatch_at(abs_time, ex, cf2, std::experimental::use_future);
  fut5.get();

  std::experimental::dispatch_at(abs_time, ex, function3(), handler1);
  std::experimental::dispatch_at(abs_time, ex, function3(), &handler1);
  std::experimental::dispatch_at(abs_time, ex, function3(), handler2());
  std::experimental::dispatch_at(abs_time, ex, function3(), h2);
  std::experimental::dispatch_at(abs_time, ex, function3(), ch2);
  std::experimental::dispatch_at(abs_time, ex, function3(), handler3());
  std::experimental::dispatch_at(abs_time, ex, function3(), std::move(h3));
  std::future<void> fut6 = std::experimental::dispatch_at(abs_time, ex, function3(), std::experimental::use_future);
  fut6.get();

  std::experimental::dispatch_at(abs_time, ex, std::move(f3), handler1);
  std::experimental::dispatch_at(abs_time, ex, std::move(f3), &handler1);
  std::experimental::dispatch_at(abs_time, ex, std::move(f3), handler2());
  std::experimental::dispatch_at(abs_time, ex, std::move(f3), h2);
  std::experimental::dispatch_at(abs_time, ex, std::move(f3), ch2);
  std::experimental::dispatch_at(abs_time, ex, std::move(f3), handler3());
  std::experimental::dispatch_at(abs_time, ex, std::move(f3), std::move(h3));
  std::future<void> fut7 = std::experimental::dispatch_at(abs_time, ex, std::move(f3), std::experimental::use_future);
  fut7.get();

  std::this_thread::sleep_for(std::chrono::seconds(1));
  assert(function_count == 56);
  assert(handler_count == 49);

  std::future<void> fut8 = std::experimental::dispatch_at(abs_time, ex, function_throw, std::experimental::use_future);
  try
  {
    fut8.get();
    assert(0);
  }
  catch (std::exception& e)
  {
    assert(e.what() == std::string("oops"));
  }

  std::future<void> fut9 = std::experimental::dispatch_at(abs_time, ex, std::experimental::package(function_throw));
  try
  {
    fut9.get();
    assert(0);
  }
  catch (std::exception& e)
  {
    assert(e.what() == std::string("oops"));
  }
}
예제 #26
0
파일: main.c 프로젝트: cquxutao/Competition
void main(void)
{ 
    
    u8 x,y[104],y1;
    extern u8 save_y[104];
    u32 count=0;
    extern u8 flag_dma,pulse;
    extern unsigned char stop,send,save;
    extern signed char y_shift;
    int a,b,c,d,f,i,j,save_a,save_b; 
    extern volatile unsigned short ADCConvertedValue[104];
    unsigned char e;
    u16 V0_value,V0_flag=0,s=0,V0_temp[104],Vmax,Vmin,Vpp,Vmax1,Vmin1,Vpp1;;
    extern unsigned char AD_dis_buffer[],dis_x_y_buffer[],AD_dis_save[];
    //目标板初化,

    Target_Init();  
    init12864lcd(); 
    Clean_12864_GDRAM();
    draw_side();
    dis_AD_dis_buffer(dis_x_y_buffer);
    write_12864com(0x30);
    Vmin=62;
    Vmax=0;
    y_shift=0;
    pulse=1;
    while(1)
    {
      if(flag_dma)
      {
       if(i<104)
       {
         i++;
       }
       else
       {
         //TIM_Cmd(TIM2, DISABLE); 
         pulse=0;
         for(i=0;i<104;)
         {
           if(stop==1);
           else{
           V0_value=ADCConvertedValue[i++];
           
           c=(int)(V0_value*3.3/4096)%10;
           d=(int)(V0_value*3.3/4096*10)%10;

           y[i]=(u8)(31-(c*10+d)*2*4/5+26+y_shift);
           y1=(u8)(31-(c*10+d)*2*4/5+26+y_shift);
           if(Vmin1>=V0_value)
           {
             Vmin1=V0_value;
           }
           if(Vmax1<=V0_value){
             Vmax1=V0_value;
           }
           
           if(Vmin>=y[i])
           {
             Vmin=y[i];
           }
           if(Vmax<=y[i]){
             Vmax=y[i];
           }
           Vpp=(Vmax-Vmin)*90/100;
           Vpp1=(Vmax1-Vmin1)*60/100;
           b=(int)((Vpp)*5/4)%10;
           a=(int)((Vpp)*5/4)/10;
           f=(int)((Vpp1*3.3/4096)*100)%10;
           
           dis_define_dot(y1,x++);
           if(x==104)x=0;
           }
         }
  
         Vmax=0;
         Vmin=62;
         
         if(GPIO_ReadInputDataBit(GPIOF,KEY7)==0){
           delay_nus(50000);
           count++;
         }
         if(count%2==0){
         dis_AD();
         
         delay_nus(10000);
         write_12864com(0x30);
         locate16(1, 1);
         write_12864dat('V');
         write_12864dat('=');
         if(GPIO_ReadInputDataBit(SW_GRP,SW1)==0){
         e=(unsigned char)a+0x30;  
         write_12864dat(e);
         write_12864dat('.');
         e=(unsigned char)b+0x30;
         write_12864dat(e);
         e=(unsigned char)f+0x30;
         write_12864dat(e);
         }
         else if(GPIO_ReadInputDataBit(SW_GRP,SW2)==0){
         write_12864dat('0');  
         write_12864dat('.');
         e=(unsigned char)a+0x30;  
         write_12864dat(e);
         e=(unsigned char)b+0x30;
         write_12864dat(e);
         }
         else if(GPIO_ReadInputDataBit(SW_GRP,SW3)==0){
         e=(unsigned char)a+0x30;  
         write_12864dat(e);
         e=(unsigned char)b+0x30;
         write_12864dat(e);
         write_12864dat('m');
         write_12864dat('v');
         }
         //e=(unsigned char)f+0x30;
         //write_12864dat(e);
         }
         if(save==1){
           save_a=a;
           save_b=b;
           for(i=0;i<992;i++)
           {
             AD_dis_save[i]=AD_dis_buffer[i];
           }
           for(i=0;i<104;i++){
             save_y[i]=y[i];
           }
           save=0;
         }
         
         if(count%2==1){
           dis_AD_dis_buffer(AD_dis_save);
           //delay_nus(10000);
           write_12864com(0x30);
           locate16(1, 1);
           write_12864dat('V');
           write_12864dat('=');
           e=(unsigned char)save_a+0x30;  
           write_12864dat(e);
           write_12864dat('.');
           e=(unsigned char)save_b+0x30;
           write_12864dat(e);
           
         }
         
         if(send==1){
         function3();
         }
         
         for(i=0;i<992;i++)
         {
          AD_dis_buffer[i]=0x00; 
         }
        
         pulse=1;
         //TIM_Cmd(TIM2, ENABLE);
       }
       DMAReConfig();
       flag_dma=0; 
      }
   
   }
}
예제 #27
0
int main (int argc, char const * argv [])

{
	static char const * optv [] =
	{
		"f:g:n:p:iqrvw:z",
		"",
		"PTS Module Controller",
		"f f\tport is (f) [" PTSCTL_PORT "]",
		"g n\tline ground attenuation is (n) [" LITERAL (PTSCTL_GRND_ATTN) "]",
		"n n\tline neutral attenuation is (n) [" LITERAL (PTSCTL_LINE_ATTN) "]",
		"p n\tpower is (n) [" LITERAL (PTSCTL_MODE) "]",
		"q\tquiet mode",
		"r\tread and display attenuator settings",
		"v\tverbose mode",
		"w n\twait (n) millseconds [" LITERAL (PTSCTL_WAIT) "]",
		(char const *) (0)
	};
	struct _file_ port =
	{
		-1,
		PTSCTL_PORT
	};

#if defined (WIN32)

	HANDLE hSerial;
	DCB dcbSerial =
	{
		0
	};

#else

	struct termios termios;

#endif

	char const * units = PTSCTL_UNITS;
	unsigned wait = PTSCTL_WAIT;
	unsigned mode = PTSCTL_MODE;
	unsigned echo = PTSCTL_ECHO;
	unsigned line = PTSCTL_LINE_ATTN;
	unsigned grnd = PTSCTL_GRND_ATTN;
	unsigned data = 0;
	flag_t flags = (flag_t)(0);
	signed c;
	optind = 1;
	if (getenv ("PTSCTL"))
	{
		port.name = strdup (getenv ("PTSCTL"));
	}
	while ((c = getoptv (argc, argv, optv)) != -1)
	{
		switch (c)
		{
		case 'f':
			port.name = optarg;
			break;
		case 'g':
			_setbits (flags, PTSCTL_CHANGE);
			grnd = (unsigned)(uintspec (optarg, 0, 0x7F));
			break;
		case 'n':
			_setbits (flags, PTSCTL_CHANGE);
			line = (unsigned)(uintspec (optarg, 0, 0x7F));
			break;
		case 'p':
			_setbits (flags, PTSCTL_CHANGE);
			mode = (unsigned)(uintspec (synonym (optarg, modes, SIZEOF (modes)), 0, 1));
			break;
		case 'w':
			wait = (unsigned)(uintspec (optarg, 5, 100));
			break;
		case 'q':
			_setbits (flags, PTSCTL_SILENCE);
			break;
		case 'r':
			_setbits (flags, PTSCTL_DISPLAY);
			break;
		case 'v':
			_setbits (flags, PTSCTL_VERBOSE);
			break;
		case 'z':
			_setbits (flags, PTSCTL_ITERATE);
			break;
		default:
			break;
		}
	}
	argc -= optind;
	argv += optind;
	if (argc)
	{
		error (1, ENOTSUP, ERROR_TOOMANY);
	}

#if defined (WIN32)

	hSerial = CreateFile (port.name, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
	if (hSerial == INVALID_HANDLE_VALUE)
	{
		error (1, errno, FILE_CANTOPEN, port.name);
	}
	dcbSerial.DCBlength = sizeof (dcbSerial);
	if (!GetCommState (hSerial, &dcbSerial))
	{
		error (1, 0, FILE_CANTREAD " state", port.name);
	}
	dcbSerial.BaudRate = CBR_9600;
	dcbSerial.ByteSize = 8;
	dcbSerial.StopBits = ONESTOPBIT;
	dcbSerial.Parity = NOPARITY;
	if (!SetCommState (hSerial, &dcbSerial))
	{
		error (1, 0, FILE_CANTSAVE " state", port.name);
	}
	CloseHandle (hSerial);
	if ((port.file = open (port.name, O_BINARY | O_RDWR)) == -1)
	{
		error (1, errno, FILE_CANTOPEN, port.name);
	}

#else

	if ((port.file = open (port.name, O_RDWR|O_NOCTTY|O_NDELAY)) == -1)
	{
		error (1, 0, FILE_CANTOPEN, port.name);
	}
	tcgetattr (port.file, &termios);
	termios.c_cflag = CS8;
	cfsetospeed (&termios, B9600);
	tcsetattr (port.file, TCSANOW, &termios);

#endif

	function1 (&port, units, wait, echo);
	if (_anyset (flags, PTSCTL_CHANGE))
	{
		data = line << 8 | grnd << 1 | mode;
		function2 (&port, units, wait, data);
	}
	if (_anyset (flags, PTSCTL_DISPLAY))
	{
		function3 (&port, units, wait);
	}
	if (_anyset (flags, PTSCTL_ITERATE))
	{
		function4 (&port, units, wait);
	}
	close (port.file);
	return (0);
}
예제 #28
0
int main()
{
  function2 f2;
  const function2 cf2;
  function3 f3;

  handler2 h2;
  const handler2 ch2;
  handler3 h3;

  std::experimental::loop_scheduler scheduler;
  std::experimental::executor ex = scheduler.get_executor();

  ex = std::experimental::system_executor();
  assert(&ex.context() == &std::experimental::system_executor().context());

  invoke(std::experimental::chain(ex.wrap(function1)));
  invoke(std::experimental::chain(ex.wrap(function1), handler1));
  invoke(std::experimental::chain(ex.wrap(function1), &handler1));
  invoke(std::experimental::chain(ex.wrap(function1), handler2()));
  invoke(std::experimental::chain(ex.wrap(function1), h2));
  invoke(std::experimental::chain(ex.wrap(function1), ch2));
  invoke(std::experimental::chain(ex.wrap(function1), handler3()));
  invoke(std::experimental::chain(ex.wrap(function1), std::move(h3)));

  invoke(std::experimental::chain(ex.wrap(&function1)));
  invoke(std::experimental::chain(ex.wrap(&function1), handler1));
  invoke(std::experimental::chain(ex.wrap(&function1), &handler1));
  invoke(std::experimental::chain(ex.wrap(&function1), handler2()));
  invoke(std::experimental::chain(ex.wrap(&function1), h2));
  invoke(std::experimental::chain(ex.wrap(&function1), ch2));
  invoke(std::experimental::chain(ex.wrap(&function1), handler3()));
  invoke(std::experimental::chain(ex.wrap(&function1), std::move(h3)));

  invoke(std::experimental::chain(ex.wrap(function2())));
  invoke(std::experimental::chain(ex.wrap(function2()), handler1));
  invoke(std::experimental::chain(ex.wrap(function2()), &handler1));
  invoke(std::experimental::chain(ex.wrap(function2()), handler2()));
  invoke(std::experimental::chain(ex.wrap(function2()), h2));
  invoke(std::experimental::chain(ex.wrap(function2()), ch2));
  invoke(std::experimental::chain(ex.wrap(function2()), handler3()));
  invoke(std::experimental::chain(ex.wrap(function2()), std::move(h3)));

  invoke(std::experimental::chain(ex.wrap(f2)));
  invoke(std::experimental::chain(ex.wrap(f2), handler1));
  invoke(std::experimental::chain(ex.wrap(f2), &handler1));
  invoke(std::experimental::chain(ex.wrap(f2), handler2()));
  invoke(std::experimental::chain(ex.wrap(f2), h2));
  invoke(std::experimental::chain(ex.wrap(f2), ch2));
  invoke(std::experimental::chain(ex.wrap(f2), handler3()));
  invoke(std::experimental::chain(ex.wrap(f2), std::move(h3)));

  invoke(std::experimental::chain(ex.wrap(cf2)));
  invoke(std::experimental::chain(ex.wrap(cf2), handler1));
  invoke(std::experimental::chain(ex.wrap(cf2), &handler1));
  invoke(std::experimental::chain(ex.wrap(cf2), handler2()));
  invoke(std::experimental::chain(ex.wrap(cf2), h2));
  invoke(std::experimental::chain(ex.wrap(cf2), ch2));
  invoke(std::experimental::chain(ex.wrap(cf2), handler3()));
  invoke(std::experimental::chain(ex.wrap(cf2), std::move(h3)));

  invoke(std::experimental::chain(ex.wrap(function3())));
  invoke(std::experimental::chain(ex.wrap(function3()), handler1));
  invoke(std::experimental::chain(ex.wrap(function3()), &handler1));
  invoke(std::experimental::chain(ex.wrap(function3()), handler2()));
  invoke(std::experimental::chain(ex.wrap(function3()), h2));
  invoke(std::experimental::chain(ex.wrap(function3()), ch2));
  invoke(std::experimental::chain(ex.wrap(function3()), handler3()));
  invoke(std::experimental::chain(ex.wrap(function3()), std::move(h3)));

  invoke(std::experimental::chain(ex.wrap(std::move(f3))));
  invoke(std::experimental::chain(ex.wrap(std::move(f3)), handler1));
  invoke(std::experimental::chain(ex.wrap(std::move(f3)), &handler1));
  invoke(std::experimental::chain(ex.wrap(std::move(f3)), handler2()));
  invoke(std::experimental::chain(ex.wrap(std::move(f3)), h2));
  invoke(std::experimental::chain(ex.wrap(std::move(f3)), ch2));
  invoke(std::experimental::chain(ex.wrap(std::move(f3)), handler3()));
  invoke(std::experimental::chain(ex.wrap(std::move(f3)), std::move(h3)));

  assert(function_count == 56);
  assert(handler_count == 49);
}
예제 #29
0
파일: ex3.c 프로젝트: piotrplaneta/RTS
void *print_functions (void *args) {
	int i = (int) args;
	int j;

	if (i % 4 == 0) {
		for(j = 0; j < 3; j++) {
			function1();
		}
		for(j = 0; j < 3; j++) {
			function2();
		}
		for(j = 0; j < 3; j++) {
			function3();
		}
		for(j = 0; j < 3; j++) {
			function4();
		}
	}
	if (i % 4 == 1) {
		for(j = 0; j < 3; j++) {
			function2();
		}
		for(j = 0; j < 3; j++) {
			function3();
		}
		for(j = 0; j < 3; j++) {
			function4();
		}
		for(j = 0; j < 3; j++) {
			function1();
		}
	}
	if (i % 4 == 2) {
		for(j = 0; j < 3; j++) {
			function3();
		}
		for(j = 0; j < 3; j++) {
			function4();
		}
		for(j = 0; j < 3; j++) {
			function1();
		}
		for(j = 0; j < 3; j++) {
			function2();
		}
	}
	if (i % 4 == 3) {
		for(j = 0; j < 3; j++) {
			function4();
		}
		for(j = 0; j < 3; j++) {
			function1();
		}
		for(j = 0; j < 3; j++) {
			function2();
		}
		for(j = 0; j < 3; j++) {
			function3();
		}
	}
	return 0;
}
예제 #30
0
  /** Cache J2000 rotation over existing cached time range using polynomials
   *
   * This method will reload an internal cache with matrices
   * formed from rotation angles fit to polynomials over a time
   * range.
   *
   * @param function1   The first polynomial function used to
   *                    find the rotation angles
   * @param function2   The second polynomial function used to
   *                    find the rotation angles
   * @param function3   The third polynomial function used to
   *                    find the rotation angles
   */
  void LineScanCameraRotation::ReloadCache() {
    NaifStatus::CheckErrors();

    // Make sure caches are already loaded
    if(!p_cachesLoaded) {
      QString msg = "A LineScanCameraRotation cache has not been loaded yet";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }

    // Clear existing matrices from cache
    p_cache.clear();

    // Create polynomials fit to angles & use to reload cache
    Isis::PolynomialUnivariate function1(p_degree);
    Isis::PolynomialUnivariate function2(p_degree);
    Isis::PolynomialUnivariate function3(p_degree);

    // Get the coefficients of the polynomials already fit to the angles of rotation defining [CI]
    std::vector<double> coeffAng1;
    std::vector<double> coeffAng2;
    std::vector<double> coeffAng3;
    GetPolynomial(coeffAng1, coeffAng2, coeffAng3);

    // Reset linear term to center around zero -- what works best is either roll-avg & pitchavg+ or pitchavg+ & yawavg-
//    coeffAng1[1] -= 0.0000158661225;
//    coeffAng2[1] = 0.0000308433;
//    coeffAng3[0] = -0.001517547;
    if(p_pitchRate)  coeffAng2[1] = p_pitchRate;
    if(p_yaw)  coeffAng3[0] = p_yaw;

    // Load the functions with the coefficients
    function1.SetCoefficients(coeffAng1);
    function2.SetCoefficients(coeffAng2);
    function3.SetCoefficients(coeffAng3);

    double CI[3][3];
    double IJ[3][3];
    std::vector<double> rtime;
    SpiceRotation *prot = p_spi->bodyRotation();
    std::vector<double> CJ;
    CJ.resize(9);

    for(std::vector<double>::size_type pos = 0; pos < p_cacheTime.size(); pos++) {
      double et = p_cacheTime.at(pos);
      rtime.push_back((et - GetBaseTime()) / GetTimeScale());
      double angle1 = function1.Evaluate(rtime);
      double angle2 = function2.Evaluate(rtime);
      double angle3 = function3.Evaluate(rtime);
      rtime.clear();

// Get the first angle back into the range Naif expects [180.,180.]
      if(angle1 < -1 * pi_c()) {
        angle1 += twopi_c();
      }
      else if(angle1 > pi_c()) {
        angle1 -= twopi_c();
      }

      eul2m_c((SpiceDouble) angle3, (SpiceDouble) angle2, (SpiceDouble) angle1,
              p_axis3,                    p_axis2,                    p_axis1,
              CI);
      mxm_c((SpiceDouble( *)[3]) & (p_jitter->SetEphemerisTimeHPF(et))[0], CI, CI);

      prot->SetEphemerisTime(et);
      mxm_c((SpiceDouble( *)[3]) & (p_cacheIB.at(pos))[0], (SpiceDouble( *)[3]) & (prot->Matrix())[0], IJ);
      mxm_c(CI, IJ, (SpiceDouble( *)[3]) &CJ[0]);

      p_cache.push_back(CJ);   // J2000 to constant frame
    }

    // Set source to cache to get updated values
    SetSource(SpiceRotation::Memcache);

    // Make sure SetEphemerisTime updates the matrix by resetting it twice (in case the first one
    // matches the current et.  p_et is private and not available from the child class
    NaifStatus::CheckErrors();
    SetEphemerisTime(p_cacheTime[0]);
    SetEphemerisTime(p_cacheTime[1]);

    NaifStatus::CheckErrors();
  }