Пример #1
0
void CRYPTO_STATIC_MUTEX_lock_read(struct CRYPTO_STATIC_MUTEX *lock) {
  union run_once_arg_t arg;
  arg.data = lock;
  /* Since we have to support Windows XP, read locks are actually exclusive. */
  run_once(&lock->once, static_lock_init, arg);
  EnterCriticalSection(&lock->lock);
}
Пример #2
0
void simple_thread::run()
{
    m_status = 1 ;
    if( on_init() != 0 ) return ;
    while(m_status == 1) run_once() ;

    on_fini() ;
}
Пример #3
0
void RoundRobinScheduler::run(void)
{
	m_graph.checkGraph();
	
	for (int i = 0; i < 10; ++i)
	{
		run_once();
	}
}
Пример #4
0
void
TrexStatelessDpCore::start() {

    while (true) {
        run_once();

        if ( m_core->is_terminated_by_master() ) {
            break;
        }
    }
}
Пример #5
0
int
main(int argc, char **argv)
{
#ifdef HAVE_SETRLIMIT
	struct rlimit rl;
#endif
	int i, c;
	struct timeval *tv;

	int num_pipes = 100;
#ifdef _WIN32
	WSADATA WSAData;
	WSAStartup(0x101, &WSAData);
#endif

	while ((c = getopt(argc, argv, "n:")) != -1) {
		switch (c) {
		case 'n':
			num_pipes = atoi(optarg);
			break;
		default:
			fprintf(stderr, "Illegal argument \"%c\"\n", c);
			exit(1);
		}
	}

#ifdef HAVE_SETRLIMIT 
	rl.rlim_cur = rl.rlim_max = num_pipes * 2 + 50;
	if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {
		perror("setrlimit");
		exit(1);
	}
#endif

	event_init();

	for (i = 0; i < 25; i++) {
		tv = run_once(num_pipes);
		if (tv == NULL)
			exit(1);
		fprintf(stdout, "%ld\n",
			tv->tv_sec * 1000000L + tv->tv_usec);
	}

#ifdef _WIN32
	WSACleanup();
#endif

	exit(0);
}
Пример #6
0
int main(int argc, char **argv)
{
	int ret = 0;
	char *path = NULL;
	struct xwii_iface *iface;

	if (argc > 2 || (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0))) {
	    printf("This is %s version %s.\n\n", PACKAGE, VERSION);
		printf("Usage: %s [-h | --help] [-o | --once]\n", argv[0]);
		printf("\t-h\t--help\tShow this information.\n");
		printf("\t-o\t--once\tFind one device and do not try to rediscover.\n");
		return 1;
	} 
	

	while (true) {
	    struct xwii_monitor *mon = xwii_monitor_new(false, false);
	    if (!mon) {
		    printf("Cannot create monitor\n");
		    return 2;
	    }
    	path = xwii_monitor_poll(mon);
    	xwii_monitor_unref(mon);
		usleep(100000);
       	if (path != NULL) {
		    ret = xwii_iface_new(&iface, path);
		    if (ret) {
			    printf("Error newing '%s' err:%d\n", path, ret);
		    } else {
                ret = xwii_iface_open(iface, XWII_IFACE_CORE |
					                     XWII_IFACE_WRITABLE);
	            if (ret) {
		            printf("Error opening '%s' err:%d\n", path, ret);
	            } else {
		            ret = run_once(iface);
		            if (ret) {
            		    printf("Event-Loop exit with status %d\n", ret);
            		}
            	}
		    }
		    free(path);
		    xwii_iface_unref(iface);
		}
		if (argc >= 2 && (strcmp(argv[1], "-o") == 0 || strcmp(argv[1], "--once") == 0))
		    break;
	}


	return ret;
}
Пример #7
0
int
main(int argc, char *argv[])
{
    int interactive = 0;
    int large = 0;
    int small = 0;
    int c;
    
    while ((c = getopt(argc, argv, "isl")) != EOF) {        
        switch (c) {
            case 'i':
                interactive = 1;
                break;            
            case 's':
                small = 1;
                break;
            case 'l':
                large = 1;
                break;                
            default:
                break;
        }
    }
    
    if (interactive) {
        run();
    }
    else if (small)
    {
        run_once(SMALL_CHUNK_SIZE, SMALL_COUNT);
    }
    else if (large)
    {
        run_once(LARGE_CHUNK_SIZE, LARGE_COUNT);            
    }
    exit(0);
}
Пример #8
0
void ObjectTrackerRos<Tracker>::run()
{
    running_ = true;

    while (ros::ok() && running_)
    {
        if (!obsrv_updated_)
        {
            usleep(100);
            continue;
        }

        run_once();
    }
}
Пример #9
0
int main(int argc, char** argv)
{
#define ITERATIONS 1
	uint64_t start_time = get_small_time();
	for (int i = 0; i < ITERATIONS; i++) {
		run_once();
#ifdef DEBUG
		queue.try_lock();
#endif
	}
	uint64_t end_time = get_small_time();
	std::cout<<"Elapsed Time: "<<(end_time - start_time)<<std::endl;


	return 0;
}
Пример #10
0
  void run(bool force_stop)
  {
    std::cout << "Start test for " << test_times_ << " times and once with " << connection_number_ << " connections.\n";
    if (pause_seconds_ != 0)
      std::cout << "for test server concurrent processing, client pause " << pause_seconds_ << " seconds before send data.\n";
    std::cout << "\n";

    std::size_t counts = 0;
    
    for (std::size_t i = 0; i < test_times_; ++i)
    {
      run_once(force_stop);
      counts += connection_number_;

      std::cout << "Established connections " << counts << ", time " << time_long_.total_milliseconds() << " ms. ";
      std::cout << "average " << time_long_.total_milliseconds()/(i+1) << " ms.\n";
      if (error_count_.get_timeout() != 0)
      {
        std::cout << "Total " << error_count_.get_timeout() << " connections timeout. ";
        std::cout << "average " << error_count_.get_timeout()/(i+1) << " timeout.\n";
      }
      if (error_count_.get_error() != 0)
      {
        std::cout << "Total " << error_count_.get_error() << " connections failed. ";
        std::cout << "average " << error_count_.get_error()/(i+1) << " failed.\n";
      }

      if (i < test_times_ - 1)
      {
        std::cout << "Wait " << wait_seconds_ << " seconds for next test. remain " << test_times_ - i - 1 <<" times.\n\n";
        timer_.expires_from_now(boost::posix_time::seconds(wait_seconds_));
        timer_.wait();
      }
      else
        std::cout << "\n";
    }

    std::cout << "All test done! total established connections " << counts << ", time " << time_long_.total_milliseconds() << " ms.";
    if (error_count_.get_timeout() != 0)
      std::cout << " total " << error_count_.get_timeout() << " connections timeout.";
    if (error_count_.get_error() != 0)
      std::cout << " total " << error_count_.get_error() << " connections failed.";
    std::cout << "\n";
  }
Пример #11
0
void master_threads::listen_callback(int, ACL_EVENT*, ACL_VSTREAM* sstream, void*)
{
	ACL_VSTREAM* client = acl_vstream_accept(sstream, NULL, 0);

	if (client == NULL)
	{
		logger_error("accept error(%s)", acl_last_serror());
		__stop = true;
	}
	else if (__thread_pool != NULL)
	{
		acl_pthread_pool_add(__thread_pool, thread_run, client);
		__count++;
	}
	else
	{
		// 单线程方式串行处理
		run_once(client);
		__count++;
	}
}
Пример #12
0
  // Just pass the whole program argument list here.
  static int from_main(int argc, const char *argv[]) {
    const char *real_program_name = argv[0];
  
    NP1_ASSERT(argc >= 2, get_usage(real_program_name));
    NP1_ASSERT(str::is_valid_utf8(argc, argv), "Arguments are not valid UTF-8 strings");
  
    int fake_argc = argc - 1;
    const char **fake_argv = &argv[1];

    std::vector<std::string> args = str::argv_to_string_vector(fake_argc, fake_argv);

    io::file stdin_f;
    stdin_f.from_stdin();

    io::file stdout_f;
    stdout_f.from_stdout();

    run_once(stdin_f, stdout_f, args);
  
    return 0;
  }
Пример #13
0
int main (int argc, char **argv)
{
	num_pipes = 5000;
	num_active = 1000;

	struct rlimit rl;
	rl.rlim_cur = rl.rlim_max = num_pipes * 2 + 50;
	if (setrlimit(RLIMIT_NOFILE, &rl) == -1)
	{
		perror("setrlimit");
	}

	evio  = new ev::io[num_pipes];
	pipes = new int[num_pipes*2];
	
	//创建对应数量的pipe
	int i = 0;
	int *cp = pipes;
	for ( ;i < num_pipes;i ++,cp += 2 )
	{
#ifdef USE_PIPES
		if (pipe(cp) == -1)
		{
#else
		if (socketpair(AF_UNIX, SOCK_STREAM, 0, cp) == -1)
		{
#endif
			perror("pipe");
			exit(1);
		}
	
		ev::io *w = &(evio[i]);
		w->set<read_cb>();
		w->start( *cp,EV_READ );  //监听读端口,待会从写端口写入数据
	}

	run_once();

	exit(0);
}
TEST(FCPriQueue, push_pop) {
  int ops = 1000;
  int work = 0;
  std::chrono::steady_clock::time_point when =
      std::chrono::steady_clock::now() + std::chrono::hours(24);
  for (auto n : nthr) {
    nthreads = n;
    FCPQ pq(10000);
    auto fn = [&](uint32_t tid) {
      for (int i = tid; i < ops; i += nthreads) {
        CHECK(pq.try_push(i));
        CHECK(pq.try_push_until(i, when));
        pq.push(i);
        doWork(work);
        int v;
        CHECK(pq.try_pop(v));
        EXPECT_NE(pq.try_pop_until(when), folly::none);
        pq.pop(v);
        doWork(work);
      }
    };
    run_once(pq, fn);
  }
}
Пример #15
0
int futex(int *uaddr, int op, int val,
          const struct timespec *timeout,
          int *uaddr2, int val3)
{
  uint64_t ms_timeout = (uint64_t)-1;
  assert(uaddr2 == NULL);
  assert(val3 == 0);
  if(timeout != NULL) {
    ms_timeout = timeout->tv_sec*1000 + timeout->tv_nsec/1000000L;
    assert(ms_timeout > 0);
  }

  run_once(futex_init());
  switch(op) {
    case FUTEX_WAIT:
      return futex_wait(uaddr, val, ms_timeout);
    case FUTEX_WAKE:
      return futex_wake(uaddr, val);
    default:
      errno = ENOSYS;
      return -1;
  }
  return -1;
}
Пример #16
0
void ROSGate::run(){
	while(ros::ok() && ok()){
		run_once();
	}
}
Пример #17
0
int
main (int argc, char **argv)
{
    struct rlimit rl;
    int i, c;
    struct timeval *tv;
    int *cp;
    extern char *optarg;

    num_pipes = 100;
    num_active = 1;
    num_writes = num_pipes;
    while ((c = getopt(argc, argv, "n:a:w:tep")) != -1) {
        switch (c) {
            case 'n':
                num_pipes = atoi(optarg);
                break;
            case 'a':
                num_active = atoi(optarg);
                break;
            case 'w':
                num_writes = atoi(optarg);
                break;
            case 'e':
                native = 1;
                break;
            case 't':
                timers = 1;
                break;
            case 'p':
                set_prios = 1;
                break;
            default:
                fprintf(stderr, "Illegal argument \"%c\"\n", c);
                exit(1);
        }
    }

#if 1
    rl.rlim_cur = rl.rlim_max = num_pipes * 2 + 50;
    if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {
        perror("setrlimit");
    }
#endif

    io_blocks = calloc(num_pipes, sizeof(*io_blocks));
    pipes = calloc(num_pipes * 2, sizeof(int));
    if (io_blocks == NULL || pipes == NULL) {
        perror("malloc");
        exit(1);
    }

    event_init();

    // Open as many pipes/sockets as required; allocate watchers and timers:
    for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
        io_blocks[i].idx = i;
        if (native) {
#if NATIVE
            ev_init (&io_blocks[i].timer, timer_cb);
            ev_init (&io_blocks[i].io, read_thunk);
            io_blocks[i].io.data = &io_blocks[i];
#endif
        }
        else {
            // This actually adds the event to the event loop, so we don't do it here:
            // event_set(&events[i], cp[0], EV_READ | EV_PERSIST, read_cb, (void *) i);
        }
#ifdef USE_PIPES
        if (pipe(cp) == -1) {
#else
        if (socketpair(AF_UNIX, SOCK_STREAM, 0, cp) == -1) {
#endif
            perror("pipe");
            exit(1);
        }
    }

    for (i = 0; i < 2; i++) {
        tv = run_once();
    }

    exit(0);
}
Пример #18
0
void master_threads::thread_run(void* arg)
{
	ACL_VSTREAM* client = (ACL_VSTREAM*) arg;
	run_once(client);
}
Пример #19
0
/* Create a new socket of type TYPE in domain DOMAIN, using
   protocol PROTOCOL.  If PROTOCOL is zero, one is chosen automatically.
   Returns a file descriptor for the new socket, or -1 for errors.  */
int __socket(int domain, int type, int protocol)
{
	Rock *r;
	int cfd, n;
	int open_flags = O_RDWR;
	int pfd[2];
	char *net;
	char msg[128];
	static struct close_cb _sock_close_cb = {.func = _sock_fd_closed};

	run_once(register_close_cb(&_sock_close_cb));

	switch (domain) {
		case PF_INET:
			open_flags |= (type & SOCK_NONBLOCK ? O_NONBLOCK : 0);
			/* get a free network directory */
			switch (_sock_strip_opts(type)) {
				case SOCK_DGRAM:
					net = "udp";
					cfd = open("/net/udp/clone", open_flags);
					/* All BSD UDP sockets are in 'headers' mode, where each
					 * packet has the remote addr:port, local addr:port and
					 * other info. */
					if (!(cfd < 0)) {
						n = snprintf(msg, sizeof(msg), "headers");
						n = write(cfd, msg, n);
						if (n < 0) {
							perror("UDP socket headers failed");
							return -1;
						}
						if (lseek(cfd, 0, SEEK_SET) != 0) {
							perror("UDP socket seek failed");
							return -1;
						}
					}
					break;
				case SOCK_STREAM:
					net = "tcp";
					cfd = open("/net/tcp/clone", open_flags);
					break;
				default:
					errno = EPROTONOSUPPORT;
					return -1;
			}
			if (cfd < 0) {
				return -1;
			}
			return _sock_data(cfd, net, domain, type, protocol, 0);
		case PF_UNIX:
			if (pipe(pfd) < 0) {
				return -1;
			}
			r = _sock_newrock(pfd[0]);
			r->domain = domain;
			r->stype = _sock_strip_opts(type);
			r->sopts = _sock_get_opts(type);
			r->protocol = protocol;
			r->other = pfd[1];
			return pfd[0];
		default:
			errno = EPROTONOSUPPORT;
			return -1;
	}
}
Пример #20
0
 void run()
 {
     do
         print();
     while (run_once());
 }
Пример #21
0
int main(int argc, char * argv[]) 
{
    int ix, iy, c;
    concurrency = 10;
    request_nums = 1000;
    round_nums = 1;
    conn_type = 0; // 1 - long ; 0 - short
    char * host = NULL;
    int port = -1;

    while ( (c = getopt(argc, argv, "c:n:r:t:h:p:")) != -1) {
	switch (c) {
	    case 'c':
		concurrency = atoi (optarg);
		break;
	    case 'n':
		request_nums = atoi (optarg);
		break;
	    case 'r':
		round_nums = atoi (optarg);
		break;
	    case 't':
	        conn_type = atoi (optarg);
		break;
	    case 'h':
		host = strdup (optarg);
		break;
	    case 'p':
		port = atoi (optarg);
		break;
	    default:
		fprintf (stderr, "usage: bench -c -n -r -t\n");
		exit(-1);
	}
    }

    if (host == NULL) 
	host = strdup (host_def);

    if (port == -1) 
	port = port_def;

    // calc the run_nums in one round
    run_nums = request_nums / concurrency;
    if (run_nums < 1) {
	fprintf (stderr, "requset is less than concurrency\n");
	exit (-1);
    }

    // create the sockets
    fds = (int*)malloc(sizeof(int) * concurrency);
    if (fds == NULL) {
	fprintf (stderr, "malloc for fds failed\n");
	exit (-1);
    }
    
    // connect 
    int fd_tmp;
    int concurrency_tmp = concurrency;
    int connect_fail = 0;
    for (ix = 0, iy = 0; ix < concurrency; ix++) {
	fd_tmp = get_connect (host, port);
	if (fd_tmp == -1) {
	    concurrency_tmp -= 1;
	    connect_fail += 1;
	    continue;
	}
	fds[iy++] = fd_tmp;
    }

    // judge
    if (connect_fail == concurrency) {
	fprintf (stderr, "All Connect Failed\n");
	exit (-1);
    }

    concurrency = concurrency_tmp;
    fprintf (stdout, "connect fail : %d\n", connect_fail);

    // create events
    events = (struct event*)malloc(sizeof(struct event) * concurrency);
    if (events == NULL) {
	fprintf (stderr, "Malloc For events Failed\n");
	exit (-1);
    }

    event_init();

    struct timeval ts, te, ta;
    int r_num = 0;
    gettimeofday (&ts, NULL);
    int round_nums_tmp = round_nums;
    while ( (round_nums_tmp--) > 0) {
	r_num += 1;
	run_once(run_nums);
	fprintf (stdout, "%d round finish\n", r_num);
    }
    gettimeofday (&te, NULL);

    lisatimersub (&te, &ts, &ta);


    /* 
       Output 
     */
    fprintf (stdout, "\n\n");
    fprintf (stdout, "Service Name : %s\n", host);
    fprintf (stdout, "Service Port : %d\n", port);
    fprintf (stdout, "\n");

    fprintf (stdout, "Concurrency Level : \t\t%10d\n", concurrency);
    fprintf (stdout, "Requests Nums : \t\t%10d\n", request_nums * round_nums);
    fprintf (stdout, "Round Nums : \t\t\t%10d\n", round_nums);
    fprintf (stdout, "\n");

    double spend_time = (double)ta.tv_sec + (double)(ta.tv_usec) / 1000000;
    fprintf (stdout, "Time taken for tests : \t%20.10g seconds\n", spend_time);
    fprintf (stdout, "Requests per seconds : \t%20.10g [#/sec]\n", \
	                   (double)(request_nums * round_nums) / spend_time);

    return 0;
}
Пример #22
0
void CRYPTO_once(CRYPTO_once_t *in_once, void (*init)(void)) {
  union run_once_arg_t arg;
  arg.func = init;
  run_once(in_once, call_once_init, arg);
}
Пример #23
0
void Nsf_Impl::run_until( time_t end )
{
	while ( time() < end )
		run_once( end );
}
Пример #24
0
void loop_impl::flush()
{
    while(run_once(false));
}
static uint64_t test(std::string name, Exp exp, uint64_t base) {
  int ops = FLAGS_ops;
  int work = FLAGS_work;

  uint64_t min = UINTMAX_MAX;
  uint64_t max = 0;
  uint64_t sum = 0;

  for (int r = 0; r < FLAGS_reps; ++r) {
    uint64_t dur;
    switch (exp) {
      case NoFC: {
        Baseline pq;
        auto fn = [&](uint32_t tid) {
          for (int i = tid; i < ops; i += nthreads) {
            CHECK(pq.try_push(i));
            doWork(work);
            int v;
            CHECK(pq.try_pop(v));
            doWork(work);
          }
        };
        dur = run_once(pq, fn);
        break;
      }
      case FCNonBlock: {
        FCPQ pq;
        auto fn = [&](uint32_t tid) {
          for (int i = tid; i < ops; i += nthreads) {
            CHECK(pq.try_push(i));
            doWork(work);
            int v;
            CHECK(pq.try_pop(v));
            doWork(work);
          }
        };
        dur = run_once(pq, fn);
        break;
      }
      case FCBlock: {
        FCPQ pq;
        auto fn = [&](uint32_t tid) {
          for (int i = tid; i < ops; i += nthreads) {
            pq.push(i);
            doWork(work);
            int v;
            pq.pop(v);
            doWork(work);
          }
        };
        dur = run_once(pq, fn);
        break;
      }
      case FCTimed: {
        FCPQ pq;
        auto fn = [&](uint32_t tid) {
          std::chrono::steady_clock::time_point when =
              std::chrono::steady_clock::now() + std::chrono::hours(24);
          for (int i = tid; i < ops; i += nthreads) {
            CHECK(pq.try_push_until(i, when));
            doWork(work);
            EXPECT_NE(pq.try_pop_until(when), folly::none);
            doWork(work);
          }
        };
        dur = run_once(pq, fn);
        break;
      }
      default:
        CHECK(false);
    }

    sum += dur;
    min = std::min(min, dur);
    max = std::max(max, dur);
  }

  uint64_t avg = sum / FLAGS_reps;
  uint64_t res = min;
  std::cout << name;
  std::cout << "   " << std::setw(4) << max / FLAGS_ops << " ns";
  std::cout << "   " << std::setw(4) << avg / FLAGS_ops << " ns";
  std::cout << "   " << std::setw(4) << res / FLAGS_ops << " ns";
  if (base) {
    std::cout << " " << std::setw(3) << 100 * base / res << "%";
  }
  std::cout << std::endl;
  return res;
}
Пример #26
0
int
main(int argc, char **argv)
{
#ifndef WIN32
	struct rlimit rl;
#endif
	int i, c;
	struct timeval *tv;
	int *cp;

#ifdef WIN32
	WSADATA WSAData;
	WSAStartup(0x101, &WSAData);
#endif
	num_pipes = 100;
	num_active = 1;
	num_writes = num_pipes;
	while ((c = getopt(argc, argv, "n:a:w:")) != -1) {
		switch (c) {
		case 'n':
			num_pipes = atoi(optarg);
			break;
		case 'a':
			num_active = atoi(optarg);
			break;
		case 'w':
			num_writes = atoi(optarg);
			break;
		default:
			fprintf(stderr, "Illegal argument \"%c\"\n", c);
			exit(1);
		}
	}

#ifndef WIN32
	rl.rlim_cur = rl.rlim_max = num_pipes * 2 + 50;
	if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {
		perror("setrlimit");
		exit(1);
	}
#endif

	events = calloc(num_pipes, sizeof(struct event));
	pipes = calloc(num_pipes * 2, sizeof(int));
	if (events == NULL || pipes == NULL) {
		perror("malloc");
		exit(1);
	}

	event_init();

	for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
#ifdef USE_PIPES
		if (pipe(cp) == -1) {
#else
		if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, cp) == -1) {
#endif
			perror("pipe");
			exit(1);
		}
	}

	for (i = 0; i < 25; i++) {
		tv = run_once();
		if (tv == NULL)
			exit(1);
		fprintf(stdout, "%ld\n",
			tv->tv_sec * 1000000L + tv->tv_usec);
	}

	exit(0);
}
Пример #27
0
int main( int argc, char *argv[] )  {

  if ((argc == 2) && (strcmp(argv[1], "leak_check") == 0)) {
    valgrind_test();
    run_once("produce_all_data 1");
    multiple_observers();
  }
  else {
    multiple_observers();
    run_once("produce_all_data: 1");
    run_once("log_nondominated: none  compute_indicators: 0");
    run_once("log_nondominated: all   compute_indicators: 0");
    run_once("log_nondominated: final compute_indicators: 0");
    run_once("log_nondominated: none  compute_indicators: 1");
    run_once("log_nondominated: all   compute_indicators: 1");
    run_once("log_nondominated: final compute_indicators: 1");
    run_once("log_nondominated: none  compute_indicators: 1 log_decision_variables: all");
    run_once("log_nondominated: all   compute_indicators: 0 log_decision_variables: none");
    run_once("log_nondominated: final compute_indicators: 1 log_decision_variables: low_dim");
  }

  coco_remove_directory("exdata");
  return 0;
}