Beispiel #1
0
void async_task_queue_submit(async_task_queue_t *task_queue, void(*callback)(void *userdata), void* userdata)
{
    struct async_task *task;

    if (NULL == task_queue || NULL == callback)
    {
        log_error("async_task_queue_submit: bad task_queue(%p) or bad callback(%p)", task_queue, callback);
        return;
    }

    task = (struct async_task*)malloc(sizeof(*task));
    memset(task, 0, sizeof(*task));

    task->callback = callback;
    task->userdata = userdata;
    task->next = NULL;

    lock_it(&task_queue->task_lock);
    if (NULL == task_queue->async_task)
    {
        task_queue->async_task = task;
        task_queue->async_task_end = task;
    }
    else
    {
        task_queue->async_task_end->next = task;
        task_queue->async_task_end = task;
    }
    unlock_it(&task_queue->task_lock);

    send(task_queue->fds[1], (const char*)&task, sizeof(task), 0);

    return;
}
Beispiel #2
0
void bw_unlock(BW *bw)
{
	if (bw->b->locked && !bw->b->ignored_lock && plain_file(bw->b)) {
		unlock_it(bw->b->name);
		bw->b->locked = 0;
	}
}
Beispiel #3
0
int steal_lock(BW *bw,int c,B *b,int *notify)
{
	if (yncheck(steallock_key, c)) {
		unsigned char bf1[256];
		unsigned char bf[300];
		unlock_it(b->name);
		if (lock_it(b->name,bf1)) {
			int x;
			for(x=0;bf1[x] && bf1[x]!=':';++x);
			bf1[x]=0;
			if(bf1[0])
				joe_snprintf_1(bf,sizeof(bf),joe_gettext(LOCKMSG1),bf1);
			else
				joe_snprintf_0(bf, sizeof(bf), joe_gettext(LOCKMSG2));
			if (mkqw(bw->parent, sz(bf), steal_lock, NULL, b, notify)) {
				return 0;
			} else {
				if (notify)
					*notify = -1;
				return -1;
			}
		} else {
			b->locked=1;
			if (notify)
				*notify = 1;
			return 0;
		}
	} else if (yncheck(ignorelock_key, c)) {
		b->locked=1;
		b->ignored_lock=1;
		if (notify)
			*notify = 1;
		return 0;
	} else if (yncheck(canceledit_key, c)) {
		if (notify)
			*notify = 1;
		return 0;
	} else {
		if (mkqw(bw->parent, sz(joe_gettext(LOCKMSG2)), steal_lock, NULL, b, notify)) {
			return 0;
		} else
			return -1;
	}
}
Beispiel #4
0
static
void async_task_queue_process(async_task_queue_t *task_queue)
{
    struct async_task *task;
    struct async_task *t_iter;

    lock_it(&task_queue->task_lock);
    task = task_queue->async_task;
    task_queue->async_task = NULL;
    task_queue->async_task_end = NULL;
    unlock_it(&task_queue->task_lock);

    while (NULL != task)
    {
        t_iter = task->next;

        task->callback(task->userdata);
        free(task);

        task = t_iter;
    }
    
    return;
}