Ejemplo n.º 1
0
/*! 
  \brief The thread which pops stuff off the RTV queue and processes them
  \param data is the pointer to the queue to pop entries off of
  \returns NULL
  */
G_MODULE_EXPORT void *rtv_subscriber(gpointer data)
{
	GAsyncQueue *queue = (GAsyncQueue *)data;
	static GMutex *mutex = NULL;
	LibreEMS_Packet *packet = NULL;

	ENTER();
	mutex = (GMutex *)DATA_GET(global_data,"rtv_subscriber_mutex");
	if (!mutex)
		g_thread_exit(0);

	while (!DATA_GET(global_data,"rtv_subscriber_thread_exit"))
	{
		/* Wait up to 0.25 seconds for thread to exit */
		packet = (LibreEMS_Packet *)g_async_queue_timeout_pop(queue,250000);
		g_mutex_unlock(mutex);
		if (packet)
		{
			DATA_SET(global_data,"rt_goodread_count",GINT_TO_POINTER((GINT)DATA_GET(global_data,"rt_goodread_count")+1));
			process_rt_vars_f(packet->data+packet->payload_base_offset,packet->payload_length);
			libreems_packet_cleanup(packet);
		}
	}
	g_thread_exit(0);
	EXIT();
	return NULL;
}
Ejemplo n.º 2
0
/*!
  \brief This function is a thread that sits and listens on the packet_queue
  for incoming data that has come from handle_data() after passing basic
  validation.  This thread will call the dispatcher with the packet, which
  will fire off all appropriate subscribers to this packet
  \param data is unused
  \returns NULL
  */
void *packet_handler(gpointer data)
{
	GTimeVal tval;
	FreeEMS_Packet *packet = NULL;
	GAsyncQueue *queue = (GAsyncQueue *)DATA_GET(global_data,"packet_queue");
	GCond *cond = NULL;

	while(TRUE)
	{
		if ((DATA_GET(global_data,"leaving") || (DATA_GET(global_data,"packet_handler_thread_exit"))))
		{
			cond = (GCond *)DATA_GET(global_data,"packet_handler_cond");
			if (cond)
				g_cond_signal(cond);
                        g_thread_exit(0);
		}
		g_get_current_time(&tval);
		g_time_val_add(&tval,250000);
		packet = (FreeEMS_Packet *)g_async_queue_timed_pop(queue,&tval);
		if (packet)
			dispatch_packet_queues(packet);
	}
	g_thread_exit(0);
	return NULL;
}
Ejemplo n.º 3
0
/*!
  \brief Windows reader thread.  Runs continuously once port is open to a 
  working device. This is a strict timeout blocking read due to windows's
  absolutelybraindead I/O model where select/poll isn't allowed on anything
  but network sockets. Overallpaed I/O is just too ugly...
  \param data is the encapsulation of the port filedescriptor
  \returns NULL on termination
  */
void *win32_reader(gpointer data)
{
	gint fd = (GINT)data;
	gint errcount = 0;
	static gsize wanted = 2048;
	gboolean res = FALSE;
	gchar buf[2048];
	gchar *ptr = NULL;
	gsize requested = 2048;
	gssize received = 0;
	gsize read_pos = 0;
	GIOStatus status;
	GError *err = NULL;
	GCond *cond = NULL;

	ENTER();
	cond = (GCond *)DATA_GET(global_data,"serial_reader_cond");
	while (TRUE)
	{
		if ((DATA_GET(global_data,"leaving")) || (DATA_GET(global_data,"serial_abort")))
		{
			if (cond)
				g_cond_signal(cond);
			g_thread_exit(0);
		}
		read_pos = requested-wanted;
		received = read(fd, &buf[read_pos], wanted);
		g_usleep(10000);
		/*printf("Want %i, got %i,",wanted, received); */
		if (received == -1)
		{
			DATA_SET(global_data,"connected",GINT_TO_POINTER(FALSE));
			g_cond_signal(cond);
			g_thread_exit(0);
		}

		wanted -= received;
		/*	printf("Still need %i\n",wanted); */
		if (wanted <= 0)
			wanted = 2048;
		/*printf("WIN32 read %i bytes\n",received);*/
		if (received > 0)
			handle_data((guchar *)buf+read_pos,received);
		g_cond_signal(cond);
	}
	EXIT();
	return NULL;
}
Ejemplo n.º 4
0
gpointer worker_run(GSList* nodes) {
	/* get current thread's private worker object */
	Worker* worker = worker_getPrivate();

	/* continuously run all events for this worker's assigned nodes.
	 * the simulation is done when the engine is killed. */
	while(!engine_isKilled(worker->cached_engine)) {
		SimulationTime barrier = engine_getExecutionBarrier(worker->cached_engine);
		guint nEventsProcessed = 0;
		guint nNodesWithEvents = 0;

		GSList* item = nodes;
		while(item) {
			Node* node = item->data;
			guint n = _worker_processNode(worker, node, barrier);
			nEventsProcessed += n;
			if(n > 0) {
				nNodesWithEvents++;
			}
			item = g_slist_next(item);
		}

		engine_notifyProcessed(worker->cached_engine, nEventsProcessed, nNodesWithEvents);
	}

	/* free all applications before freeing any of the nodes since freeing
	 * applications may cause close() to get called on sockets which needs
	 * other node information.
	 */
	g_slist_foreach(nodes, (GFunc) node_stopAllApplications, NULL);
	g_slist_foreach(nodes, (GFunc) node_free, NULL);

	g_thread_exit(NULL);
	return NULL;
}
Ejemplo n.º 5
0
static gpointer stun_thread_func (const gpointer user_data)
{
  StunAgent oldagent;
  StunAgent newagent;
  int sock;
  int exit_code = -1;

  sock = listen_socket (IPPORT_STUN);

  if (sock == -1) {
    g_assert_not_reached ();
  }

  stun_agent_init (&oldagent, known_attributes,
      STUN_COMPATIBILITY_RFC3489, 0);
  stun_agent_init (&newagent, known_attributes,
      STUN_COMPATIBILITY_RFC5389, STUN_AGENT_USAGE_USE_FINGERPRINT);

  while (!exit_stun_thread) {
    g_debug ("Ready to process next datagram");
    dgram_process (sock, &oldagent, &newagent);
  }

  exit_code = close (sock);
  g_thread_exit (GINT_TO_POINTER (exit_code));
  return NULL;
}
static gpointer
server_in_background (BackgroundData *data)
{
	int    argc = data->argc;
	char **argv = data->argv;

	CORBA_Object servant = CORBA_OBJECT_NIL;
	
	CORBA_char filename[] = "calculator.ref";

	CORBA_Environment  ev[1];
	CORBA_exception_init(ev);
	
	server_init (&argc, argv, &global_orb, &default_poa, ev);
	etk_abort_if_exception(ev, "failed ORB init");

	servant = server_activate_service (global_orb, default_poa, ev);
	etk_abort_if_exception(ev, "failed activating service");

	g_print ("Writing service reference to: %s\n\n", filename);

	etk_export_object_to_file (global_orb, 
				   servant, 
				   filename, 
				   ev);
	etk_abort_if_exception(ev, "failed exporting IOR");
	
	server_run (global_orb, ev);
	etk_abort_if_exception(ev, "failed entering main loop");

	server_cleanup (global_orb, default_poa, servant, ev);
	etk_abort_if_exception(ev, "failed cleanup");

	g_thread_exit (NULL);
}
Ejemplo n.º 7
0
gpointer
idle_thread_func(gpointer user_data)
{
  PluginOption *option = ((ThreadData *)user_data)->option;
  int thread_index = ((ThreadData *)user_data)->index;

  int sock_type = SOCK_STREAM;

  if (sock_type_d)
    sock_type = SOCK_DGRAM;
  if (sock_type_s)
    sock_type = SOCK_STREAM;

  int fd;
  if (unix_socket_x)
    fd = connect_unix_domain_socket(sock_type, option->target);
  else
    fd = connect_ip_socket(sock_type, option->target, option->port, option->use_ipv6);

  if (fd<0)
    {
      ERROR("can not connect to %s:%s (%p)\n",option->target, option->port,g_thread_self());
    }
  else
    {
      DEBUG("(%d) connected to server on socket %d (%p)\n",thread_index,fd,g_thread_self());
    }

  g_mutex_lock(thread_lock);
  connect_finished++;

  if (connect_finished == active_thread_count + idle_thread_count)
    g_cond_broadcast(thread_connected);

  g_mutex_unlock(thread_lock);

  DEBUG("thread (%s,%p) created. wait for start ...\n",loggen_plugin_info.name,g_thread_self());
  g_mutex_lock(thread_lock);
  while (!thread_run)
    {
      g_cond_wait(thread_start,thread_lock);
    }
  g_mutex_unlock(thread_lock);

  DEBUG("thread (%s,%p) started. (r=%d,c=%d)\n",loggen_plugin_info.name,g_thread_self(),option->rate,
        option->number_of_messages);

  while (fd > 0 && thread_run && active_thread_count>0)
    {
      g_usleep(10*1000);
    }

  g_mutex_lock(thread_lock);
  idle_thread_count--;
  g_mutex_unlock(thread_lock);

  close(fd);
  g_thread_exit(NULL);
  return NULL;
}
Ejemplo n.º 8
0
static gpointer oh_event_thread_loop(gpointer data)
{
        GTimeVal time;
        SaErrorT rv;

	g_mutex_lock(oh_thread_mutex);
        while(oh_run_threaded()) {
		trace("Thread Harvesting events");
                rv = oh_harvest_events();
                if(rv != SA_OK) {
                        trace("Error on harvest of events.");
                }
                
		trace("Thread processing events");
                rv = oh_process_events();
                if(rv != SA_OK) {
                        trace("Error on processing of events, aborting");
                }
                
                trace("Thread processing hotswap");
                process_hotswap_policy();
                
                g_get_current_time(&time);
                g_time_val_add(&time, OH_THREAD_SLEEP_TIME);

                trace("Going to sleep");
                if (g_cond_timed_wait(oh_thread_wait, oh_thread_mutex, &time))
                        trace("SIGNALED: Got signal from plugin");
                else
                        trace("TIMEDOUT: Woke up, am looping again");
        }
	g_mutex_unlock(oh_thread_mutex);
        g_thread_exit(0);
        return data;
}
Ejemplo n.º 9
0
static gpointer oh_discovery_thread_loop(gpointer data)
{
        GTimeVal time;
        SaErrorT error = SA_OK;

        g_mutex_lock(oh_discovery_thread_mutex);
        while (1) {
                trace("Doing threaded discovery on all handlers");
                error = oh_domain_resource_discovery(0);
                if (error) {
                        trace("Got error on threaded discovery return.");
                }

                /* Let oh_wake_discovery_thread know this thread is done */
                g_cond_broadcast(oh_discovery_thread_wait);
                g_get_current_time(&time);
                g_time_val_add(&time, OH_DISCOVERY_THREAD_SLEEP_TIME);
                /* Go to sleep; let oh_wake_discovery_thread take the mutex */
                trace("Going to sleep");
                if (g_cond_timed_wait(oh_discovery_thread_wait,
                                      oh_discovery_thread_mutex, &time))
                        trace("SIGNALED: Got signal from saHpiDiscover()");
                else
                        trace("TIMEDOUT: Woke up, am doing discovery again");
        }
        g_mutex_unlock(oh_discovery_thread_mutex);
        g_thread_exit(0);

        return data;
}
Ejemplo n.º 10
0
static gpointer _get_data_threaded (GldiTask *pTask)
{
	g_mutex_lock (pTask->pMutex);
	_run_thread:  // at this point the mutex is locked, either by the first execution of this function, or by 'g_cond_wait'
	
	//\_______________________ get the data
	_set_elapsed_time (pTask);
	pTask->get_data (pTask->pSharedMemory);
	
	// and signal that data are ready to be processed.
	pTask->bNeedsUpdate = TRUE;  // this is only accessed by the update fonction, which is triggered just after, so no need to protect this variable.
	
	//\_______________________ call the update function from the main loop
	if (pTask->iSidUpdateIdle == 0)
		pTask->iSidUpdateIdle = g_idle_add ((GSourceFunc) _check_for_update_idle, pTask);  // note that 'iSidUpdateIdle' can actually be set after the 'update' is called. that's why the 'update' have to wait for the mutex to finish its job.
	
	// sleep until the next iteration or just leave.
	if (pTask->pCond)  // periodic task -> block until the condition becomes TRUE again.
	{
		pTask->bRunThread = FALSE;
		while (! pTask->bRunThread)
			g_cond_wait (pTask->pCond, pTask->pMutex);  // releases the mutex, then takes it again when awakening.
		if (g_atomic_int_get (&pTask->bDiscard) == 0)
			goto _run_thread;
	}
	g_mutex_unlock (pTask->pMutex);
	g_thread_exit (NULL);
	return NULL;
}
Ejemplo n.º 11
0
static void *
run_test (void *threadid)
{
  gint id = GPOINTER_TO_INT (threadid);

  while (TRUE) {
    if (id == 0) {
      gint res = gst_poll_wait (set, 10);

      if (res < 0) {
        g_print ("error %d %s\n", errno, g_strerror (errno));
      }
    } else {
      mess_some_more ();
      if (g_timer_elapsed (timer, NULL) > 0.5) {
        g_mutex_lock (fdlock);
        g_print ("active fds :%d\n", g_list_length (fds));
        g_timer_start (timer);
        g_mutex_unlock (fdlock);
      }
      g_usleep (1);
    }
  }

  g_thread_exit (NULL);
  return NULL;
}
Ejemplo n.º 12
0
static gpointer stun_thread_func (const gpointer user_data)
{
  StunAgent oldagent;
  StunAgent newagent;
  int sock = GPOINTER_TO_INT (user_data);
  int exit_code = -1;

  g_mutex_lock (stun_thread_mutex_ptr);
  g_cond_signal (stun_thread_signal_ptr);
  g_mutex_unlock (stun_thread_mutex_ptr);

  stun_agent_init (&oldagent, known_attributes,
      STUN_COMPATIBILITY_RFC3489, 0);
  stun_agent_init (&newagent, known_attributes,
      STUN_COMPATIBILITY_RFC5389, STUN_AGENT_USAGE_USE_FINGERPRINT);

  while (!exit_stun_thread) {
    g_debug ("Ready to process next datagram");
    dgram_process (sock, &oldagent, &newagent);
  }

  exit_code = close (sock);
  g_thread_exit (GINT_TO_POINTER (exit_code));
  return NULL;
}
Ejemplo n.º 13
0
static void *
run_test (void *user_data)
{
  gint threadid = GPOINTER_TO_INT (user_data);
  guint64 nb;
  GstBuffer *buf;
  GstClockTime start, end;

  g_mutex_lock (mutex);
  g_mutex_unlock (mutex);

  start = gst_util_get_timestamp ();

  g_assert (nbbuffers > 0);

  for (nb = nbbuffers; nb; nb--) {
    buf = gst_buffer_new ();
    gst_buffer_unref (buf);
  }

  end = gst_util_get_timestamp ();
  g_print ("total %" GST_TIME_FORMAT " - average %" GST_TIME_FORMAT
      "  - Thread %d\n", GST_TIME_ARGS (end - start),
      GST_TIME_ARGS ((end - start) / nbbuffers), threadid);


  g_thread_exit (NULL);
  return NULL;
}
Ejemplo n.º 14
0
gpointer upload(gpointer arg)
{
#if 0
    gtk_widget_hide(mtp_submenu_item_free);
#endif
    if(!mutex)
    {
#if 0
        gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(mtp_submenu_item_up))),UP_DEFAULT_LABEL);
        gtk_widget_set_sensitive(mtp_submenu_item_up, TRUE);
#endif
        return NULL;
    }
    g_mutex_lock(mutex);
    if(!mtp_device)
    {
#if 0
        gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(mtp_submenu_item_up))),UP_DEFAULT_LABEL);
        gtk_widget_set_sensitive(mtp_submenu_item_up, TRUE);
#endif
        g_mutex_unlock(mutex);
        return NULL;
    }

    Tuple* tuple;
    GList *up_list=NULL,*node;
    node=up_list=get_upload_list();
    gint up_err=0;
    while(node)
    {
        tuple=(Tuple*)(node->data);
        up_err = upload_file(tuple);
        if(up_err )
        {
            /*show_dialog("An error has occured while uploading...\nUpload failed!");*/
            break;
        }
        if(exiting)
        {
            /*show_dialog("Shutting down MTP while uploading.\nPending uploads were cancelled");*/
            break;
        }

        node = g_list_next(node);
    }
    g_list_free(up_list);
#if 0
    gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(mtp_submenu_item_up))),UP_DEFAULT_LABEL);
    gtk_widget_set_sensitive(mtp_submenu_item_up, TRUE);
#endif
    g_mutex_unlock(mutex);
#if DEBUG
    g_print("MTP upload process finished\n");
#endif
#if 0
    gtk_widget_show(mtp_submenu_item_free);
#endif
    g_thread_exit(NULL);
    return NULL;
}
void mmsvc_core_worker_exit(Client client)
{
	LOGD("Enter");
	if (!client) {
		LOGE("Error - null client");
		return;
	}

	mmsvc_core_connection_close(client->ch[MUSED_CHANNEL_MSG].fd);
	mmsvc_core_connection_close(client->ch[MUSED_CHANNEL_DATA].fd);
	if (!client->ch[MUSED_CHANNEL_MSG].p_gthread) {
		LOGE("Error - null p_gthread");
		return;
	}
	LOGD("%p thread exit\n", client->ch[MUSED_CHANNEL_MSG].p_gthread);
	g_thread_unref(client->ch[MUSED_CHANNEL_MSG].p_gthread);

	if (client->ch[MUSED_CHANNEL_DATA].p_gthread)
		g_thread_unref(client->ch[MUSED_CHANNEL_DATA].p_gthread);
	MMSVC_FREE(client);

	mmsvc_core_config_get_instance()->free();

	LOGD("Leave");
	g_thread_exit(NULL);
}
Ejemplo n.º 16
0
/*
 *  _thread_handle_signals()
 *
 *  Trap linux signals for the whole multi-threaded application.
 *
 *  Params:
 *    main_loop  -- closing this shuts down the app orderly
 *
 *  Returns/Affects:
 *      returns and/or set the atomic gint gd_flag_exit
 *      returns last signal
*/
static gpointer  _thread_handle_signals(gpointer main_loop)
{
	sigset_t signal_set;
	siginfo_t signal_info;
	gint    sig = 0;
	gint   rval = 0;

	sigfillset (&signal_set);
	g_debug("signal handler: startup successful");

	while (g_atomic_int_get(&gd_flag_exit)) {
		/* wait for any and all signals */
		sig = sigwaitinfo (&signal_set, &signal_info);
		if (!sig) {
			g_message("signal handler: sigwaitinfo() returned an error => {%s}",
				g_strerror(errno));
			continue;
		}
		/* when we get this far, we've  caught a signal */
		rval = _process_signals ( &signal_info );
		g_atomic_int_set(&gd_flag_exit, rval);

	} /* end-while */

	g_main_loop_quit(main_loop);

	pthread_sigmask (SIG_UNBLOCK, &signal_set, NULL);

	g_debug("signal handler: shutdown complete");

	g_thread_exit ( GINT_TO_POINTER(sig) );

	return (NULL);
}
Ejemplo n.º 17
0
/* Progress bar implementation */
static void* progress_bar(void *unused)
{
	GTimeVal	time;
	char		buf[PROGRESS_BUF_SIZE], A[20];
	int		i = 0, t = 0, len, mes_len;

	memset(buf, 0, PROGRESS_BUF_SIZE);
	mes_len = strlen(progress_mes);
	while (in_progress) {
		snprintf(A, 10, " %d.%d s ", t / 10, t % 10);
		len = strlen(A);
		memset(buf + mes_len, '.', i);
		strncpy(buf, progress_mes, mes_len);
		if (i > 8)
			strncpy(buf + mes_len + (i - len) / 2, A, len);
		printf("%s\r", buf);
		fflush(stdout);
		g_get_current_time(&time);
		g_time_val_add(&time, G_USEC_PER_SEC / 10);
		g_cond_timed_wait(thread_wait, thread_mutex, &time);
		if (i < (PROGRESS_BUF_SIZE - mes_len - 1)) i++;
		t++;
	};
        g_thread_exit(0);
	return (void *)1;
}
Ejemplo n.º 18
0
/**
 * Function to optimize on a thread.
 *
 * \return NULL.
 */
static void *
optimize_thread (ParallelData * data)   ///< Function data.
{
  unsigned int i, thread;
  double e;
#if DEBUG_OPTIMIZE
  fprintf (stderr, "optimize_thread: start\n");
#endif
  thread = data->thread;
#if DEBUG_OPTIMIZE
  fprintf (stderr, "optimize_thread: thread=%u start=%u end=%u\n", thread,
           optimize->thread[thread], optimize->thread[thread + 1]);
#endif
  for (i = optimize->thread[thread]; i < optimize->thread[thread + 1]; ++i)
    {
      e = optimize_norm (i);
      g_mutex_lock (mutex);
      optimize_best (i, e);
      optimize_save_variables (i, e);
      if (e < optimize->threshold)
        optimize->stop = 1;
      g_mutex_unlock (mutex);
      if (optimize->stop)
        break;
#if DEBUG_OPTIMIZE
      fprintf (stderr, "optimize_thread: i=%u e=%lg\n", i, e);
#endif
    }
#if DEBUG_OPTIMIZE
  fprintf (stderr, "optimize_thread: end\n");
#endif
  g_thread_exit (NULL);
  return NULL;
}
Ejemplo n.º 19
0
static void
main_loop_thread  ()
{
  _mb_global_data.loop = g_main_loop_new (NULL, FALSE);
  g_main_loop_run (_mb_global_data.loop);
  g_thread_exit (0);
}
Ejemplo n.º 20
0
static gpointer oh_event_thread_loop(gpointer data)
{
        GTimeVal time;
        SaErrorT error = SA_OK;
        static int first_loop = 1;

        g_mutex_lock(oh_event_thread_mutex);
        while (1) {
                /* Give the discovery time to start first -> FIXME */
                if (first_loop) {
                        struct timespec sleepytime =
                                { .tv_sec = 0, .tv_nsec = 500000000};
                        first_loop = 0;
                        nanosleep(&sleepytime, NULL);
                }

                trace("Thread Harvesting events");

                error = oh_harvest_events();
                if (error != SA_OK) dbg("Error on harvest of events.");

                trace("Thread processing events");
                error = oh_process_events();
                if (error != SA_OK) dbg("Error on processing of events.");

                /* Let oh_wake_event_thread know this thread is done */
                g_cond_broadcast(oh_event_thread_wait);
                g_get_current_time(&time);
                g_time_val_add(&time, OH_EVENT_THREAD_SLEEP_TIME);
                trace("Going to sleep");
                if (g_cond_timed_wait(oh_event_thread_wait, oh_event_thread_mutex, &time))
                        trace("SIGNALED: Got signal from plugin");
                else
                        trace("TIMEDOUT: Woke up, am looping again");
        }
        g_mutex_unlock(oh_event_thread_mutex);
        g_thread_exit(0);

        return data;
}

int oh_threaded_init()
{
        int error = 0;

        trace("Attempting to init event");
        if (!g_thread_supported()) {
                trace("Initializing thread support");
                g_thread_init(NULL);
        } else {
                trace("Already supporting threads");
        }

        error = oh_discovery_init();
        if (oh_event_init() || error) error = 1;

        return error;
}
Ejemplo n.º 21
0
static gpointer thd2(gpointer data)
{
    arg_t *arg = data;

    get_ble_tree(2, arg->mac, arg->file_path);

    g_thread_exit(0);
    return NULL;
}
Ejemplo n.º 22
0
static gpointer run_main_loop(gpointer data)
{
	while (running)
		g_main_context_iteration(ctx, TRUE);

	g_thread_exit(NULL);

	return NULL;
}
Ejemplo n.º 23
0
static gpointer
enable_ctx_thread (gpointer user_data)
{
    if ( !XRecordEnableContext (grab_info->data_disp, grab_info->context,
                                grab_key_event_cb, NULL) ) {
        g_warning ("Unable to enable context...");
        grab_xrecord_finalize ();
    }

    g_thread_exit (NULL);
}
Ejemplo n.º 24
0
/**
 * glk_exit:
 *
 * If you want to shut down your program in the middle of your `glk_main()`
 * function, you can call glk_exit().
 *
 * This function does not return.
 *
 * If you print some text to a window and then shut down your program, you can
 * assume that the player will be able to read it. Most likely the Glk library
 * will give a “`Hit any key to exit`” prompt.
 * (There are other possiblities, however.
 * A terminal-window version of Glk might simply exit and leave the last screen
 * state visible in the terminal window.)
 *
 * <note><para>
 * You should only shut down your program with glk_exit() or by returning from
 * your <function>glk_main()</function> function. If you call the ANSI
 * <function>exit()</function> function, bad things may happen. Some versions of
 * the Glk library may be designed for multiple sessions, for example, and you
 * would be cutting off all the sessions instead of just yours. You would
 * probably also prevent final text from being visible to the player.
 * </para></note>
 *
 * > # Chimara #
 * > If there are any windows open at the time glk_exit() is called, then
 * > Chimara will leave them open.
 * > This way, the final text remains visible.
 * > Note that bad things most definitely <emphasis>will</emphasis> happen if
 * > you use the ANSI `exit()`.
 */
void
glk_exit(void)
{
    ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key);

    shutdown_glk_pre();

    /* Find the biggest text buffer window */
    winid_t win, largewin = NULL;
    glui32 largearea = 0;
    for(win = glk_window_iterate(NULL, NULL); win; win = glk_window_iterate(win, NULL)) {
        if(win->type == wintype_TextBuffer) {
            glui32 w, h;
            if(!largewin) {
                largewin = win;
                glk_window_get_size(largewin, &w, &h);
                largearea = w * h;
            } else {
                glk_window_get_size(win, &w, &h);
                if(w * h > largearea) {
                    largewin = win;
                    largearea = w * h;
                }
            }
        }
    }
    if(largewin) {
        glk_set_window(largewin);
        glk_set_style(style_Alert);
        glk_put_string("\n");
        glk_put_string(glk_data->final_message);
        glk_put_string("\n");
        flush_window_buffer(largewin);
    }

    /* Wait for a keypress if any text grid or buffer windows are open */
    gboolean should_wait = FALSE;
    g_mutex_lock(&glk_data->shutdown_lock);
    for(win = glk_window_iterate(NULL, NULL); win; win = glk_window_iterate(win, NULL)) {
        if(win->type == wintype_TextGrid || win->type == wintype_TextBuffer) {
            g_signal_handler_unblock(win->widget, win->shutdown_keypress_handler);
            should_wait = TRUE;
        }
    }
    if (should_wait)
        g_cond_wait(&glk_data->shutdown_key_pressed, &glk_data->shutdown_lock);
    g_mutex_unlock(&glk_data->shutdown_lock);

    shutdown_glk_post();

    gdk_threads_add_idle((GSourceFunc)emit_stopped_signal, glk_data->self);

    g_thread_exit(NULL);
}
Ejemplo n.º 25
0
static void
gimp_fonts_load_thread (GimpFontsLoadFuncData *data)
{
  gimp_fonts_load_func (data->config);

  g_mutex_lock (&data->mutex);
  data->caching_complete = TRUE;
  g_cond_signal (&data->cond);
  g_mutex_unlock (&data->mutex);

  g_thread_exit (0);
}
Ejemplo n.º 26
0
static gpointer testServerMonitorThreadFunc(gpointer)
{
    // Wait for the specified timeout to happen.
    g_usleep(gMaxWaitForChild * G_USEC_PER_SEC);

    // Kill the child process if not ready yet.
    if (!gChildIsReady)
        stopTestServer();

    g_thread_exit(0);
    return 0;
}
Ejemplo n.º 27
0
/*
 * Event loop thread
 */
static gpointer _event_thread(gpointer data)
{
  printf_dbg("Event loop START\n");
  g_mutex_lock(cb_mutex);
  event_loop = g_main_loop_new(NULL, FALSE);
  g_mutex_unlock(cb_mutex);
  g_main_loop_run(event_loop);
  g_main_loop_unref(event_loop);
  event_loop = NULL;
  printf_dbg("Event loop EXIT\n");
  g_thread_exit(0);
  return 0;
}
Ejemplo n.º 28
0
static gpointer
rejilla_checksum_files_thread (gpointer data)
{
	GError *error = NULL;
	RejillaJobAction action;
	RejillaChecksumFiles *self;
	RejillaTrack *current = NULL;
	RejillaChecksumFilesPrivate *priv;
	RejillaChecksumFilesThreadCtx *ctx;
	RejillaBurnResult result = REJILLA_BURN_NOT_SUPPORTED;

	self = REJILLA_CHECKSUM_FILES (data);
	priv = REJILLA_CHECKSUM_FILES_PRIVATE (self);

	/* check DISC types and add checksums for DATA and IMAGE-bin types */
	rejilla_job_get_action (REJILLA_JOB (self), &action);
	rejilla_job_get_current_track (REJILLA_JOB (self), &current);
	if (action == REJILLA_JOB_ACTION_CHECKSUM) {
		priv->checksum_type = rejilla_track_get_checksum_type (current);
		if (priv->checksum_type & (REJILLA_CHECKSUM_MD5_FILE|REJILLA_CHECKSUM_SHA1_FILE|REJILLA_CHECKSUM_SHA256_FILE|REJILLA_CHECKSUM_DETECT))
			result = rejilla_checksum_files_check_files (self, &error);
		else
			result = REJILLA_BURN_ERR;
	}
	else if (action == REJILLA_JOB_ACTION_IMAGE) {
		if (REJILLA_IS_TRACK_DATA (current))
			result = rejilla_checksum_files_create_checksum (self, &error);
		else
			result = REJILLA_BURN_ERR;
	}

	if (result != REJILLA_BURN_CANCEL) {
		ctx = g_new0 (RejillaChecksumFilesThreadCtx, 1);
		ctx->sum = self;
		ctx->error = error;
		ctx->result = result;
		priv->end_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE,
						rejilla_checksum_files_end,
						ctx,
						rejilla_checksum_files_destroy);
	}

	/* End thread */
	g_mutex_lock (priv->mutex);
	priv->thread = NULL;
	g_cond_signal (priv->cond);
	g_mutex_unlock (priv->mutex);

	g_thread_exit (NULL);
	return NULL;
}
Ejemplo n.º 29
0
gpointer
start_single_dcp_thread(gpointer _thread_info)
{
	ThreadInfo* t = _thread_info;
	RS_IMAGE16 *tmp = t->tmp;

	pre_cache_tables(t->dcp);
	if (tmp->pixelsize == 4  && (rs_detect_cpu_features() & RS_CPU_FLAG_SSE2) && !t->dcp->read_out_curve)
	{
		if ((rs_detect_cpu_features() & RS_CPU_FLAG_AVX) && render_AVX(t))
		{
			/* AVX routine renders 4 pixels in parallel, but any remaining must be */
			/* calculated using C routines */
			if (tmp->w & 3)
			{
				t->start_x = tmp->w - (tmp->w & 3);
				render(t);
			}
		} 
		else if ((rs_detect_cpu_features() & RS_CPU_FLAG_SSE4_1) && render_SSE4(t))
		{
			/* SSE4 routine renders 4 pixels in parallel, but any remaining must be */
			/* calculated using C routines */
			if (tmp->w & 3)
			{
				t->start_x = tmp->w - (tmp->w & 3);
				render(t);
			}
		} 
		else if (render_SSE2(t))
		{
			/* SSE2 routine renders 4 pixels in parallel, but any remaining must be */
			/* calculated using C routines */
			if (tmp->w & 3)
			{
				t->start_x = tmp->w - (tmp->w & 3);
				render(t);
			}
		} else {
			/* Not SSE2 compiled, render using plain C */
			render(t);
		}
	}
	else
		render(t);

	if (!t->single_thread)
		g_thread_exit(NULL);

	return NULL; /* Make the compiler shut up - we'll never return */
}
Ejemplo n.º 30
0
static void check_afc(gpointer data)
{
    //prepare a buffer
    unsigned int buffersize = BUFFER_SIZE * sizeof(unsigned int);
    int *buf = (int *) malloc(buffersize);
    int *buf2 = (int *) malloc(buffersize);
    unsigned int bytes = 0;
    uint64_t position = 0;

    //fill buffer
    int i = 0;
    for (i = 0; i < BUFFER_SIZE; i++) {
        buf[i] = ((param *) data)->id * i;
    }

    //now  writes buffer on device
    uint64_t file = 0;
    char path[50];
    sprintf(path, "/Buf%i", ((param *) data)->id);
    afc_file_open(((param *) data)->afc, path, AFC_FOPEN_RW, &file);
    afc_file_write(((param *) data)->afc, file, (char *) buf, buffersize, &bytes);
    afc_file_close(((param *) data)->afc, file);
    file = 0;
    if (bytes != buffersize)
        printf("Write operation failed\n");

    //now read it
    bytes = 0;
    afc_file_open(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file);
    afc_file_read(((param *) data)->afc, file, (char *) buf2, buffersize/2, &bytes);
    afc_file_read(((param *) data)->afc, file, (char *) buf2 + (buffersize/2), buffersize/2, &bytes);
    if(AFC_E_SUCCESS != afc_file_tell(((param *) data)->afc, file, &position))
        printf("Tell operation failed\n");
    afc_file_close(((param *) data)->afc, file);
    if (position != buffersize)
        printf("Read operation failed\n");

    //compare buffers
    for (i = 0; i < BUFFER_SIZE; i++) {
        if (buf[i] != buf2[i]) {
            printf("Buffers are differents, stream corrupted\n");
            break;
        }
    }

    //cleanup
    afc_remove_path(((param *) data)->afc, path);
    g_thread_exit(0);
}