Use sx locks rather than lockmgr locks for eventhandlers.

Submitted by: Jonathan Mini <mini@haikugeek.com>
This commit is contained in:
alfred 2002-04-02 04:18:54 +00:00
parent ab6bb4225e
commit cb408d85e7
2 changed files with 16 additions and 18 deletions

View File

@ -90,6 +90,7 @@ eventhandler_register(struct eventhandler_list *list, char *name,
return(NULL);
}
list->el_flags = 0;
bzero(&list->el_lock, sizeof(list->el_lock));
list->el_name = (char *)list + sizeof(struct eventhandler_list);
strcpy(list->el_name, name);
TAILQ_INSERT_HEAD(&eventhandler_lists, list, el_link);
@ -97,7 +98,7 @@ eventhandler_register(struct eventhandler_list *list, char *name,
}
if (!(list->el_flags & EHE_INITTED)) {
TAILQ_INIT(&list->el_entries);
lockinit(&list->el_lock, PZERO, name, 0, 0);
sx_init(&list->el_lock, name);
list->el_flags = EHE_INITTED;
}
@ -112,7 +113,7 @@ eventhandler_register(struct eventhandler_list *list, char *name,
eg->ee.ee_priority = priority;
/* sort it into the list */
lockmgr(&list->el_lock, LK_EXCLUSIVE, NULL, curthread);
EHE_LOCK(list);
for (ep = TAILQ_FIRST(&list->el_entries);
ep != NULL;
ep = TAILQ_NEXT(ep, ee_link)) {
@ -123,7 +124,7 @@ eventhandler_register(struct eventhandler_list *list, char *name,
}
if (ep == NULL)
TAILQ_INSERT_TAIL(&list->el_entries, &eg->ee, ee_link);
lockmgr(&list->el_lock, LK_RELEASE, NULL, curthread);
EHE_UNLOCK(list);
mtx_unlock(&eventhandler_mutex);
return(&eg->ee);
}
@ -134,7 +135,7 @@ eventhandler_deregister(struct eventhandler_list *list, eventhandler_tag tag)
struct eventhandler_entry *ep = tag;
/* XXX insert diagnostic check here? */
lockmgr(&list->el_lock, LK_EXCLUSIVE, NULL, curthread);
EHE_LOCK(list);
if (ep != NULL) {
/* remove just this entry */
TAILQ_REMOVE(&list->el_entries, ep, ee_link);
@ -147,7 +148,7 @@ eventhandler_deregister(struct eventhandler_list *list, eventhandler_tag tag)
free(ep, M_EVENTHANDLER);
}
}
lockmgr(&list->el_lock, LK_RELEASE, NULL, curthread);
EHE_UNLOCK(list);
}
struct eventhandler_list *

View File

@ -29,15 +29,9 @@
#ifndef SYS_EVENTHANDLER_H
#define SYS_EVENTHANDLER_H
/*
* XXX - compatability until lockmgr() goes away or all the #includes are
* updated.
*/
#include <sys/lockmgr.h>
#include <sys/lock.h>
#include <sys/sx.h>
#include <sys/queue.h>
#include <sys/_lock.h>
#include <sys/_mutex.h>
struct eventhandler_entry
{
@ -51,13 +45,16 @@ struct eventhandler_list
char *el_name;
int el_flags;
#define EHE_INITTED (1<<0)
struct lock el_lock;
struct sx el_lock;
TAILQ_ENTRY(eventhandler_list) el_link;
TAILQ_HEAD(,eventhandler_entry) el_entries;
};
typedef struct eventhandler_entry *eventhandler_tag;
#define EHE_LOCK(p) sx_xlock(&(p)->el_lock)
#define EHE_UNLOCK(p) sx_xunlock(&(p)->el_lock)
/*
* Fast handler lists require the eventhandler list be present
* at link time. They don't allow addition of entries to
@ -87,7 +84,7 @@ do { \
struct eventhandler_entry *_ep, *_en; \
\
if (_el->el_flags & EHE_INITTED) { \
lockmgr(&_el->el_lock, LK_EXCLUSIVE, NULL, curthread); \
EHE_LOCK(_el); \
_ep = TAILQ_FIRST(&(_el->el_entries)); \
while (_ep != NULL) { \
_en = TAILQ_NEXT(_ep, ee_link); \
@ -95,7 +92,7 @@ do { \
## args); \
_ep = _en; \
} \
lockmgr(&_el->el_lock, LK_RELEASE, NULL, curthread); \
EHE_UNLOCK(_el); \
} \
} while (0)
@ -127,7 +124,7 @@ do { \
\
if (((_el = eventhandler_find_list(#name)) != NULL) && \
(_el->el_flags & EHE_INITTED)) { \
lockmgr(&_el->el_lock, LK_EXCLUSIVE, NULL, curthread); \
EHE_LOCK(_el); \
_ep = TAILQ_FIRST(&(_el->el_entries)); \
while (_ep != NULL) { \
_en = TAILQ_NEXT(_ep, ee_link); \
@ -135,7 +132,7 @@ do { \
## args); \
_ep = _en; \
} \
lockmgr(&_el->el_lock, LK_RELEASE, NULL, curthread); \
EHE_UNLOCK(_el); \
} \
} while (0)