objects.c revision 6ba597c56d749c61b4f783157f63196d7b2445f0
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <signal.h>
#include <errno.h>
#include <syslog.h>
#include <libuutil.h>
#include <errno.h>
#include "events.h"
#include "objects.h"
#include "util.h"
/*
* objects.c - contains routines which manipulate object lists of NCUs,
* locations, ENMs and known WLANs.
*/
typedef struct nwamd_object_list {
{
{ NWAM_EVENT_TYPE_NOOP, NULL }
};
{
{ NWAM_EVENT_TYPE_NOOP, NULL }
};
{
{ NWAM_EVENT_TYPE_NOOP, NULL }
};
{
{ NWAM_EVENT_TYPE_NOOP, NULL }
};
{
{ NWAM_EVENT_TYPE_NOOP, NULL }
};
/* Should be kept in same order as object types */
};
/*
* Comparison function for objects, passed in as callback to
* uu_list_pool_create().
*/
/* ARGSUSED */
static int
{
int rv;
(void) pthread_mutex_lock(&l->nwamd_object_mutex);
if (l != r)
(void) pthread_mutex_lock(&r->nwamd_object_mutex);
if (l != r)
(void) pthread_mutex_unlock(&r->nwamd_object_mutex);
(void) pthread_mutex_unlock(&l->nwamd_object_mutex);
return (rv);
}
void
nwamd_object_lists_init(void)
{
int i;
sizeof (struct nwamd_object),
if (object_list_pool == NULL)
for (i = 0;
i < sizeof (object_lists) / sizeof (struct nwamd_object_list);
i++) {
NULL, 0);
pfail("uu_list_create failed with error %d",
uu_error());
}
}
void
nwamd_object_lists_fini(void)
{
int i;
for (i = 0;
i < sizeof (object_lists) / sizeof (struct nwamd_object_list);
i++) {
}
}
if (object_list_pool != NULL)
}
static nwamd_object_list_t *
{
return (&object_lists[type]);
}
static int
{
return (0);
}
static int
{
return (-1);
}
return (0);
}
static void
{
}
/*
* Initialize object and return it in locked state.
*/
void *data)
{
return (NULL);
/* 1 for the list and 1 for the returned object */
/* Add object to appropriate object list */
if (nwamd_object_list_lock(type) != 0) {
"object %s", name);
return (NULL);
}
return (NULL);
}
return (object);
}
/*
* Find object in object list, returning it holding a lock and with the
* reference count incremented. The opposite function to this is
* nwamd_object_release().
*/
{
if (nwamd_object_list_rlock(type) != 0)
return (NULL);
break;
}
}
return (object);
}
/* Removes object from list, destroy mutex, and free storage. */
static void
{
struct nwamd_object_list *object_list;
o != NULL;
if (o == object) {
(void) pthread_mutex_unlock(
(void) pthread_mutex_destroy(
switch (objtype) {
case NWAM_OBJECT_TYPE_NCU:
break;
case NWAM_OBJECT_TYPE_LOC:
break;
case NWAM_OBJECT_TYPE_ENM:
break;
default:
"got unexpected object type %d", objtype);
break;
}
break;
}
}
}
static void
{
if (object->nwamd_object_refcount == 0) {
/*
* We need to maintain the locking hierarchy of owning the
* list lock before we get the object lock when we are
* destroying the object. If we merely release and then
* reacquire in the right order we might not find the right
* object. Instead we bump the ref count so that it can't
* be destroyed, we drop the object lock, we acquire the
* list lock, we acquire the object lock, decrement the ref
* count, check to make sure we are really destroying it and
* somebody else hasn't gotten it, and then, if its unref'd,
* destroying it.
*/
(void) nwamd_object_list_lock(objtype);
if (--object->nwamd_object_refcount != 0)
(void) pthread_mutex_unlock(
else
} else {
}
}
/*
* Drop mutex without decreasing reference count. Used where we wish to
* let go of an object but ensure it will not go away.
*/
void
{
}
void
{
}
void
{
}
void
{
}
void
{
}
void
{
}
void
{
}
{
return (object_list->object_event_methods);
}
/*
* Walk all objects of specified type calling callback function cb.
* Object is locked for duration of callback.
*/
int
void *data)
{
int ret = 0;
if (nwamd_object_list_rlock(type) != 0)
return (-1);
if (ret != 0) {
return (ret);
}
}
return (0);
}