VIR_LOG_INIT("conf.virinterfaceobj");
struct _virInterfaceObj {
- virMutex lock;
+ virObjectLockable parent;
bool active; /* true if interface is active (up) */
virInterfaceDefPtr def; /* The interface definition */
/* virInterfaceObj manipulation */
+static virClassPtr virInterfaceObjClass;
+static void virInterfaceObjDispose(void *obj);
+
+static int
+virInterfaceObjOnceInit(void)
+{
+ if (!(virInterfaceObjClass = virClassNew(virClassForObjectLockable(),
+ "virInterfaceObj",
+ sizeof(virInterfaceObj),
+ virInterfaceObjDispose)))
+ return -1;
+
+ return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virInterfaceObj)
+
+
+static void
+virInterfaceObjDispose(void *opaque)
+{
+ virInterfaceObjPtr obj = opaque;
+
+ virInterfaceDefFree(obj->def);
+}
+
+
static virInterfaceObjPtr
virInterfaceObjNew(virInterfaceDefPtr def)
{
virInterfaceObjPtr obj;
- if (VIR_ALLOC(obj) < 0)
+ if (virInterfaceObjInitialize() < 0)
return NULL;
- if (virMutexInit(&obj->lock) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("cannot initialize mutex"));
- VIR_FREE(obj);
+ if (!(obj = virObjectLockableNew(virInterfaceObjClass)))
return NULL;
- }
- virInterfaceObjLock(obj);
+ virObjectLock(obj);
obj->def = def;
return obj;
void
-virInterfaceObjLock(virInterfaceObjPtr obj)
+virInterfaceObjEndAPI(virInterfaceObjPtr *obj)
{
- virMutexLock(&obj->lock);
-}
-
-
-void
-virInterfaceObjUnlock(virInterfaceObjPtr obj)
-{
- virMutexUnlock(&obj->lock);
-}
-
-
-void
-virInterfaceObjFree(virInterfaceObjPtr obj)
-{
- if (!obj)
+ if (!*obj)
return;
- virInterfaceDefFree(obj->def);
- virMutexDestroy(&obj->lock);
- VIR_FREE(obj);
+ virObjectUnlock(*obj);
+ virObjectUnref(*obj);
+ *obj = NULL;
}
virInterfaceObjPtr obj = interfaces->objs[i];
virInterfaceDefPtr def;
- virInterfaceObjLock(obj);
+ virObjectLock(obj);
def = obj->def;
if (STRCASEEQ(def->mac, mac)) {
if (matchct < maxmatches) {
if (VIR_STRDUP(matches[matchct], def->name) < 0) {
- virInterfaceObjUnlock(obj);
+ virObjectUnlock(obj);
goto error;
}
matchct++;
}
}
- virInterfaceObjUnlock(obj);
+ virObjectUnlock(obj);
}
return matchct;
virInterfaceObjPtr obj = interfaces->objs[i];
virInterfaceDefPtr def;
- virInterfaceObjLock(obj);
+ virObjectLock(obj);
def = obj->def;
if (STREQ(def->name, name))
- return obj;
- virInterfaceObjUnlock(obj);
+ return virObjectRef(obj);
+ virObjectUnlock(obj);
}
return NULL;
size_t i;
for (i = 0; i < interfaces->count; i++)
- virInterfaceObjFree(interfaces->objs[i]);
+ virObjectUnref(interfaces->objs[i]);
VIR_FREE(interfaces->objs);
VIR_FREE(interfaces);
}
VIR_FREE(xml);
if (!(obj = virInterfaceObjListAssignDef(dest, backup)))
goto error;
- virInterfaceObjUnlock(obj); /* locked by virInterfaceObjListAssignDef */
+ virInterfaceObjEndAPI(&obj);
}
return dest;
if (VIR_APPEND_ELEMENT_COPY(interfaces->objs,
interfaces->count, obj) < 0) {
obj->def = NULL;
- virInterfaceObjUnlock(obj);
- virInterfaceObjFree(obj);
+ virInterfaceObjEndAPI(&obj);
return NULL;
}
-
- return obj;
-
+ return virObjectRef(obj);
}
{
size_t i;
- virInterfaceObjUnlock(obj);
+ virObjectUnlock(obj);
for (i = 0; i < interfaces->count; i++) {
- virInterfaceObjLock(interfaces->objs[i]);
+ virObjectLock(interfaces->objs[i]);
if (interfaces->objs[i] == obj) {
- virInterfaceObjUnlock(interfaces->objs[i]);
- virInterfaceObjFree(interfaces->objs[i]);
+ virObjectUnlock(interfaces->objs[i]);
+ virObjectUnref(interfaces->objs[i]);
VIR_DELETE_ELEMENT(interfaces->objs, i, interfaces->count);
break;
}
- virInterfaceObjUnlock(interfaces->objs[i]);
+ virObjectUnlock(interfaces->objs[i]);
}
}
for (i = 0; (i < interfaces->count); i++) {
virInterfaceObjPtr obj = interfaces->objs[i];
- virInterfaceObjLock(obj);
+ virObjectLock(obj);
if (wantActive == virInterfaceObjIsActive(obj))
ninterfaces++;
- virInterfaceObjUnlock(obj);
+ virObjectUnlock(obj);
}
return ninterfaces;
virInterfaceObjPtr obj = interfaces->objs[i];
virInterfaceDefPtr def;
- virInterfaceObjLock(obj);
+ virObjectLock(obj);
def = obj->def;
if (wantActive == virInterfaceObjIsActive(obj)) {
if (VIR_STRDUP(names[nnames], def->name) < 0) {
- virInterfaceObjUnlock(obj);
+ virObjectUnlock(obj);
goto failure;
}
nnames++;
}
- virInterfaceObjUnlock(obj);
+ virObjectUnlock(obj);
}
return nnames;
}
virInterfaceObjSetActive(obj, true);
- virInterfaceObjUnlock(obj);
+ virInterfaceObjEndAPI(&obj);
}
ret = 0;
ret = virGetInterface(conn, def->name, def->mac);
- virInterfaceObjUnlock(obj);
+ virInterfaceObjEndAPI(&obj);
return ret;
}
ret = virInterfaceObjIsActive(obj);
- virInterfaceObjUnlock(obj);
+ virInterfaceObjEndAPI(&obj);
return ret;
}
ret = virInterfaceDefFormat(def);
- virInterfaceObjUnlock(obj);
+ virInterfaceObjEndAPI(&obj);
return ret;
}
cleanup:
virInterfaceDefFree(def);
- if (obj)
- virInterfaceObjUnlock(obj);
+ virInterfaceObjEndAPI(&obj);
testDriverUnlock(privconn);
return ret;
}
return -1;
virInterfaceObjListRemove(privconn->ifaces, obj);
+ virObjectUnref(obj);
return 0;
}
ret = 0;
cleanup:
- virInterfaceObjUnlock(obj);
+ virInterfaceObjEndAPI(&obj);
return ret;
}
ret = 0;
cleanup:
- virInterfaceObjUnlock(obj);
+ virInterfaceObjEndAPI(&obj);
return ret;
}