void link_push(Link* link ,M_Node* node){
    link_lock(link);
    if (!link->rear) {
        link->front = link->rear = node;
    }else{
        link->rear->next = node;
        link->rear = node;
    }
    link->node_count ++;
    link->size += node->data_buffer_size;
    link_unlock(link);
}
Example #2
0
void
link_wait (void)
{
	if (!(link_is_thread_safe && link_is_io_in_thread)) {
		link_unlock ();
		link_main_iteration (TRUE);
		link_lock ();
	} else {
		g_assert (link_main_cond != NULL);
		g_cond_wait (link_main_cond, link_main_lock);
	}
}
Example #3
0
static int
ln_lock(
    char *	res, /* name of resource to lock */
    int		op)  /* true to lock; false to unlock */
{
    long mypid;
    char *lockfile = NULL;
    char *tlockfile = NULL;
    char *mres = NULL;
    int rc;
    char pid_str[NUM_STR_SIZE];

    mypid = (long)getpid();

    lockfile = g_strjoin(NULL, _lnlock_dir, "/am", res, ".lock", NULL);

    if (!op) {
        /* unlock the resource */
        assert(read_lock(lockfile) == mypid);

        (void)delete_lock(lockfile);
        amfree(lockfile);
        return 0;
    }

    /* lock the resource */

    g_snprintf(pid_str, sizeof(pid_str), "%ld", mypid);
    tlockfile = g_strjoin(NULL, _lnlock_dir, "/am", res, ".", pid_str, NULL);

    (void)create_lock(tlockfile, mypid);

    mres = stralloc2(res, ".");

    while(1) {
        rc = link_lock(lockfile, tlockfile);
        if (rc == -1) break;
        if (rc == 0) break;

        rc = steal_lock(lockfile, mypid, mres);
        if (rc == -1) break;
        if (rc == 0) continue;
        sleep(1);
    }

    (void) delete_lock(tlockfile);

    amfree(mres);
    amfree(tlockfile);
    amfree(lockfile);

    return rc;
}
M_Node* link_pop(Link* link){
    link_lock(link);
    M_Node* node = link->front;
    
    if(node){
        link->front = node->next;
        if(!link->front){
            link->rear = link->front;
        }
        node->next = NULL;
        link->node_count --;
        link->size -= node->data_buffer_size;
    }
    link_unlock(link);
    return node;
}
Example #5
0
static void
link_exec_set_io_thread (gpointer data, gboolean immediate)
{
	GError *error = NULL;
	gboolean to_io_thread = TRUE;

	if (link_is_io_in_thread)
		return;

	link_lock ();
	g_mutex_lock (link_cmd_queue_lock);

	link_is_io_in_thread = TRUE;
	
	link_thread_context = g_main_context_new ();
	link_thread_loop = g_main_loop_new (link_thread_context, TRUE);

	link_connections_move_io_T (to_io_thread);
	link_servers_move_io_T     (to_io_thread);

	if (link_pipe (link_wakeup_fds) < 0)
		g_error ("Can't create CORBA main-thread wakeup pipe");

	link_main_source = link_source_create_watch
		(link_thread_context, LINK_WAKEUP_POLL,
		 NULL, (G_IO_IN | G_IO_PRI),
		 link_mainloop_handle_input, NULL);
	
	link_io_thread = g_thread_create_full
		(link_io_thread_fn, NULL, 256 * 1024, TRUE, FALSE,
		 G_THREAD_PRIORITY_NORMAL, &error);
	
	if (!link_io_thread || error)
		g_error ("Failed to create linc worker thread");

	g_main_loop_quit (link_loop);

	g_mutex_unlock (link_cmd_queue_lock);
	link_unlock ();
}