* Cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29591 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-03-18 16:16:05 +00:00
parent 7ce5cc5505
commit b93ed02c5a
+22 -21
View File
@@ -1,13 +1,8 @@
/* /*
* Copyright 2007, Hugo Santos. All Rights Reserved. * Copyright 2007, Hugo Santos. All Rights Reserved.
* Copyright 2004, Marcus Overhagen. All Rights Reserved.
*
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*
* Authors:
* Hugo Santos, [email protected]
*
* Some of this code is based on previous work by Marcus Overhagen.
*
* `m_defrag' and friends are straight from FreeBSD 6.2.
*/ */
#include "device.h" #include "device.h"
@@ -19,16 +14,19 @@
#include <compat/sys/mbuf.h> #include <compat/sys/mbuf.h>
#include <compat/sys/kernel.h> #include <compat/sys/kernel.h>
static object_cache *sMBufCache; static object_cache *sMBufCache;
static object_cache *sChunkCache; static object_cache *sChunkCache;
static object_cache *sJumbo9ChunkCache; static object_cache *sJumbo9ChunkCache;
int max_linkhdr = 16; int max_linkhdr = 16;
int max_protohdr = 40 + 20; /* ip6 + tcp */ int max_protohdr = 40 + 20; /* ip6 + tcp */
/* max_linkhdr + max_protohdr, but that's not allowed by gcc. */ /* max_linkhdr + max_protohdr, but that's not allowed by gcc. */
int max_hdr = 16 + 40 + 20; int max_hdr = 16 + 40 + 20;
static int static int
m_to_oc_flags(int how) m_to_oc_flags(int how)
{ {
@@ -64,30 +62,30 @@ static int
construct_ext_sized_mbuf(struct mbuf *mb, int how, int size) construct_ext_sized_mbuf(struct mbuf *mb, int how, int size)
{ {
object_cache *cache; object_cache *cache;
int ext_type; int extType;
if (size != MCLBYTES && size != MJUM9BYTES) if (size != MCLBYTES && size != MJUM9BYTES)
panic("unsupported size"); panic("unsupported size");
if (size == MCLBYTES) { if (size == MCLBYTES) {
cache = sChunkCache; cache = sChunkCache;
ext_type = EXT_CLUSTER; extType = EXT_CLUSTER;
} else { } else {
cache = sJumbo9ChunkCache; cache = sJumbo9ChunkCache;
ext_type = EXT_JUMBO9; extType = EXT_JUMBO9;
} }
mb->m_ext.ext_buf = object_cache_alloc(cache, m_to_oc_flags(how)); mb->m_ext.ext_buf = object_cache_alloc(cache, m_to_oc_flags(how));
if (mb->m_ext.ext_buf == NULL) if (mb->m_ext.ext_buf == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
mb->m_data = mb->m_ext.ext_buf; mb->m_data = mb->m_ext.ext_buf;
mb->m_flags |= M_EXT; mb->m_flags |= M_EXT;
/* mb->m_ext.ext_free = NULL; */ /* mb->m_ext.ext_free = NULL; */
/* mb->m_ext.ext_args = NULL; */ /* mb->m_ext.ext_args = NULL; */
mb->m_ext.ext_size = size; mb->m_ext.ext_size = size;
mb->m_ext.ext_type = ext_type; mb->m_ext.ext_type = extType;
/* mb->m_ext.ref_cnt = NULL; */ /* mb->m_ext.ref_cnt = NULL; */
return 0; return 0;
} }
@@ -113,12 +111,15 @@ static void
destruct_pkt_mbuf(struct mbuf *mb) destruct_pkt_mbuf(struct mbuf *mb)
{ {
object_cache *cache; object_cache *cache;
if (mb->m_ext.ext_type & EXT_CLUSTER) if ((mb->m_ext.ext_type & EXT_CLUSTER) != 0)
cache = sChunkCache; cache = sChunkCache;
else if (mb->m_ext.ext_type & EXT_JUMBO9) else if ((mb->m_ext.ext_type & EXT_JUMBO9) != 0)
cache = sJumbo9ChunkCache; cache = sJumbo9ChunkCache;
else else {
panic("unknown cache"); panic("unknown cache");
return;
}
object_cache_free(cache, mb->m_ext.ext_buf); object_cache_free(cache, mb->m_ext.ext_buf);
mb->m_ext.ext_buf = NULL; mb->m_ext.ext_buf = NULL;
} }
@@ -220,7 +221,7 @@ mb_free_ext(struct mbuf *m)
/* /*
if (m->m_ext.ref_count != NULL) if (m->m_ext.ref_count != NULL)
panic("unsupported"); panic("unsupported");
*/ */
if (m->m_ext.ext_type == EXT_PACKET) if (m->m_ext.ext_type == EXT_PACKET)
destruct_pkt_mbuf(m); destruct_pkt_mbuf(m);
@@ -261,7 +262,7 @@ m_extadd(struct mbuf *m, caddr_t buffer, u_int size,
status_t status_t
init_mbufs() init_mbufs(void)
{ {
sMBufCache = create_object_cache("mbufs", MSIZE, 8, NULL, NULL, NULL); sMBufCache = create_object_cache("mbufs", MSIZE, 8, NULL, NULL, NULL);
if (sMBufCache == NULL) if (sMBufCache == NULL)
@@ -270,8 +271,8 @@ init_mbufs()
NULL); NULL);
if (sChunkCache == NULL) if (sChunkCache == NULL)
goto clean; goto clean;
sJumbo9ChunkCache = create_object_cache("mbuf jumbo9 chunks", MJUM9BYTES, 0, NULL, NULL, sJumbo9ChunkCache = create_object_cache("mbuf jumbo9 chunks", MJUM9BYTES, 0,
NULL); NULL, NULL, NULL);
if (sJumbo9ChunkCache == NULL) if (sJumbo9ChunkCache == NULL)
goto clean; goto clean;
return B_OK; return B_OK;
@@ -286,7 +287,7 @@ clean:
void void
uninit_mbufs() uninit_mbufs(void)
{ {
delete_object_cache(sMBufCache); delete_object_cache(sMBufCache);
delete_object_cache(sChunkCache); delete_object_cache(sChunkCache);