Пример #1
0
int virCondWait(virCondPtr c, virMutexPtr m)
{
    HANDLE event = virThreadLocalGet(&virCondEvent);

    if (!event) {
        event = CreateEvent(0, FALSE, FALSE, NULL);
        if (!event) {
            return -1;
        }
        virThreadLocalSet(&virCondEvent, event);
    }

    virMutexLock(&c->lock);

    if (VIR_REALLOC_N(c->waiters, c->nwaiters + 1) < 0) {
        virMutexUnlock(&c->lock);
        return -1;
    }
    c->waiters[c->nwaiters] = event;
    c->nwaiters++;

    virMutexUnlock(&c->lock);

    virMutexUnlock(m);

    if (WaitForSingleObject(event, INFINITE) == WAIT_FAILED) {
        virMutexLock(m);
        errno = EINVAL;
        return -1;
    }

    virMutexLock(m);
    return 0;
}
Пример #2
0
static virErrorPtr
virLastErrorObject(void)
{
    virErrorPtr err;
    err = virThreadLocalGet(&virLastErr);
    if (!err) {
        if (VIR_ALLOC_QUIET(err) < 0)
            return NULL;
        if (virThreadLocalSet(&virLastErr, err) < 0)
            VIR_FREE(err);
    }
    return err;
}
Пример #3
0
void
virThreadJobSetWorker(const char *worker)
{
    if (!worker || virThreadJobInitialize() < 0)
        return;

    if (virThreadLocalSet(&virThreadJobWorker, (void *) worker) < 0)
        virReportSystemError(errno,
                             _("cannot set worker name to %s"),
                             worker);

    VIR_DEBUG("Thread %llu is running worker %s", virThreadSelfID(), worker);
}
Пример #4
0
/**
 * virIdentitySetCurrent:
 *
 * Set the new identity to be associated with this thread.
 * The caller should not modify the passed identity after
 * it has been set, other than to release its own reference.
 *
 * Returns 0 on success, or -1 on error
 */
int virIdentitySetCurrent(virIdentityPtr ident)
{
    virIdentityPtr old;

    if (virIdentityInitialize() < 0)
        return -1;

    old = virThreadLocalGet(&virIdentityCurrent);
    virObjectUnref(old);

    if (virThreadLocalSet(&virIdentityCurrent,
                          virObjectRef(ident)) < 0) {
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("Unable to set thread local identity"));
        return -1;
    }

    return 0;
}
Пример #5
0
void
virThreadJobSet(const char *caller)
{
    const char *worker;

    if (!caller || virThreadJobInitialize() < 0)
        return;

    if (virThreadLocalSet(&virThreadJobName, (void *) caller) < 0)
        virReportSystemError(errno,
                             _("cannot set current job to %s"),
                             caller);

    if ((worker = virThreadLocalGet(&virThreadJobWorker))) {
        VIR_DEBUG("Thread %llu (%s) is now running job %s",
                  virThreadSelfID(), worker, caller);
    } else {
        VIR_DEBUG("Thread %llu is now running job %s",
                  virThreadSelfID(), caller);
    }
}
Пример #6
0
void
virThreadJobClear(int rv)
{
    const char *old;
    const char *worker;

    if (virThreadJobInitialize() < 0)
        return;

    if (!(old = virThreadLocalGet(&virThreadJobName)))
        return;

    if (virThreadLocalSet(&virThreadJobName, NULL) < 0)
        virReportSystemError(errno, "%s", _("cannot reset current job"));

    if ((worker = virThreadLocalGet(&virThreadJobWorker))) {
        VIR_DEBUG("Thread %llu (%s) finished job %s with ret=%d",
                  virThreadSelfID(), worker, old, rv);
    } else {
        VIR_DEBUG("Thread %llu finished job %s with ret=%d",
                  virThreadSelfID(), old, rv);
    }
}