static gpointer
delayed_control (gpointer data)
{
  GstPoll *set = data;
  GstPollFD fd = GST_POLL_FD_INIT;

  fd.fd = 1;

  THREAD_START ();

  g_usleep (500000);

  gst_poll_add_fd (set, &fd);
  gst_poll_fd_ctl_write (set, &fd, TRUE);
  gst_poll_restart (set);

  THREAD_SYNCHRONIZE ();

  g_usleep (500000);

  gst_poll_add_fd (set, &fd);
  gst_poll_fd_ctl_write (set, &fd, TRUE);
  gst_poll_restart (set);

  return NULL;
}
Exemple #2
0
static gpointer
post_delayed_thread (gpointer data)
{
  THREAD_START ();
  send_5app_1el_1err_2app_messages (1 * G_USEC_PER_SEC);
  return NULL;
}
Exemple #3
0
int main(void)
{
    CLKPR = (1<<7);
    CLKPR = 0;

    /* Disable watchdog timer */
    MCUSR = 0;
    wdt_disable();

    /* Start the multi-threading kernel */
    init_kernel(STACK_MAIN);

    /* Timer */
    TCCR2B = 0x03;                   /* Pre-scaler for timer0 */
    TCCR2A = 1<<WGM21;               /* CTC mode */
    TIMSK2 = 1<<OCIE2A;              /* Interrupt on compare match */
    OCR2A  = (SCALED_F_CPU / 32 / 2400) - 1;

    TRACE_INIT;
    sei();
    t_stackErrorHandler(stackOverflow);
    fbuf_errorHandler(bufferOverflow);
    reset_params();

    /* HDLC and AFSK setup */
    mon_init(&cdc_outstr);
    adf7021_init();
    inframes  = hdlc_init_decoder( afsk_init_decoder() );
    outframes = hdlc_init_encoder( afsk_init_encoder() );
    digipeater_init();
    /* Activate digipeater in ui thread */

    /* USB */
    usb_init();
    THREAD_START(usbSerListener, STACK_USBLISTENER);

    ui_init();

    /* GPS and tracking */
    gps_init(&cdc_outstr);
    tracker_init();


    TRACE(1);
    while(1)
    {
        lbeep();
        if (t_is_idle()) {
            /* Enter idle mode or sleep mode here */
            powerdown_handler();
            sleep_mode();
        }
        else
            t_yield();
    }
}
Exemple #4
0
static void
start_threads_callback(evutil_socket_t fd, short what, void *arg)
{
	int i;

	for (i = 0; i < QUEUE_THREAD_COUNT; ++i) {
		THREAD_START(load_threads[i], load_deferred_queue,
				&deferred_data[i]);
	}
}
Exemple #5
0
static void
thread_link_unlink (gpointer data)
{
  THREAD_START ();

  while (THREAD_TEST_RUNNING ()) {
    gst_pad_link (src, sink);
    gst_pad_unlink (src, sink);
    THREAD_SWITCH ();
  }
}
static gpointer
delayed_flush (gpointer data)
{
  GstPoll *set = data;

  THREAD_START ();

  g_usleep (500000);
  gst_poll_set_flushing (set, TRUE);

  return NULL;
}
Exemple #7
0
void gps_init(Stream *outstr)
{
    cond_init(&wait_gps); 
    monitor_pos = monitor_raw = false; 
    uint16_t baud; 
    GET_PARAM(GPS_BAUD, &baud);
    in = uart_rx_init(baud, FALSE);
    out = outstr;
    THREAD_START(nmeaListener, STACK_GPSLISTENER);
    make_output(GPSON); 
    set_port(GPSON);
}
static void
thread_unref (GstMiniObject * mobj)
{
  int j;

  THREAD_START ();

  for (j = 0; j < refs_per_thread; ++j) {
    gst_mini_object_unref (mobj);

    if (j % num_threads == 0)
      THREAD_SWITCH ();
  }
}
static void
thread_buffer_producer (MyBufferPool * pool)
{
  int j;

  THREAD_START ();

  for (j = 0; j < recycle_buffer_count; ++j) {
    GstBuffer *buf = my_recycle_buffer_new (pool);
    gst_buffer_unref (buf);
  }

  pool->is_closed = TRUE;
}
Exemple #10
0
void usb_init()
{
    /* Initialize USB Subsystem */
    /* See makefile for mode constraints */
    USB_Init();
    sem_init(&cdc_run, 0);
    bcond_init(&usb_active, usb_con());

    STREAM_INIT( cdc_instr, CDC_BUF_SIZE);
    STREAM_INIT( cdc_outstr, CDC_BUF_SIZE);
    cdc_outstr.kick = NULL;

    THREAD_START(usb_thread, STACK_USB);
}
/* test thread-safe refcounting of GstMiniObject */
static void
thread_ref (GstMiniObject * mobj)
{
  int j;

  THREAD_START ();

  for (j = 0; j < refs_per_thread; ++j) {
    gst_mini_object_ref (mobj);

    if (j % num_threads == 0)
      THREAD_SWITCH ();
  }
  GST_DEBUG ("thread stopped");
}
static void
thread_buffer_consumer (MyBufferPool * pool)
{
  THREAD_START ();

  do {
    GstBuffer *buf;

    buf = my_buffer_pool_drain_one (pool);
    if (buf != NULL)
      my_recycle_buffer_destroy (MY_RECYCLE_BUFFER_CAST (buf));

    THREAD_SWITCH ();
  }
  while (!pool->is_closed);
}
Exemple #13
0
int CThread::Start()
{
	int status;
	THREAD_OBJ threadHandle;

	m_isRunning = true;

	// Here we start the thread. The entry point is the
	// run_internal() function, which on it's turn calls this->Run()
	THREAD_START(run_internal, this, threadHandle, m_SyncHandle, status);

	if (status != 0)
		m_isRunning = false;

	return status;
}
/* thread function for threaded default name change test */
static gpointer
thread_name_object_default (int *i)
{
  int j;

  THREAD_START ();

  for (j = *i; j < num_objects; j += num_threads) {
    GstObject *o = GST_OBJECT (g_list_nth_data (object_list, j));

    /* g_message ("THREAD %p: setting default name on object %d\n",
       g_thread_self (), j); */
    gst_object_set_name (o, NULL);
    THREAD_SWITCH ();
  }

  /* thread is done, so let's return */
  g_message ("THREAD %p: set name\n", g_thread_self ());
  g_free (i);

  return NULL;
}
Exemple #15
0
void mon_activate(bool m)
{ 
   /* Start if not on already */
   bool tstart = m && !mon_on;
   
   /* Stop if not stopped already */
   bool tstop = !m && mon_on;
   
   mon_on = m;
   FBQ* mq = (mon_on? &mon : NULL);
   hdlc_subscribe_rx(mq, 0);
   if (!mon_on || GET_BYTE_PARAM(TXMON_ON))
      hdlc_monitor_tx(mq);
   
   if (tstart) 
      THREAD_START(mon_thread, STACK_MONITOR);  
   if (tstop) {
      hdlc_monitor_tx(NULL);
      hdlc_subscribe_rx(NULL, 0);
      fbq_signal(&mon);
   }
}
static void
thread_no_events(void *arg)
{
	THREAD_T thread;
	struct basic_test_data *data = arg;
	struct timeval starttime, endtime;
	int i;
	exit_base = data->base;

	memset(times,0,sizeof(times));
	for (i=0;i<5;++i) {
		event_assign(&time_events[i], data->base,
		    -1, 0, note_time_cb, &times[i]);
	}

	evutil_gettimeofday(&starttime, NULL);
	THREAD_START(thread, register_events_subthread, data->base);
	event_base_loop(data->base, EVLOOP_NO_EXIT_ON_EMPTY);
	evutil_gettimeofday(&endtime, NULL);
	tt_assert(event_base_got_break(data->base));
	THREAD_JOIN(thread);
	for (i=0; i<5; ++i) {
		struct timeval diff;
		double sec;
		evutil_timersub(&times[i], &starttime, &diff);
		sec = diff.tv_sec + diff.tv_usec/1.0e6;
		TT_BLATHER(("event %d at %.4f seconds", i, sec));
	}
	test_timeval_diff_eq(&starttime, &times[0], 100);
	test_timeval_diff_eq(&starttime, &times[1], 200);
	test_timeval_diff_eq(&starttime, &times[2], 400);
	test_timeval_diff_eq(&starttime, &times[3], 450);
	test_timeval_diff_eq(&starttime, &times[4], 500);
	test_timeval_diff_eq(&starttime, &endtime,  500);

end:
	;
}
Exemple #17
0
/*[ Method --------------------------------------------------------------------

Name:
	ivThreadWnd::createThread

Description:
	Creates a new thread for handling window's message.

Exceptions:
	Throws IvtException if thread cannot be created.
	
Hazard Key:
	None

API:
	no

-----------------------------------------------------------------------------*/
BOOL ivThreadWnd::createThread()
/*] END Method */
{
	if (mhThread) return TRUE;

	// set up main thread for processing
	THREAD_START(mhThread, ThreadWnd_ServiceThread, this);

	if(!mhThread)
	{
		// THREAD_START() failed.
		return FALSE;
	}

	// wait for thread to be started (reports the thread id)
	while (!mThreadId)
	{
		// TBD: add timeout
		::Sleep(100);
	}

	return TRUE;
}
/* thread function for threaded name change test */
static gpointer
thread_name_object (GstObject * object)
{
  gchar *thread_id = g_strdup_printf ("%p", g_thread_self ());

  THREAD_START ();

  /* give main thread a head start */
  g_usleep (100000);

  /* write our name repeatedly */
  g_message ("THREAD %s: starting loop\n", thread_id);
  while (THREAD_TEST_RUNNING ()) {
    gst_object_set_name (object, thread_id);
    /* a minimal sleep invokes a thread switch */
    THREAD_SWITCH ();
  }

  /* thread is done, so let's return */
  g_message ("THREAD %s: set name\n", thread_id);
  g_free (thread_id);

  return NULL;
}
Exemple #19
0
static void
thread_conditions_simple(void *arg)
{
	struct timeval tv_signal, tv_timeout, tv_broadcast;
	struct alerted_record alerted[NUM_THREADS];
	THREAD_T threads[NUM_THREADS];
	struct cond_wait cond;
	int i;
	struct timeval launched_at;
	struct event wake_one;
	struct event wake_all;
	struct basic_test_data *data = arg;
	struct event_base *base = data->base;
	int n_timed_out=0, n_signal=0, n_broadcast=0;

	tv_signal.tv_sec = tv_timeout.tv_sec = tv_broadcast.tv_sec = 0;
	tv_signal.tv_usec = 30*1000;
	tv_timeout.tv_usec = 150*1000;
	tv_broadcast.tv_usec = 500*1000;

	EVTHREAD_ALLOC_LOCK(cond.lock, EVTHREAD_LOCKTYPE_RECURSIVE);
	EVTHREAD_ALLOC_COND(cond.cond);
	tt_assert(cond.lock);
	tt_assert(cond.cond);
	for (i = 0; i < NUM_THREADS; ++i) {
		memset(&alerted[i], 0, sizeof(struct alerted_record));
		alerted[i].cond = &cond;
	}

	/* Threads 5 and 6 will be allowed to time out */
	memcpy(&alerted[5].delay, &tv_timeout, sizeof(tv_timeout));
	memcpy(&alerted[6].delay, &tv_timeout, sizeof(tv_timeout));

	evtimer_assign(&wake_one, base, wake_one_timeout, &cond);
	evtimer_assign(&wake_all, base, wake_all_timeout, &cond);

	evutil_gettimeofday(&launched_at, NULL);

	/* Launch the threads... */
	for (i = 0; i < NUM_THREADS; ++i) {
		THREAD_START(threads[i], wait_for_condition, &alerted[i]);
	}

	/* Start the timers... */
	tt_int_op(event_add(&wake_one, &tv_signal), ==, 0);
	tt_int_op(event_add(&wake_all, &tv_broadcast), ==, 0);

	/* And run for a bit... */
	event_base_dispatch(base);

	/* And wait till the threads are done. */
	for (i = 0; i < NUM_THREADS; ++i)
		THREAD_JOIN(threads[i]);

	/* Now, let's see what happened. At least one of 5 or 6 should
	 * have timed out. */
	n_timed_out = alerted[5].timed_out + alerted[6].timed_out;
	tt_int_op(n_timed_out, >=, 1);
	tt_int_op(n_timed_out, <=, 2);

	for (i = 0; i < NUM_THREADS; ++i) {
		const struct timeval *target_delay;
		struct timeval target_time, actual_delay;
		if (alerted[i].timed_out) {
			TT_BLATHER(("%d looks like a timeout\n", i));
			target_delay = &tv_timeout;
			tt_assert(i == 5 || i == 6);
		} else if (evutil_timerisset(&alerted[i].alerted_at)) {
			long diff1,diff2;
			evutil_timersub(&alerted[i].alerted_at,
			    &launched_at, &actual_delay);
			diff1 = timeval_msec_diff(&actual_delay,
			    &tv_signal);
			diff2 = timeval_msec_diff(&actual_delay,
			    &tv_broadcast);
			if (abs(diff1) < abs(diff2)) {
				TT_BLATHER(("%d looks like a signal\n", i));
				target_delay = &tv_signal;
				++n_signal;
			} else {
				TT_BLATHER(("%d looks like a broadcast\n", i));
				target_delay = &tv_broadcast;
				++n_broadcast;
			}
		} else {
			TT_FAIL(("Thread %d never got woken", i));
			continue;
		}
		evutil_timeradd(target_delay, &launched_at, &target_time);
		test_timeval_diff_leq(&target_time, &alerted[i].alerted_at,
		    0, 50);
	}
	tt_int_op(n_broadcast + n_signal + n_timed_out, ==, NUM_THREADS);
	tt_int_op(n_signal, ==, 1);

end:
	;
}
Exemple #20
0
static void broadsheet_start_watchdog_thread(void)
{
    THREAD_START(broadsheet_watchdog_thread_id, &broadsheet_watchdog_thread_exit, broadsheet_watchdog_thread,
        BROADSHEET_WATCHDOG_THREAD_NAME);
}
Exemple #21
0
int main(int argc, char **argv)
{
    natsConnection      *conn  = NULL;
    natsOptions         *opts  = NULL;
    natsSubscription    *sub   = NULL;
    natsStatus          s      = NATS_OK;
    struct event_base   *evLoop= NULL;
    THREAD_T            pub;
    threadInfo          info;

    nats_Open(-1);

    opts = parseArgs(argc, argv, usage);

    printf("Sending %" PRId64 " messages to subject '%s'\n", total, subj);

    // One time initialization of things that we need.
    natsLibevent_Init();

    // Create a loop.
    evLoop = event_base_new();
    if (evLoop == NULL)
        s = NATS_ERR;

    // Indicate which loop and callbacks to use once connected.
    if (s == NATS_OK)
        s = natsOptions_SetEventLoop(opts, (void*) evLoop,
                                     natsLibevent_Attach,
                                     natsLibevent_Read,
                                     natsLibevent_Write,
                                     natsLibevent_Detach);

    if (s == NATS_OK)
        s = natsConnection_Connect(&conn, opts);

    if (s == NATS_OK)
        start = nats_Now();

    if (s == NATS_OK)
    {
        info.conn   = conn;
        info.status = NATS_OK;

        THREAD_START(pub, pubThread, (void*) &info);
    }

    if (s == NATS_OK)
    {
        event_base_dispatch(evLoop);

        THREAD_JOIN(pub);
        s = info.status;
    }

    if (s == NATS_OK)
    {
        printPerf("Sent", count, start, elapsed);
    }
    else
    {
        printf("Error: %d - %s\n", s, natsStatus_GetText(s));
        nats_PrintLastErrorStack(stderr);
    }

    // Destroy all our objects to avoid report of memory leak
    natsSubscription_Destroy(sub);
    natsConnection_Destroy(conn);
    natsOptions_Destroy(opts);

    if (evLoop != NULL)
        event_base_free(evLoop);

    // To silence reports of memory still in used with valgrind
    nats_Close();
    libevent_global_shutdown();

    return 0;
}