diff --git a/src/add-ons/kernel/network/stack/datalink.cpp b/src/add-ons/kernel/network/stack/datalink.cpp index 8c24e5a8ac..1402236c8b 100644 --- a/src/add-ons/kernel/network/stack/datalink.cpp +++ b/src/add-ons/kernel/network/stack/datalink.cpp @@ -47,13 +47,16 @@ device_reader_thread(void *_interface) net_device *device = interface->device; status_t status = B_OK; - RecursiveLocker rx_lock(interface->rx_lock); + RecursiveLocker locker(interface->rx_lock); while (device->flags & IFF_UP) { + locker.Unlock(); + net_buffer *buffer; - rx_lock.Unlock(); status = device->module->receive_data(device, &buffer); - rx_lock.Lock(); + + locker.Lock(); + if (status == B_OK) { // feed device monitors DeviceMonitorList::Iterator iterator = diff --git a/src/add-ons/kernel/network/stack/net_buffer.cpp b/src/add-ons/kernel/network/stack/net_buffer.cpp index c317355145..42a0589858 100644 --- a/src/add-ons/kernel/network/stack/net_buffer.cpp +++ b/src/add-ons/kernel/network/stack/net_buffer.cpp @@ -309,7 +309,24 @@ get_node_at_offset(net_buffer_private *buffer, size_t offset) } -// #pragma mark - +static void +copy_metadata(net_buffer *destination, const net_buffer *source) +{ + memcpy(destination->source, source->source, + min_c(source->source->sa_len, sizeof(sockaddr_storage))); + memcpy(destination->destination, source->destination, + min_c(source->destination->sa_len, sizeof(sockaddr_storage))); + + destination->flags = source->flags; + destination->interface = source->interface; + destination->offset = source->offset; + destination->size = source->size; + destination->protocol = source->protocol; + destination->type = source->type; +} + + +// #pragma mark - module API static net_buffer * @@ -367,23 +384,6 @@ free_buffer(net_buffer *_buffer) } -static void -copy_metadata(net_buffer *destination, const net_buffer *source) -{ - memcpy(destination->source, source->source, - min_c(source->source->sa_len, sizeof(sockaddr_storage))); - memcpy(destination->destination, source->destination, - min_c(source->destination->sa_len, sizeof(sockaddr_storage))); - - destination->flags = source->flags; - destination->interface = source->interface; - destination->offset = source->offset; - destination->size = source->size; - destination->protocol = source->protocol; - destination->type = source->type; -} - - /*! Creates a duplicate of the \a buffer. The new buffer does not share internal storage; they are completely independent from each other. */ @@ -1185,44 +1185,31 @@ swap_addresses(net_buffer *buffer) } -status_t -init_net_buffers() -{ - // TODO improve our code a bit so we can add constructors - // and keep around half-constructed buffers in the slab - - sNetBufferCache = create_object_cache("net buffer cache", - sizeof(net_buffer_private), 8, NULL, NULL, NULL); - if (sNetBufferCache == NULL) - return B_NO_MEMORY; - - sDataNodeCache = create_object_cache("data node cache", BUFFER_SIZE, 0, - NULL, NULL, NULL); - if (sDataNodeCache == NULL) { - delete_object_cache(sNetBufferCache); - return B_NO_MEMORY; - } - - return B_OK; -} - - -status_t -uninit_net_buffers() -{ - delete_object_cache(sNetBufferCache); - delete_object_cache(sDataNodeCache); - - return B_OK; -} - - static status_t std_ops(int32 op, ...) { switch (op) { case B_MODULE_INIT: + // TODO: improve our code a bit so we can add constructors + // and keep around half-constructed buffers in the slab + + sNetBufferCache = create_object_cache("net buffer cache", + sizeof(net_buffer_private), 8, NULL, NULL, NULL); + if (sNetBufferCache == NULL) + return B_NO_MEMORY; + + sDataNodeCache = create_object_cache("data node cache", BUFFER_SIZE, + 0, NULL, NULL, NULL); + if (sDataNodeCache == NULL) { + delete_object_cache(sNetBufferCache); + return B_NO_MEMORY; + } + + return B_OK; + case B_MODULE_UNINIT: + delete_object_cache(sNetBufferCache); + delete_object_cache(sDataNodeCache); return B_OK; default: diff --git a/src/add-ons/kernel/network/stack/stack.cpp b/src/add-ons/kernel/network/stack/stack.cpp index 9fc731e34e..777384e806 100644 --- a/src/add-ons/kernel/network/stack/stack.cpp +++ b/src/add-ons/kernel/network/stack/stack.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -785,10 +785,6 @@ init_stack() goto err8; } - status = init_net_buffers(); - if (status < B_OK) - goto err9; - sInitialized = true; link_init(); @@ -806,8 +802,6 @@ init_stack() return B_OK; -err9: - hash_uninit(sReceivingProtocolChains); err8: hash_uninit(sDatalinkProtocolChains); err7: @@ -837,8 +831,6 @@ uninit_stack() uninit_interfaces(); uninit_domains(); - uninit_net_buffers(); - benaphore_destroy(&sChainLock); benaphore_destroy(&sInitializeChainLock); diff --git a/src/add-ons/kernel/network/stack/stack_private.h b/src/add-ons/kernel/network/stack/stack_private.h index 838f3aa85d..9c047c43a4 100644 --- a/src/add-ons/kernel/network/stack/stack_private.h +++ b/src/add-ons/kernel/network/stack/stack_private.h @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -33,8 +33,4 @@ status_t put_domain_protocols(net_socket *socket); status_t get_domain_datalink_protocols(net_interface *interface); status_t put_domain_datalink_protocols(net_interface *interface); -// net_buffer.cpp -status_t init_net_buffers(); -status_t uninit_net_buffers(); - #endif // STACK_PRIVATE_H