oic; no need for oc_memb anymore.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/7131b026 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7131b026 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7131b026 Branch: refs/heads/develop Commit: 7131b026faa8806075118abe33d39ae274b669d3 Parents: a2c3b0d Author: Marko Kiiskila <ma...@runtime.io> Authored: Mon Nov 21 17:15:08 2016 -0800 Committer: Marko Kiiskila <ma...@runtime.io> Committed: Mon Nov 21 17:15:50 2016 -0800 ---------------------------------------------------------------------- net/oic/src/api/oc_rep.c | 1 - net/oic/src/messaging/coap/observe.c | 1 - net/oic/src/messaging/coap/transactions.c | 1 - net/oic/src/util/oc_memb.c | 111 -------------------- net/oic/src/util/oc_memb.h | 135 ------------------------- 5 files changed, 249 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7131b026/net/oic/src/api/oc_rep.c ---------------------------------------------------------------------- diff --git a/net/oic/src/api/oc_rep.c b/net/oic/src/api/oc_rep.c index e1b47bf..3465775 100644 --- a/net/oic/src/api/oc_rep.c +++ b/net/oic/src/api/oc_rep.c @@ -21,7 +21,6 @@ #include "config.h" #include "port/oc_assert.h" #include "port/oc_log.h" -#include "util/oc_memb.h" #include "api/oc_priv.h" #include <tinycbor/cbor_buf_writer.h> #include <tinycbor/cbor_buf_reader.h> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7131b026/net/oic/src/messaging/coap/observe.c ---------------------------------------------------------------------- diff --git a/net/oic/src/messaging/coap/observe.c b/net/oic/src/messaging/coap/observe.c index c16823a..c67c0a7 100644 --- a/net/oic/src/messaging/coap/observe.c +++ b/net/oic/src/messaging/coap/observe.c @@ -41,7 +41,6 @@ #include <os/os_mempool.h> #include "observe.h" -#include "util/oc_memb.h" #include "oc_coap.h" #include "oc_rep.h" http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7131b026/net/oic/src/messaging/coap/transactions.c ---------------------------------------------------------------------- diff --git a/net/oic/src/messaging/coap/transactions.c b/net/oic/src/messaging/coap/transactions.c index 4c9df87..c05ba63 100644 --- a/net/oic/src/messaging/coap/transactions.c +++ b/net/oic/src/messaging/coap/transactions.c @@ -40,7 +40,6 @@ #include "observe.h" #include "oc_buffer.h" #include "util/oc_list.h" -#include "util/oc_memb.h" #ifdef OC_CLIENT #include "oc_client_state.h" http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7131b026/net/oic/src/util/oc_memb.c ---------------------------------------------------------------------- diff --git a/net/oic/src/util/oc_memb.c b/net/oic/src/util/oc_memb.c deleted file mode 100644 index 31909a9..0000000 --- a/net/oic/src/util/oc_memb.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2004, Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is part of the Contiki operating system. - * - * Author: Adam Dunkels <a...@sics.se> - * - */ - -#include "oc_memb.h" -#include <string.h> - -/*---------------------------------------------------------------------------*/ -void -oc_memb_init(struct oc_memb *m) -{ - memset(m->count, 0, m->num); - memset(m->mem, 0, (unsigned)m->size * (unsigned)m->num); -} -/*---------------------------------------------------------------------------*/ -void * -oc_memb_alloc(struct oc_memb *m) -{ - int i; - - for (i = 0; i < m->num; ++i) { - if (m->count[i] == 0) { - /* If this block was unused, we increase the reference count to - indicate that it now is used and return a pointer to the - memory block. */ - ++(m->count[i]); - return (void *)((char *)m->mem + (i * m->size)); - } - } - - /* No free block was found, so we return NULL to indicate failure to - allocate block. */ - return NULL; -} -/*---------------------------------------------------------------------------*/ -char -oc_memb_free(struct oc_memb *m, void *ptr) -{ - int i; - char *ptr2; - - /* Walk through the list of blocks and try to find the block to - which the pointer "ptr" points to. */ - ptr2 = (char *)m->mem; - for (i = 0; i < m->num; ++i) { - - if (ptr2 == (char *)ptr) { - /* We've found to block to which "ptr" points so we decrease the - reference count and return the new value of it. */ - if (m->count[i] > 0) { - /* Make sure that we don't deallocate free memory. */ - --(m->count[i]); - } - return m->count[i]; - } - ptr2 += m->size; - } - return -1; -} -/*---------------------------------------------------------------------------*/ -int -oc_memb_inmemb(struct oc_memb *m, void *ptr) -{ - return (char *)ptr >= (char *)m->mem && - (char *)ptr < (char *)m->mem + (m->num * m->size); -} -/*---------------------------------------------------------------------------*/ -int -oc_memb_numfree(struct oc_memb *m) -{ - int i; - int num_free = 0; - - for (i = 0; i < m->num; ++i) { - if (m->count[i] == 0) { - ++num_free; - } - } - - return num_free; -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7131b026/net/oic/src/util/oc_memb.h ---------------------------------------------------------------------- diff --git a/net/oic/src/util/oc_memb.h b/net/oic/src/util/oc_memb.h deleted file mode 100644 index 37ecca6..0000000 --- a/net/oic/src/util/oc_memb.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2004, Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is part of the Contiki operating system. - * - * Author: Adam Dunkels <a...@sics.se> - * - */ - -/** - * \defgroup memb Memory block management functions - * - * The memory block allocation routines provide a simple yet powerful - * set of functions for managing a set of memory blocks of fixed - * size. A set of memory blocks is statically declared with the - * OC_MEMB() macro. Memory blocks are allocated from the declared - * memory by the oc_memb_alloc() function, and are deallocated with the - * oc_memb_free() function. - * - */ - -#ifndef OC_MEMB_H -#define OC_MEMB_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define CC_CONCAT2(s1, s2) s1##s2 -/** - * A C preprocessing macro for concatenating two preprocessor tokens. - * - * We need use two macros (CC_CONCAT and CC_CONCAT2) in order to allow - * concatenation of two \#defined macros. - */ -#define CC_CONCAT(s1, s2) CC_CONCAT2(s1, s2) - -/** - * Declare a memory block. - * - * This macro is used to statically declare a block of memory that can - * be used by the block allocation functions. The macro statically - * declares a C array with a size that matches the specified number of - * blocks and their individual sizes. - * - * Example: - \code - MEMB(connections, struct connection, 16); - \endcode - * - * \param name The name of the memory block (later used with - * oc_memb_init(), oc_memb_alloc() and oc_memb_free()). - * - * \param structure The name of the struct that the memory block holds - * - * \param num The total number of memory chunks in the block. - * - */ -#define OC_MEMB(name, structure, num) \ - static char CC_CONCAT(name, _memb_count)[num]; \ - static structure CC_CONCAT(name, _memb_mem)[num]; \ - static struct oc_memb name = { sizeof(structure), num, \ - CC_CONCAT(name, _memb_count), \ - (void *)CC_CONCAT(name, _memb_mem) } - -struct oc_memb -{ - unsigned short size; - unsigned short num; - char *count; - void *mem; -}; - -/** - * Initialize a memory block that was declared with MEMB(). - * - * \param m A memory block previously declared with MEMB(). - */ -void oc_memb_init(struct oc_memb *m); - -/** - * Allocate a memory block from a block of memory declared with MEMB(). - * - * \param m A memory block previously declared with MEMB(). - */ -void *oc_memb_alloc(struct oc_memb *m); - -/** - * Deallocate a memory block from a memory block previously declared - * with MEMB(). - * - * \param m m A memory block previously declared with MEMB(). - * - * \param ptr A pointer to the memory block that is to be deallocated. - * - * \return The new reference count for the memory block (should be 0 - * if successfully deallocated) or -1 if the pointer "ptr" did not - * point to a legal memory block. - */ -char oc_memb_free(struct oc_memb *m, void *ptr); - -int oc_memb_inmemb(struct oc_memb *m, void *ptr); - -int oc_memb_numfree(struct oc_memb *m); - -#ifdef __cplusplus -} -#endif - -#endif /* OC_MEMB_H */