* struct family now uses a DoublyLinkedList instead of a struct list.

* Added but commented out adding/removing chains to its family: this would allow
  the stack to unload protocol modules as soon as they are no longer needed.
  However, it currently does not work yet (double lock, we need a recursive lock
  here to allow this).
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30199 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-04-16 11:11:37 +00:00
parent 7caa5d430c
commit 4e5191e9c1
+14 -13
View File
@@ -41,6 +41,9 @@
#define MAX_CHAIN_MODULES 5 #define MAX_CHAIN_MODULES 5
struct chain;
typedef DoublyLinkedList<chain> ChainList;
struct chain_key { struct chain_key {
int family; int family;
int type; int type;
@@ -61,10 +64,10 @@ struct family {
struct family* next; struct family* next;
int type; int type;
int32 ref_count; int32 ref_count;
struct list chains; ChainList chains;
}; };
struct chain { struct chain : DoublyLinkedListLinkImpl<chain> {
chain(int family, int type, int protocol); chain(int family, int type, int protocol);
~chain(); ~chain();
@@ -83,7 +86,6 @@ struct chain {
static void DeleteChains(hash_table* chains); static void DeleteChains(hash_table* chains);
chain* next; chain* next;
struct list_link family_link;
struct family* parent; struct family* parent;
int family; int family;
@@ -113,7 +115,6 @@ family::family(int _type)
type(_type), type(_type),
ref_count(0) ref_count(0)
{ {
list_init_etc(&chains, offsetof(struct chain, family_link));
} }
@@ -131,14 +132,10 @@ family::Release()
return; return;
TRACE(("family %d unused, uninit chains\n", type)); TRACE(("family %d unused, uninit chains\n", type));
MutexLocker locker(&sChainLock); MutexLocker _(sChainLock);
struct chain* chain = NULL;
while (true) {
chain = (struct chain*)list_get_next_item(&chains, chain);
if (chain == NULL)
break;
ChainList::Iterator iterator = chains.GetIterator();
while (struct chain* chain = iterator.Next()) {
chain->Uninitialize(); chain->Uninitialize();
} }
} }
@@ -208,6 +205,8 @@ chain::chain(int _family, int _type, int _protocol)
if (parent == NULL) if (parent == NULL)
parent = ::family::Add(family); parent = ::family::Add(family);
//parent->chains.Add(this);
for (int32 i = 0; i < MAX_CHAIN_MODULES; i++) { for (int32 i = 0; i < MAX_CHAIN_MODULES; i++) {
modules[i] = NULL; modules[i] = NULL;
infos[i] = NULL; infos[i] = NULL;
@@ -220,6 +219,8 @@ chain::~chain()
for (int32 i = 0; i < MAX_CHAIN_MODULES; i++) { for (int32 i = 0; i < MAX_CHAIN_MODULES; i++) {
free((char*)modules[i]); free((char*)modules[i]);
} }
//parent->chains.Remove(this);
} }
@@ -227,7 +228,7 @@ status_t
chain::Acquire() chain::Acquire()
{ {
if (atomic_add(&ref_count, 1) > 0) { if (atomic_add(&ref_count, 1) > 0) {
if (flags & CHAIN_MISSING_MODULE) { if ((flags & CHAIN_MISSING_MODULE) != 0) {
atomic_add(&ref_count, -1); atomic_add(&ref_count, -1);
return EAFNOSUPPORT; return EAFNOSUPPORT;
} }
@@ -282,7 +283,7 @@ chain::Uninitialize()
return; return;
TRACE(("uninit chain %d.%d.%d\n", family, type, protocol)); TRACE(("uninit chain %d.%d.%d\n", family, type, protocol));
MutexLocker locker(sInitializeChainLock); MutexLocker _(sInitializeChainLock);
for (int32 i = 0; modules[i] != NULL; i++) { for (int32 i = 0; modules[i] != NULL; i++) {
put_module(modules[i]); put_module(modules[i]);