Beispiel #1
0
static void 
mdw_dvb_demux_thread_read_write_finalize(MdwDvbDemux *self) 
{
    g_assert(self != NULL);
    MdwDvbDemuxPrivate *priv = MDW_DVB_DEMUX_GET_PRIVATE(self);
    if (priv->thread_read_write == NULL) 
    {
        return;
    } 
    DEBUG_INFO("Finalizing thread to read/write");
    g_assert(priv->main_queue != NULL);
    g_assert(priv->thread_read_write_queue != NULL);

    MdwMessage *m = mdw_message_new(MDW_MESSAGE_TYPE_FINALIZE, 0);
    mdw_message_put(m, priv->thread_read_write_queue);
    
    m = mdw_message_get(priv->main_queue, TRUE);
    g_assert(m->type == MDW_MESSAGE_TYPE_FINALIZED);
    g_assert(m->buffer == NULL);
    g_assert(m->size == 0);
    mdw_message_free(m, TRUE);

    g_assert(g_async_queue_length(priv->main_queue) == 0);
    g_assert(g_async_queue_length(priv->thread_read_write_queue) == 0);

    g_async_queue_unref(priv->main_queue);
    g_async_queue_unref(priv->thread_read_write_queue);

    priv->main_queue = NULL;
    priv->thread_read_write_queue = NULL;
    priv->thread_read_write = NULL;

}
Beispiel #2
0
static void
arv_stream_finalize (GObject *object)
{
	ArvStream *stream = ARV_STREAM (object);
	ArvBuffer *buffer;

	arv_debug_stream ("[Stream::finalize] Flush %d buffer[s] in input queue",
			  g_async_queue_length (stream->priv->input_queue));
	arv_debug_stream ("[Stream::finalize] Flush %d buffer[s] in output queue",
			  g_async_queue_length (stream->priv->output_queue));

	do {
		buffer = g_async_queue_try_pop (stream->priv->output_queue);
		if (buffer != NULL)
			g_object_unref (buffer);
	} while (buffer != NULL);

	do {
		buffer = g_async_queue_try_pop (stream->priv->input_queue);
		if (buffer != NULL)
			g_object_unref (buffer);
	} while (buffer != NULL);

	g_async_queue_unref (stream->priv->input_queue);
	g_async_queue_unref (stream->priv->output_queue);

	parent_class->finalize (object);
}
void
gst_vaapi_decoder_finalize (GstVaapiDecoder * decoder)
{
  const GstVaapiDecoderClass *const klass =
      GST_VAAPI_DECODER_GET_CLASS (decoder);

  if (klass->destroy)
    klass->destroy (decoder);

  gst_video_codec_state_unref (decoder->codec_state);
  decoder->codec_state = NULL;

  parser_state_finalize (&decoder->parser_state);

  if (decoder->buffers) {
    g_async_queue_unref (decoder->buffers);
    decoder->buffers = NULL;
  }

  if (decoder->frames) {
    g_async_queue_unref (decoder->frames);
    decoder->frames = NULL;
  }

  gst_vaapi_object_replace (&decoder->context, NULL);
  decoder->va_context = VA_INVALID_ID;

  gst_vaapi_display_replace (&decoder->display, NULL);
  decoder->va_display = NULL;
}
Beispiel #4
0
G_MODULE_EXPORT gchar * request_interface_version(gint *len)
{
	OutputData *output = NULL;
	GAsyncQueue *queue = NULL;
	FreeEMS_Packet *packet = NULL;
	gchar *version = NULL;
	GTimeVal tval;
	Serial_Params *serial_params = NULL;
	guint8 *buf = NULL;
	/* Raw packet */
	guint8 pkt[INTVER_REQ_PKT_LEN];
	gint res = 0;
	gint i = 0;
	guint8 sum = 0;
	gint tmit_len = 0;

	serial_params = DATA_GET(global_data,"serial_params");
	g_return_val_if_fail(serial_params,NULL);

	if (DATA_GET(global_data,"offline"))
		return g_strdup("Offline");

	pkt[HEADER_IDX] = 0;
	pkt[H_PAYLOAD_IDX] = (REQUEST_INTERFACE_VERSION & 0xff00 ) >> 8;
	pkt[L_PAYLOAD_IDX] = (REQUEST_INTERFACE_VERSION & 0x00ff );
	for (i=0;i<INTVER_REQ_PKT_LEN-1;i++)
		sum += pkt[i];
	pkt[INTVER_REQ_PKT_LEN-1] = sum;
	buf = finalize_packet((guint8 *)&pkt,INTVER_REQ_PKT_LEN,&tmit_len);
	queue = g_async_queue_new();
	register_packet_queue(PAYLOAD_ID,queue,RESPONSE_INTERFACE_VERSION);
	if (!write_wrapper_f(serial_params->fd,buf, tmit_len, NULL))
	{
		deregister_packet_queue(PAYLOAD_ID,queue,RESPONSE_INTERFACE_VERSION);
		g_free(buf);
		g_async_queue_unref(queue);
		return NULL;
	}
	g_free(buf);
	g_get_current_time(&tval);
	g_time_val_add(&tval,500000);
	packet = g_async_queue_timed_pop(queue,&tval);
	deregister_packet_queue(PAYLOAD_ID,queue,RESPONSE_INTERFACE_VERSION);
	g_async_queue_unref(queue);
	/*
	   if (packet)
	   printf("Firmware version PACKET ARRIVED!\n");
	   else
	   printf("TIMEOUT\n");
	 */

	if (packet)
	{
		version = g_strndup((const gchar *)(packet->data+packet->payload_base_offset),packet->payload_length);
		if (len)
			*len = packet->payload_length;
		freeems_packet_cleanup(packet);
	}
	return version;
}
Beispiel #5
0
/*
 \brief This dispatches out packets to awaiting subscribers (if any)
 If the payload or sequnce number matches what's in the packet, this packet
 is copied and pushed down the supplied queue to the lucky winner. This allows
 multiple subscribers per payloadID or sequence number, which offers some
 interesting flexibility
 \param packet is a pointer to the new packet
 \see FreeEMS_Packet
 */
G_MODULE_EXPORT void dispatch_packet_queues(FreeEMS_Packet *packet)
{
	static GHashTable *payloads = NULL;
	static GHashTable *sequences = NULL;
	static GMutex *mutex = NULL;
	GAsyncQueue *queue = NULL;
	guint8 header = packet->data[0];
	guint i = 0;
	GList *list = NULL;

	if (!mutex)
		mutex = (GMutex *)DATA_GET(global_data,"queue_mutex");
	if (!payloads)
		payloads = (GHashTable *)DATA_GET(global_data,"payload_id_queue_hash");
	if (!sequences)
		sequences = (GHashTable *)DATA_GET(global_data,"sequence_num_queue_hash");

	g_return_if_fail(mutex);
	g_mutex_lock(mutex);
	/* If sequence set, look for it and dispatch if found */
	if ((sequences) && ((packet->header_bits & HAS_SEQUENCE_MASK) > 0))
	{
		list = (GList *)g_hash_table_lookup(sequences,GINT_TO_POINTER((GINT)packet->seq_num));
		if (list)
		{
			for (i=0;i<g_list_length(list);i++)
			{
				queue = (GAsyncQueue *)g_list_nth_data(list,i);
				if (queue)
				{
					g_async_queue_ref(queue);
					g_async_queue_push(queue,(gpointer)packet_deep_copy(packet));
					g_async_queue_unref(queue);
				}
			}
		}
	}
	if (payloads)
	{
		/* If payload ID matches, dispatch if found */
		list = (GList *)g_hash_table_lookup(payloads,GINT_TO_POINTER((GINT)packet->payload_id));
		if (list)
		{
			for (i=0;i<g_list_length(list);i++)
			{
				queue = (GAsyncQueue *)g_list_nth_data(list,i);
				if (queue)
				{
					g_async_queue_ref(queue);
					g_async_queue_push(queue,(gpointer)packet_deep_copy(packet));
					g_async_queue_unref(queue);
				}
			}
		}
	}
	g_mutex_unlock(mutex);
	freeems_packet_cleanup(packet);
}
Beispiel #6
0
void
network_server_clean(struct network_server_s *srv)
{
	if (!srv)
		return;

	if (srv->thread_events != NULL) {
		GRID_WARN("EventThread not joined!");
		g_error("EventThread not joined!");
	}
	if (srv->thread_first_worker) {
		GRID_WARN("FirstThread not joined!");
		g_error("FirstThread not joined!");
	}

	g_mutex_clear(&srv->lock_threads);

	network_server_close_servers(srv);

	if (srv->endpointv) {
		struct endpoint_s **u;
		for (u=srv->endpointv; *u ;u++)
			g_free(*u);
		g_free(srv->endpointv);
	}

	if (srv->stats) {
		grid_stats_holder_clean(srv->stats);
	}

	metautils_pclose(&(srv->wakeup[0]));
	metautils_pclose(&(srv->wakeup[1]));

	if (srv->queue_monitor) {
		g_async_queue_unref(srv->queue_monitor);
		srv->queue_monitor = NULL;
	}

	if (srv->queue_events) {
		g_async_queue_unref(srv->queue_events);
		srv->queue_events = NULL;
	}

	if (srv->workers_active_1) {
		grid_single_rrd_destroy(srv->workers_active_1);
		srv->workers_active_1 = NULL;
	}
	if (srv->workers_active_60) {
		grid_single_rrd_destroy(srv->workers_active_60);
		srv->workers_active_60 = NULL;
	}

	g_free(srv);
}
Beispiel #7
0
/* Internal function: do any Glk-thread cleanup for shutting down the Glk library. */
void
shutdown_glk_post(void)
{
	ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key);

	/* Free all opaque objects; can't iterate normally, because the objects are
	 being removed from the global iteration lists */
	if(glk_data->root_window)
		glk_window_close(glk_data->root_window->data, NULL);
	g_assert(glk_data->root_window == NULL);
	strid_t str;
	while( (str = glk_stream_iterate(NULL, NULL)) )
		glk_stream_close(str, NULL);
	frefid_t fref;
	while( (fref = glk_fileref_iterate(NULL, NULL)) )
		glk_fileref_destroy(fref);
	schanid_t sch;
	while( (sch = glk_schannel_iterate(NULL, NULL)) )
		glk_schannel_destroy(sch);
	
	/* Empty the event queue */
	g_mutex_lock(&glk_data->event_lock);
	g_queue_foreach(glk_data->event_queue, (GFunc)g_free, NULL);
	g_queue_clear(glk_data->event_queue);
	g_mutex_unlock(&glk_data->event_lock);

	/* Reset the abort signaling mechanism */
	g_mutex_lock(&glk_data->abort_lock);
	glk_data->abort_signalled = FALSE;
	g_mutex_unlock(&glk_data->abort_lock);

	/* Reset arrangement mechanism */
	g_mutex_lock(&glk_data->arrange_lock);
	glk_data->needs_rearrange = FALSE;
	glk_data->ignore_next_arrange_event = FALSE;
	g_mutex_unlock(&glk_data->arrange_lock);

	/* Unref input queues (they are not destroyed because the main thread stil holds a ref */
	g_async_queue_unref(glk_data->char_input_queue);
	g_async_queue_unref(glk_data->line_input_queue);

	/* Reset other stuff */
	glk_data->interrupt_handler = NULL;
	g_free(glk_data->current_dir);
	glk_data->current_dir = NULL;
	/* Remove the dispatch callbacks */
	glk_data->register_obj = NULL;
	glk_data->unregister_obj = NULL;
	glk_data->register_arr = NULL;
	glk_data->unregister_arr = NULL;
}
int main(int argc, char *argv[])
{
    guint n_threads = 10;
    guint n;

    struct configuration conf= { NULL, NULL, NULL, 0 };

    GThread **threads = g_new(GThread*, n_threads);
    struct thread_data* td = g_new(struct thread_data, n_threads);

    conf.queue = g_async_queue_new();
    conf.ready = g_async_queue_new();


    for (n = 0; n < n_threads; n++) {
        td[n].thread_id = n + 1;
        td[n].conf = &conf;
        threads[n] = g_thread_create((GThreadFunc)process_queue, &td[n], TRUE, NULL);

        g_async_queue_pop(conf.ready);
    }

    g_async_queue_unref(conf.ready);

    g_message("%d threads created", n_threads);

    add_job(&conf,"TEST1","10", 3305);
    add_job(&conf,"TEST2","11", 3306);
    add_job(&conf,"TEST3","12", 3307);
    add_job(&conf,"TEST4","13", 3308);
    add_job(&conf,"TEST5","14", 3309);
    add_job(&conf,"TEST6","14", 3309);
    add_job(&conf,"TEST7","14", 3309);

    for (n = 0; n < n_threads; n++) {
        struct job * jb = g_new0(struct job, 1);
        jb->type = JOB_SHUTDOWN;
        g_async_queue_push(conf.queue, jb);
    }

    for (n = 0; n < n_threads; n++)
        g_thread_join(threads[n]);

    g_async_queue_unref(conf.queue);
    g_free(td);
    g_free(threads);

    return 0;
}
G_GNUC_INTERNAL
void
_mdw_default_player_display_finalize(MdwDefaultPlayerDisplay** p_display)
{
    g_assert(p_display != NULL && *p_display != NULL);
    MdwDefaultPlayerDisplay* display = *p_display;

    DEBUG_INFO("Deinitializing DirectFB"); 
    if (display->directfb_thread) {
        MdwMessage* m = mdw_message_new(MDW_MESSAGE_TYPE_FINALIZE, 0);
        mdw_message_put(m, display->directfb_queue);
        g_assert(display->main_queue != NULL);
        m = mdw_message_get(display->main_queue, TRUE);
        if (m->type == MDW_MESSAGE_TYPE_FINALIZED) {
            /* deinitialized */
            /* g_thread_join ? */
        } else {
            DEBUG_ERROR("directfb_thread did not return MDW_MESSAGE_TYPE_FINALIZED");
            g_assert_not_reached();
        }
        g_assert(g_async_queue_length(display->main_queue) == 0);
        g_assert(g_async_queue_length(display->directfb_queue) == 0);
    }
    if (display->surface) {
        display->surface->Release(display->surface);
    }
    if (display->window) {
        display->window->Release(display->window);
    }
    if (display->layer) {
        display->layer->Release(display->layer);
    }
    if (display->dfb) {
        display->dfb->Release(display->dfb);
    }
    DEBUG_INFO("DirectFB released"); 
    if (display->main_queue) {
        g_assert(g_async_queue_length(display->main_queue) == 0);
        g_async_queue_unref(display->main_queue);
    }
    if (display->directfb_queue) {
        g_assert(g_async_queue_length(display->directfb_queue) == 0);
        g_async_queue_unref(display->directfb_queue);
    }
    g_free(display);
    *p_display = NULL;

}
Beispiel #10
0
static void
finalize (GSource *source)
{
  g_async_queue_unref (((struct source *)source)->queue);

  delete (struct source *)source;
}
/**
 * free all event-threads
 *
 * frees all the registered event-threads and event-queue
 */
void chassis_event_threads_free(chassis_event_threads_t *threads) {
	guint i;
	chassis_event_op_t *op;

	if (!threads) return;

	/* all threads are running, now wait until they are down again */
	for (i = 0; i < threads->event_threads->len; i++) {
		chassis_event_thread_t *event_thread = threads->event_threads->pdata[i];

		chassis_event_thread_free(event_thread);
	}

	g_ptr_array_free(threads->event_threads, TRUE);

	/* free the events that are still in the queue */
	while ((op = g_async_queue_try_pop(threads->event_queue))) {
		chassis_event_op_free(op);
	}
	g_async_queue_unref(threads->event_queue);

	/* close the notification pipe */
	if (threads->event_notify_fds[0] != -1) {
		closesocket(threads->event_notify_fds[0]);
	}
	if (threads->event_notify_fds[1] != -1) {
		closesocket(threads->event_notify_fds[1]);
	}


	g_free(threads);
}
Beispiel #12
0
/**
 * oh_destroy_session
 * @sid:
 * @update_domain:
 *
 *
 * Returns:
 **/
SaErrorT oh_destroy_session(SaHpiSessionIdT sid)
{
        struct oh_session *session = NULL;
        gpointer event = NULL;
        int i, len;

        if (sid < 1)
                return SA_ERR_HPI_INVALID_PARAMS;

        wrap_g_static_rec_mutex_lock(&oh_sessions.lock); /* Locked session table */
        session = g_hash_table_lookup(oh_sessions.table, &sid);
        if (!session) {
                wrap_g_static_rec_mutex_unlock(&oh_sessions.lock);
                return SA_ERR_HPI_INVALID_SESSION;
        }
        oh_sessions.list = g_slist_remove(oh_sessions.list, session);
        g_hash_table_remove(oh_sessions.table, &(session->id));
        wrap_g_static_rec_mutex_unlock(&oh_sessions.lock); /* Unlocked session table */

        /* Finalize session */
        len = g_async_queue_length(session->eventq);
        if (len > 0) {
                for (i = 0; i < len; i++) {
                        event = g_async_queue_try_pop(session->eventq);
                        if (event)
                                oh_event_free(event, FALSE);
                        event = NULL;
                }
        }
        g_async_queue_unref(session->eventq);
        g_free(session);

        return SA_OK;
}
Beispiel #13
0
static void _kqtime_freeStatsThreadWorkerHelper(GThread* thread, KQTimeStatsWorker* worker) {
	if(thread) {
		/* tell the thread to exit */
		if(worker && worker->commands) {
			KQTimeCommand* exitCommand = g_new0(KQTimeCommand, 1);
			exitCommand->type = KQTIME_CMD_EXIT;
			g_async_queue_push(worker->commands, exitCommand);
		}

		/* wait for the thread to exit */
		g_thread_join(thread);
		g_thread_unref(thread);
	}

	if(worker->logFile) {
		fclose(worker->logFile);
	}
	if(worker->gzLogFile) {
		gzflush(worker->gzLogFile, Z_FINISH);
		gzclose(worker->gzLogFile);
	}

	if(worker) {
		if(worker->commands) {
			g_async_queue_unref(worker->commands);
		}
		g_free(worker);
	}
}
Beispiel #14
0
/**
 * oh_create_session
 * @did:
 *
 *
 *
 * Returns:
 **/
SaHpiSessionIdT oh_create_session(SaHpiDomainIdT did)
{
        struct oh_session *session = NULL;
        struct oh_domain *domain = NULL;
        static SaHpiSessionIdT id = 1; /* Session ids will start at 1 */

        if (did < 1) return 0;

        session = g_new0(struct oh_session, 1);
        if (!session) return 0;

        session->did = did;
        session->eventq = g_async_queue_new();

        domain = oh_get_domain(did);
        if (!domain) {
                g_async_queue_unref(session->eventq);
                g_free(session);
                return 0;
        }
        g_static_rec_mutex_lock(&oh_sessions.lock); /* Locked session table */
        session->id = id++;
        g_hash_table_insert(oh_sessions.table, &(session->id), session);
        g_array_append_val(domain->sessions, session->id);
        g_static_rec_mutex_unlock(&oh_sessions.lock); /* Unlocked session table */
        oh_release_domain(domain);

        return session->id;
}
Beispiel #15
0
void proc_emu_on_io_in(struct connection *con, struct processor_data *pd)
{
	g_debug("%s con %p pd %p", __PRETTY_FUNCTION__, con, pd);
	struct emu_ctx *ctx = pd->ctx;

	int offset = MAX(ctx->offset-300, 0);
	void *streamdata = NULL;
	int32_t size = bistream_get_stream(pd->bistream, bistream_in, offset, -1, &streamdata);
	int ret = 0;
	if( size != -1 )
	{
		struct emu *e = emu_new();
#if 0
		emu_cpu_debugflag_set(emu_cpu_get(e), instruction_string);
		emu_log_level_set(emu_logging_get(e),EMU_LOG_DEBUG);
#endif
		ret = emu_shellcode_test(e, streamdata, size);
		emu_free(e);
		ctx->offset += size;
		if( ret >= 0 )
		{
			struct incident *ix = incident_new("dionaea.shellcode.detected");
			GAsyncQueue *aq = g_async_queue_ref(g_dionaea->threads->cmds);
			g_async_queue_push(aq, async_cmd_new(async_incident_report, ix));
			g_async_queue_unref(aq);
			ev_async_send(g_dionaea->loop, &g_dionaea->threads->trigger);
			g_debug("shellcode found offset %i", ret);
			profile(ctx->config, con, streamdata, size, ret);

			pd->state = processor_done;
		}
		g_free(streamdata);
	}
}
/* Base encoder cleanup (internal) */
void
gst_vaapi_encoder_finalize (GstVaapiEncoder * encoder)
{
  GstVaapiEncoderClass *const klass = GST_VAAPI_ENCODER_GET_CLASS (encoder);

  klass->finalize (encoder);

  gst_vaapi_object_replace (&encoder->context, NULL);
  gst_vaapi_display_replace (&encoder->display, NULL);
  encoder->va_display = NULL;

  if (encoder->properties) {
    g_ptr_array_unref (encoder->properties);
    encoder->properties = NULL;
  }

  gst_vaapi_video_pool_replace (&encoder->codedbuf_pool, NULL);
  if (encoder->codedbuf_queue) {
    g_async_queue_unref (encoder->codedbuf_queue);
    encoder->codedbuf_queue = NULL;
  }
  g_cond_clear (&encoder->surface_free);
  g_cond_clear (&encoder->codedbuf_free);
  g_mutex_clear (&encoder->mutex);
}
Beispiel #17
0
static void
xmr_player_dispose(GObject *object)
{
	XmrPlayer *player = XMR_PLAYER(object);
	XmrPlayerPrivate *priv = player->priv;
	
	libvlc_event_manager_t *event_mgr;
	gint i;

	event_mgr = libvlc_media_player_event_manager(priv->player);
	
	for (i = 0; i < g_vlc_event_count; ++i)
		libvlc_event_detach(event_mgr, g_vlc_events[i], vlc_event_callback, player);

	if (priv->event_idle_id != 0)
	{
		g_source_remove (priv->event_idle_id);
		priv->event_idle_id = 0;
	}

	if (priv->event_queue)
	{
		g_async_queue_unref(priv->event_queue);
		priv->event_queue = NULL;
	}

	libvlc_media_player_release(priv->player);
	libvlc_release(priv->instance);

	G_OBJECT_CLASS(xmr_player_parent_class)->dispose(object);
}
Beispiel #18
0
static void
tag_reader_finalize (GObject *object)
{
    TagReader *self = TAG_READER (object);

    self->priv->run = FALSE;

    while (g_async_queue_length (self->priv->job_queue) > 0) {
        QueueEntry *entry = g_async_queue_try_pop (self->priv->job_queue);

        if (!entry) {
            continue;
        }

        if (entry->location) {
            g_free (entry->location);
        }
        if (entry->mtype) {
            g_free (entry->mtype);
        }
        g_free (entry);
    }

    g_async_queue_push (self->priv->job_queue, NULL);
    g_thread_join (self->priv->job_thread);

    g_async_queue_unref (self->priv->job_queue);

    G_OBJECT_CLASS (tag_reader_parent_class)->finalize (object);
}
Beispiel #19
0
/*
 \brief Per plugin handler which shuts down the RTV stuff. Kills off the 
 rtv_subscriber thread, dismantles the queue in preparation for plugin shutdown
 \returns TRUE
 */
G_MODULE_EXPORT gboolean teardown_rtv(void)
{
	GAsyncQueue *queue = NULL;
	GThread *thread = NULL;
	GMutex *mutex = (GMutex *)DATA_GET(global_data,"rtv_subscriber_mutex");

	ENTER();
	/* This sends packets to the rtv_subscriber queue */
	thread = (GThread *)DATA_GET(global_data,"rtv_subscriber_thread");
	if (thread)
	{
		DATA_SET(global_data,"rtv_subscriber_thread_exit",GINT_TO_POINTER(1));
		g_thread_join(thread);
		DATA_SET(global_data,"rtv_subscriber_thread",NULL);
		DATA_SET(global_data,"rtv_subscriber_thread_exit",NULL);
	}
	g_mutex_lock(mutex);
	queue = (GAsyncQueue *)DATA_GET(global_data,"rtv_subscriber_queue");
	deregister_packet_queue(PAYLOAD_ID,queue,RESPONSE_BASIC_DATALOG);
	g_async_queue_unref(queue);
	DATA_SET(global_data,"rtv_subscriber_queue",NULL);
	g_mutex_unlock(mutex);
	DATA_SET(global_data,"realtime_id",NULL);
	EXIT();
	return TRUE;
}
static void moose_job_manager_finalize(GObject *gobject) {
    MooseJobManager *self = MOOSE_JOB_MANAGER(gobject);
    MooseJobManagerPrivate *priv = self->priv;

    /* Send a terminating job to the Queue and wait for it finish */
    g_async_queue_push(priv->job_queue, (gpointer)&priv->terminator);
    g_thread_join(priv->execute_thread);

    /* Free ressources */
    g_async_queue_unref(priv->job_queue);

    g_cond_clear(&priv->finish_cond);
    g_mutex_clear(&priv->finish_mutex);
    g_mutex_clear(&priv->current_job_mutex);
    g_mutex_clear(&priv->hash_table_mutex);
    g_mutex_clear(&priv->job_id_counter_mutex);

    if(priv->current_job != NULL) {
        moose_job_free(priv->current_job);
    }

    g_hash_table_destroy(priv->results);

    /* Always chain up to the parent class; as with dispose(), finalize()
     * is guaranteed to exist on the parent's class virtual function table
     */
    G_OBJECT_CLASS(g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)))->finalize(gobject);
}
Beispiel #21
0
void
_g_thread_pool_shutdown (void)
{
  GThread *thread;

  g_thread_pool_set_max_unused_threads (0);

  G_LOCK (threads);
  while (active_threads != NULL)
    {
      thread = g_thread_ref (active_threads->data);
      G_UNLOCK (threads);
      g_thread_join (thread);
      G_LOCK (threads);
    }
  while (finished_threads != NULL)
    {
      thread = finished_threads->data;
      finished_threads = g_slist_delete_link (finished_threads,
                                              finished_threads);
      G_UNLOCK (threads);
      g_thread_join (thread);
      G_LOCK (threads);
    }
  G_UNLOCK (threads);

  if (unused_thread_queue)
    {
      g_async_queue_unref (unused_thread_queue);
      unused_thread_queue = NULL;
    }
}
Beispiel #22
0
bool Action::run_one( GAsyncQueue * queue , gulong wait_ms )
{
    g_assert( queue );

    g_async_queue_ref( queue );

    Action * action = 0;

    if ( wait_ms == 0 )
    {
        action = ( Action * ) g_async_queue_try_pop( queue );
    }
    else
    {
        action = ( Action * ) Util::g_async_queue_timeout_pop( queue , wait_ms * 1000 );
    }

    g_async_queue_unref( queue );

    if ( action )
    {
        run_internal( action );

        delete action;

        return true;
    }

    return false;
}
Beispiel #23
0
static void
impl_deactivate(PeasActivatable *activatable)
{
	XmrSearchPlugin *plugin;
	XmrWindow *window = NULL;

	plugin = XMR_SEARCH_PLUGIN(activatable);
	g_object_get(plugin, "object", &window, NULL);

	if (window)
	{
		g_signal_handlers_disconnect_by_func(window, on_music_search, plugin);
		g_object_unref(window);
	}
	
	if (plugin->event_idle_id)
		g_source_remove(plugin->event_idle_id);

	g_async_queue_unref(plugin->event_queue);
	
	if (plugin->mutex)
	{
#if GLIB_CHECK_VERSION(2, 32, 0)
		g_mutex_clear(plugin->mutex);
		g_free(plugin->mutex);
#else
		g_mutex_free(plugin->mutex);
#endif
		plugin->mutex = NULL;
	}
}
Beispiel #24
0
void QuiddityManager::clear_command_sync() {
  command_lock();
  command_->set_id(QuiddityCommand::quit);
  invoke_in_thread();
  g_async_queue_unref(command_queue_);
  command_unlock();
}
Beispiel #25
0
void janus_serial_destroy(void) {
	if(!g_atomic_int_get(&initialized))
		return;
	g_atomic_int_set(&stopping, 1);

	if(handler_thread != NULL) {
		g_thread_join(handler_thread);
		handler_thread = NULL;
	}
	if(watchdog != NULL) {
		g_thread_join(watchdog);
		watchdog = NULL;
	}

	/* FIXME We should destroy the sessions cleanly */
	janus_mutex_lock(&sessions_mutex);
	g_hash_table_destroy(sessions);
	janus_mutex_unlock(&sessions_mutex);
	g_async_queue_unref(messages);
	messages = NULL;
	sessions = NULL;

	g_atomic_int_set(&initialized, 0);
	g_atomic_int_set(&stopping, 0);
	JANUS_LOG(LOG_INFO, "%s destroyed!\n", JANUS_SERIAL_NAME);
}
Beispiel #26
0
static void
_gck_call_base_finalize (GckCallClass *klass)
{
	GMainContext *context;
	GSource *src;

	if (klass->thread_pool) {
		g_assert (g_thread_pool_unprocessed (klass->thread_pool) == 0);
		g_thread_pool_free (klass->thread_pool, FALSE, TRUE);
		klass->thread_pool = NULL;
	}

	if (klass->completed_id) {
		context = g_main_context_default ();
		g_return_if_fail (context);

		src = g_main_context_find_source_by_id (context, klass->completed_id);
		g_assert (src);
		g_source_destroy (src);
		klass->completed_id = 0;
	}

	if (klass->completed_queue) {
		g_assert (g_async_queue_length (klass->completed_queue));
		g_async_queue_unref (klass->completed_queue);
		klass->completed_queue = NULL;
	}
}
Beispiel #27
0
int
main (int argc, char** argv)
{
	ui_t *ui = NULL;
	sink_t *sink = NULL;
	GThread *sink_thread = NULL;
	GAsyncQueue *queue = NULL;

	g_thread_init (NULL);
	queue = g_async_queue_new ();

	if (!(sink = sink_init (queue)))
		return EXIT_FAILURE;

	if(!(ui = ui_init (queue, &argc, &argv)))
		 return EXIT_FAILURE;

	g_async_queue_unref (queue);
	sink_thread = g_thread_create (sink_run, (gpointer) sink, TRUE, NULL);

	ui_run(ui);
	g_thread_join (sink_thread);

	ui_cleanup (ui);
	sink_cleanup (sink);

	g_printf ("So long, and thanks for the fish !\n");

	return EXIT_SUCCESS;
}
Beispiel #28
0
void janus_pfunix_session_over(void *transport, guint64 session_id, gboolean timeout) {
	/* We only care if it's a timeout: if so, close the connection */
	if(transport == NULL || !timeout)
		return;
	/* FIXME Should we really close the connection in case of a timeout? */
	janus_pfunix_client *client = (janus_pfunix_client *)transport;
	janus_mutex_lock(&clients_mutex);
	if(g_hash_table_lookup(clients, client) != NULL) {
		client->session_timeout = TRUE;
		if(client->fd != -1) {
			/* Shutdown the client socket */
			shutdown(client->fd, SHUT_WR);
		} else {
			/* Destroy the client */
			g_hash_table_remove(clients_by_path, client->addr.sun_path);
			g_hash_table_remove(clients, client);
			if(client->messages != NULL) {
				char *response = NULL;
				while((response = g_async_queue_try_pop(client->messages)) != NULL) {
					g_free(response);
				}
				g_async_queue_unref(client->messages);
			}
			g_free(client);
		}
	}
	janus_mutex_unlock(&clients_mutex);
}
Beispiel #29
0
void
destroy_sctp_transport(struct sctp_transport *sctp)
{
    if (sctp == NULL)
        return;

    usrsctp_close(sctp->sock);
    usrsctp_deregister_address(sctp);
    BIO_free_all(sctp->incoming_bio);
    BIO_free_all(sctp->outgoing_bio);
#ifdef DEBUG_SCTP
    close(sctp->incoming_stub);
    close(sctp->outgoing_stub);
#endif
    g_async_queue_unref(sctp->deferred_messages);
    free(sctp);
    sctp = NULL;

    g_sctp_ref--;
    if (g_sctp_ref == 0) {
        for (int i = 0; i < 300; ++i) {
            if (usrsctp_finish() == 0)
                return;
            g_usleep(10000);
        }
    }
}
Beispiel #30
0
/**
 * oh_create_session
 * @did:
 *
 *
 *
 * Returns:
 **/
SaHpiSessionIdT oh_create_session(SaHpiDomainIdT did)
{
        struct oh_session *session = NULL;
        struct oh_domain *domain = NULL;
        static SaHpiSessionIdT id = 1;        /* Session ids will start at 1 */

        if (did == SAHPI_UNSPECIFIED_DOMAIN_ID)
                did = OH_DEFAULT_DOMAIN_ID;

        session = g_new0(struct oh_session, 1);
        if (!session)
                return 0;

        session->did = did;
        session->eventq = g_async_queue_new();
        session->subscribed = SAHPI_FALSE;

        domain = oh_get_domain(did);
        if (!domain) {
                g_async_queue_unref(session->eventq);
                g_free(session);
                return 0;
        }
        wrap_g_static_rec_mutex_lock(&oh_sessions.lock); /* Locked session table */
        session->id = id++;
        g_hash_table_insert(oh_sessions.table, &(session->id), session);
        oh_sessions.list = g_slist_append(oh_sessions.list, session);
        wrap_g_static_rec_mutex_unlock(&oh_sessions.lock); /* Unlocked session table */
        oh_release_domain(domain);

        return session->id;
}