1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright 2014 Couchbase, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #ifndef NETBUF_DEFS_H 19 #define NETBUF_DEFS_H 20 21 typedef struct netbuf_st nb_MGR; 22 typedef unsigned int nb_SIZE; 23 24 /** 25 * @file 26 * Netbuf Core Structures 27 * @addtogroup netbufs 28 * @{ 29 */ 30 31 /** 32 * @name Cache Allocation 33 * @{ 34 * 35 * The following settings control the default allocation policy. 36 * Each allocator pool has both blocks and the amount of data per block. 37 * 38 * Multiple blocks help with cache locality when traversing, while large 39 * data segements allow each individual element to be spaced near the next. 40 */ 41 42 /** @brief How many blocks to preallocate for SNDQ elements, per manager */ 43 #define NB_SNDQ_CACHEBLOCKS 4 44 /** @brief How many SNDQELEM structures per block */ 45 #define NB_SNDQ_BASEALLOC 128 46 47 48 /** @brief How many dealloc blocks to allocated per MBLOCK */ 49 #define NB_MBDEALLOC_CACHEBLOCKS 0 50 /** @brief Number of dealloc structures per block */ 51 #define NB_MBDEALLOC_BASEALLOC 24 52 53 54 /** @brief How many data blocks to allocate per manager */ 55 #define NB_DATA_CACHEBLOCKS 16 56 /** @brief Default data allocation size */ 57 #define NB_DATA_BASEALLOC 32768 58 /**@}*/ 59 60 typedef struct { 61 nb_SIZE sndq_cacheblocks; 62 nb_SIZE sndq_basealloc; 63 nb_SIZE dea_cacheblocks; 64 nb_SIZE dea_basealloc; 65 nb_SIZE data_cacheblocks; 66 nb_SIZE data_basealloc; 67 } nb_SETTINGS; 68 69 #ifndef _WIN32 70 typedef struct { 71 void *iov_base; 72 size_t iov_len; 73 } nb_IOV; 74 75 /**Macro which serves as a static initializer for an nb_IOV. This works 76 * on both Windows and Unix despite the layout of the structure being different 77 */ 78 #define NETBUF_IOV_INIT(base, len) { base, len } 79 #else 80 typedef struct { 81 ULONG iov_len; 82 void *iov_base; 83 } nb_IOV; 84 #define NETBUF_IOV_INIT(base, len) { len, base } 85 #endif 86 87 /**@}*/ 88 89 #endif /* NETBUF_DEFS_H */ 90