extern "C" void
        dispatch_after_lambda(void)
{
    MU_BEGIN_TEST(dispatch_after_lambda);

    dispatch_async(dispatch_get_main_queue(), [=]{
		dispatch_time_t time_a_min = dispatch_time(0,  5.5*NSEC_PER_SEC);
        dispatch_time_t time_a     = dispatch_time(0,  6.0*NSEC_PER_SEC);
		dispatch_time_t time_a_max = dispatch_time(0,  6.5*NSEC_PER_SEC);
		dispatch_time_t time_a_start = dispatch_time(0,0);
        dispatch_after(time_a, dispatch_get_current_queue(), [=]{
			dispatch_time_t now_a = dispatch_time(0, 0);
			MU_MESSAGE("must finish between 5.5s and 6.5s: %f",(now_a-time_a_start)/(float)NSEC_PER_SEC);
			MU_ASSERT_TRUE(0<=(now_a - time_a_min));
			MU_ASSERT_TRUE(0<=(time_a_max - now_a));

			dispatch_time_t time_b_min = dispatch_time(0,  1.5*NSEC_PER_SEC);
			dispatch_time_t time_b     = dispatch_time(0,    2*NSEC_PER_SEC);
			dispatch_time_t time_b_max = dispatch_time(0,  2.5*NSEC_PER_SEC);
			dispatch_time_t time_b_start = dispatch_time(0,0);
            dispatch_after(time_b, dispatch_get_current_queue(), [=]{
				dispatch_time_t now_b = dispatch_time(0, 0);
				MU_MESSAGE("must finish between 1.5s and 2.5s: %f",(now_b-time_b_start)/(float)NSEC_PER_SEC);
				MU_ASSERT_TRUE(0<=(now_b - time_b_min));
				MU_ASSERT_TRUE(0<=(time_b_max - now_b));

#if 1 // FIXME: Nesting three lambdas seems to be broken...
				dispatch_time_t time_c_min = dispatch_time(0,  0*NSEC_PER_SEC);
				dispatch_time_t time_c     = dispatch_time(0,  0*NSEC_PER_SEC);
				dispatch_time_t time_c_max = dispatch_time(0,  .5*NSEC_PER_SEC);                
				dispatch_time_t time_c_start = dispatch_time(0, 0);
                dispatch_after(time_c, dispatch_get_current_queue(), [=]{
					dispatch_time_t now_c = dispatch_time(0, 0);
					MU_MESSAGE("must finish between 0s and .5s:  %f",(now_c-time_c_start)/(float)NSEC_PER_SEC);
					MU_ASSERT_TRUE(0<=(now_c - time_c_min));
					MU_ASSERT_TRUE(0<=(time_c_max - now_c));

					dispatch_async_f(dispatch_get_current_queue(), NULL, done);
				});
#else
                dispatch_async_f(dispatch_get_current_queue(), NULL, done);
#endif
			});
		});
	});

	dispatch_main();
	MU_FAIL("Should never reach this");
	MU_END_TEST;
}
Esempio n. 2
0
//--------------------------------------------------------------
void testApp::setup(){
  current_msg_string = 0;
  
  settingXml.loadFile("settings.xml");
  
  string portName = settingXml.getValue("settings:serial-port", "/dev/tty.usbmodem1411");
  string hostName = settingXml.getValue("settings:host", HOST_NAME);
  int baudRate = settingXml.getValue("settings:baud-rate", BAUD_RATE);
  int listenPort = settingXml.getValue("settings:listen-port", LISTEN_PORT);
  int sendPort = settingXml.getValue("settings:send-port", SEND_PORT);
  
  cout << "host : "<< hostName <<"listen port at: "<<listenPort << "sendport at: "<< sendPort<<endl;

  busy = false;
  isReset = false;
  serial.enumerateDevices();
  serial.setup(portName, baudRate);
  
  reciver.setup(listenPort);

  sender.setup(hostName, sendPort);
  
  nTimesRead = 0;
	nBytesRead = 0;
	readTime = 0;
  currentPosition = 0;
	memset(bytesReadString, 0, 7);
  
  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{//do reset after 5 seconds
  });
Esempio n. 3
0
queue xdispatch::current_queue()
{
#ifdef __APPLE__
    // disable deprecation warning for get_current_queue
 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
    return queue( dispatch_get_current_queue() );
}
Esempio n. 4
0
static void dispatch_start(void* context) {
    dispatch_time_t time_a;
    time_delta_t* delta = (time_delta_t*)malloc(sizeof(time_delta_t));
    delta->min = dispatch_time(0,  NSEC_PER_SEC*5.5);
    time_a     = dispatch_time(0,  NSEC_PER_SEC*6.0);
    delta->max = dispatch_time(0,  NSEC_PER_SEC*6.5);
    delta->start = dispatch_time(0,0);
    dispatch_after_f(time_a, dispatch_get_current_queue(), delta, dispatch_6);
}
Esempio n. 5
0
void
func_outer(void* context)
{
    UNREFERENCED_PARAMETER(context);
    time_a_min = dispatch_time(0,  (int64_t)5.5*NSEC_PER_SEC);
    time_a     = dispatch_time(0,   6*NSEC_PER_SEC);
    time_a_max = dispatch_time(0,  (int64_t)6.5*NSEC_PER_SEC);
    dispatch_after_f(time_a, dispatch_get_current_queue(), NULL, func_a);
}
Esempio n. 6
0
static void dispatch_0(void* context) {
    time_delta_t* previous = (time_delta_t*)context;
    dispatch_time_t now_c = dispatch_time(0, 0);
    MU_MESSAGE("must finish between 0.0s and 0.5s: %f",(now_c-previous->start)/(float)NSEC_PER_SEC);
    MU_ASSERT_TRUE(0<=(now_c - previous->min));
    MU_ASSERT_TRUE(0<=(previous->max - now_c));

    dispatch_async_f(dispatch_get_current_queue(), NULL, done);
}
Esempio n. 7
0
void
func_c(void* context)
{
    dispatch_time_t now_c = dispatch_time(0, 0);
    UNREFERENCED_PARAMETER(context);

    test_time_less_than("can't finish faster than 0s", 0, now_c - time_c_min);
    test_time_less_than("must finish faster than .5s", 0, time_c_max - now_c);

    dispatch_async_f(dispatch_get_current_queue(), NULL, done);
}
Esempio n. 8
0
static mrb_value
mrb_queue_current(mrb_state *mrb, mrb_value self)
{
  mrb_value instance;
  dispatch_queue_t q;

  instance = mrb_queue_create_instance(mrb);
  q = dispatch_get_current_queue();

  return mrb_queue_set_queue(instance, q);
}
Esempio n. 9
0
void
func_a(void* context)
{
    dispatch_time_t now_a = dispatch_time(0, 0);
    UNREFERENCED_PARAMETER(context);
    test_time_less_than("can't finish faster than 5.5s", 0, now_a - time_a_min);
    test_time_less_than("must finish faster than  6.5s", 0, time_a_max - now_a);

    time_b_min = dispatch_time(0,  (int64_t)1.5*NSEC_PER_SEC);
    time_b     = dispatch_time(0,    2*NSEC_PER_SEC);
    time_b_max = dispatch_time(0,  (int64_t)2.5*NSEC_PER_SEC);
    dispatch_after_f(time_b, dispatch_get_current_queue(), NULL, func_b);
}
Esempio n. 10
0
void WorkQueue::executeWorkItem(void* item)
{
    WorkQueue* queue = static_cast<WorkQueue*>(dispatch_get_context(dispatch_get_current_queue()));
    OwnPtr<WorkItem> workItem(static_cast<WorkItem*>(item));
    
    {
        MutexLocker locker(queue->m_isValidMutex);
        if (!queue->m_isValid)
            return;
    }
    
    workItem->execute();
}
Esempio n. 11
0
void WorkQueue::executeFunction(void* context)
{
    WorkQueue* queue = static_cast<WorkQueue*>(dispatch_get_context(dispatch_get_current_queue()));
    OwnPtr<Function<void()> > function = adoptPtr(static_cast<Function<void()>*>(context));
    
    {
        MutexLocker locker(queue->m_isValidMutex);
        if (!queue->m_isValid)
            return;
    }

    (*function)();
}
Esempio n. 12
0
static void dispatch_6(void* context) {
    dispatch_time_t time_b;
    time_delta_t* previous = (time_delta_t*)context;
    time_delta_t* delta = (time_delta_t*)malloc(sizeof(time_delta_t));
    dispatch_time_t now_a = dispatch_time(0, 0);
    MU_MESSAGE("must finish between 5.5s and 6.5s: %f",(now_a-previous->start)/(float)NSEC_PER_SEC);
    MU_ASSERT_TRUE(0<=(now_a - previous->min));
    MU_ASSERT_TRUE(0<=(previous->max - now_a));

    delta->min = dispatch_time(0,  1.5*NSEC_PER_SEC);
    time_b = dispatch_time(0,    2*NSEC_PER_SEC);
    delta->max = dispatch_time(0,  2.5*NSEC_PER_SEC);
    delta->start = dispatch_time(0,0);
    dispatch_after_f(time_b, dispatch_get_current_queue(), delta, dispatch_2);
}
static void
		start_node(void *context)
{
	dispatch_group_t g = (dispatch_group_t)(context);
	size_t i;
	dispatch_queue_t this_q = dispatch_get_current_queue();

	for (i = 0; i < COUNT; i++) {
		dispatch_group_async_f(g, this_q, NULL, work);
	}

	dispatch_group_async_f(g, this_q, NULL, node_done);

	//MU_MESSAGE("Spawned node %s", dispatch_queue_get_label(dispatch_get_current_queue()));
}
int main(void)
{
	test_start("Dispatch Suspend Timer");

	dispatch_queue_t main_q = dispatch_get_main_queue();
	test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue());

	__block int i = 0;
	__block int j = 0;

	dispatch_source_attr_t attr = dispatch_source_attr_create();
	test_ptr_notnull("dispatch_source_attr_create", attr);
	
	dispatch_source_attr_set_finalizer(attr, ^(dispatch_source_t ds) {
		test_ptr_notnull("finalizer ran", ds);
		if (ds == tweedledum) test_stop();
	});
Esempio n. 15
0
void exec_quip(SINGLE_QSP_ARG_DECL)
{
#ifdef USE_QS_QUEUE

	// This is iOS only!

	//dispatch_async_f(QS_QUEUE(THIS_QSP),qsp,exec_qs_cmds);

	if( QS_QUEUE(THIS_QSP) == dispatch_get_current_queue() ){
		exec_qs_cmds(THIS_QSP);
	} else {
		dispatch_async_f(QS_QUEUE(THIS_QSP),THIS_QSP,exec_qs_cmds);
	}

#else /* ! USE_QS_QUEUE */

	exec_qs_cmds(THIS_QSP);

#endif /* ! USE_QS_QUEUE */
}
int
main(void)
{
	dispatch_queue_t main_q;

	test_start("Dispatch Update Timer");

	main_q = dispatch_get_main_queue();
	test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue());
	
	timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, main_q);
	dispatch_source_set_timer(timer, 1000000000ull, 0, 0);
	dispatch_source_set_cancel_handler_f(timer, cancel_handler);
	dispatch_source_set_event_handler_f(timer, event_handler);
	test_ptr_notnull("dispatch_source_timer_create", timer);

	gettimeofday(&start_time, NULL);
	dispatch_resume(as_do(timer));

	dispatch_main();
}
Esempio n. 17
0
int main(void)
{
    test_start("Dispatch Update Timer");

    dispatch_queue_t main_q = dispatch_get_main_queue();
    test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue());

    __block int i = 0;
    struct timeval start_time;

    gettimeofday(&start_time, NULL);
    dispatch_source_attr_t attr = dispatch_source_attr_create();
    dispatch_source_attr_set_finalizer(attr, ^(dispatch_source_t ds) {
        struct timeval end_time;
        gettimeofday(&end_time, NULL);
        // Make sure we actually managed to adjust the interval
        // duration.  Seven one second ticks would blow past
        // this.
        test_long_less_than("total duration", end_time.tv_sec - start_time.tv_sec, 3);
        test_ptr_notnull("finalizer ran", ds);
        test_stop();
    });
int main(void)
{
	test_start("Dispatch Source Timer, bit 31");

	dispatch_queue_t main_q = dispatch_get_main_queue();
	test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue());

	__block int i = 0;
	struct timeval start_time;

	gettimeofday(&start_time, NULL);
	dispatch_source_attr_t attr = dispatch_source_attr_create();
	dispatch_source_attr_set_finalizer(attr, ^(dispatch_source_t ds) {
		struct timeval end_time;
		gettimeofday(&end_time, NULL);
		test_ptr_notnull("finalizer ran", ds);
		// XXX: check, s/b 2.0799... seconds, which is <4 seconds
		// when it could end on a bad boundry.
		test_long_less_than("needs to finish faster than 4 seconds", end_time.tv_sec - start_time.tv_sec, 4);
		// And it has to take at least two seconds...
		test_long_less_than("can't finish faster than 2 seconds", 1, end_time.tv_sec - start_time.tv_sec);
		test_stop();
	});
bool
dispatch_test_check_evfilt_read_for_fd(int fd)
{
#if HAS_SYS_EVENT_H
	int kq = kqueue();
	assert(kq != -1);
	struct kevent ke = {
		.ident = fd,
		.filter = EVFILT_READ,
		.flags = EV_ADD|EV_ENABLE,
	};
	struct timespec t = {
		.tv_sec = 1,
	};
	int r = kevent(kq, &ke, 1, &ke, 1, &t);
	close(kq);
	return r > 0;
#else
	struct pollfd pfd = {
		.fd = fd,
		.events = POLLIN,
	};
	int rc;
	do {
		rc = poll(&pfd, 1, 0);
	} while (rc == -1 && errno == EINTR);
	assert(rc != -1);
	return rc == 1;
#endif
}

void
_dispatch_test_current(const char* file, long line, const char* desc, dispatch_queue_t expected)
{
	dispatch_queue_t actual = dispatch_get_current_queue();
	_test_ptr(file, line, desc, actual, expected);
}
Esempio n. 20
0
bool
dispatch_test_check_evfilt_read_for_fd(int fd)
{
	int kq = kqueue();
	assert(kq != -1);
	struct kevent ke = {
		.ident = fd,
		.filter = EVFILT_READ,
		.flags = EV_ADD|EV_ENABLE,
	};
	struct timespec t = {
		.tv_sec = 1,
	};
	int r = kevent(kq, &ke, 1, &ke, 1, &t);
	close(kq);
	return r > 0;
}

void
_dispatch_test_current(const char* file, long line, const char* desc, dispatch_queue_t expected)
{
	dispatch_queue_t actual = dispatch_get_current_queue();
	_test_ptr(file, line, desc, actual, expected);
}
Esempio n. 21
0
static VALUE
rb_queue_get_current(VALUE klass, SEL sel)
{
    // TODO: check this to see if we need to retain it
    return rb_queue_from_dispatch(dispatch_get_current_queue(), false);
}
Esempio n. 22
0
void group_notify(void* data){
	dispatch_queue_t m = dispatch_get_main_queue();
	dispatch_queue_t c = dispatch_get_current_queue();
	MU_ASSERT_EQUAL(m, c);
	MU_PASS("Great!");
}