示例#1
0
const char *
virThreadJobGet(void)
{
    const char *job;

    if (virThreadJobInitialize() < 0)
        return NULL;

    job = virThreadLocalGet(&virThreadJobName);
    if (!job)
        job = virThreadLocalGet(&virThreadJobWorker);

    return job;
}
示例#2
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;
}
示例#3
0
/**
 * virIdentityGetCurrent:
 *
 * Get the current identity associated with this thread. The
 * caller will own a reference to the returned identity, but
 * must not modify the object in any way, other than to
 * release the reference when done with virObjectUnref
 *
 * Returns: a reference to the current identity, or NULL
 */
virIdentityPtr virIdentityGetCurrent(void)
{
    virIdentityPtr ident;

    if (virIdentityInitialize() < 0)
        return NULL;

    ident = virThreadLocalGet(&virIdentityCurrent);
    return virObjectRef(ident);
}
示例#4
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;
}
示例#5
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);
    }
}
示例#6
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;
}
示例#7
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);
    }
}