diff options
author | Chris Hall (GMCH) <chris.hall@highwayman.com> | 2009-12-02 17:08:59 +0000 |
---|---|---|
committer | Chris Hall (GMCH) <chris.hall@highwayman.com> | 2009-12-02 17:08:59 +0000 |
commit | db597018b8c47208e4139b75fdcd798505695ea8 (patch) | |
tree | f5fa021d7d72d726f6a5cf8812e8123649d21041 /lib/heap.h | |
parent | 02e6e018111e39e9445f54eda6d61a24ea9f41ee (diff) | |
download | quagga-db597018b8c47208e4139b75fdcd798505695ea8.tar.bz2 quagga-db597018b8c47208e4139b75fdcd798505695ea8.tar.xz |
Pthreads infrastructure -- initial commit
New files: lib/qpthreads.c & .h
Encapsulates the Pthreads facilities to be used in Quagga.
Implicitly documents the sub-set of Pthreads being used.
Provides error checking for a number of functions which may return
errors, but are not generally expected to and for whom an error is
treated as fatal.
Could be modified to "null out" the use of Pthreads.
New files: lib/qtime.c & .h
Defines a 64-bit integer time value which is a lot easier to
handle than the usual timespec and timeval structures. (C99
requires a 64-bit integer.)
Provides front ends for gettimeofday() & clock_gettime() which
return 64-bit time value. Also conversions to and from timespec and
timeval.
Provides a monotonic clock for when CLOCK_MONOTONIC is not available.
(This is based on code from Joakim Tjernlund.)
New files: lib/heap.c & .h
Implements a heap data structure closely allied to the vector.
This will be used for timer handling.
Modified: lib/memtypes.c
New memory types for qpthreads structures and for the heap.
Modified: lib/zassert.h
Added explicit "passert" == assert which is not subject to NDEBUG.
Added explicit "nassert" == assert which is subject to NDEBUG.
Added zabort, zabort_errno and zabbort_err for when something has
gone fatally wrong. (Require changes to lib/log.c which are TBD.)
Diffstat (limited to 'lib/heap.h')
-rw-r--r-- | lib/heap.h | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/lib/heap.h b/lib/heap.h new file mode 100644 index 00000000..d91fff4a --- /dev/null +++ b/lib/heap.h @@ -0,0 +1,96 @@ +/* Generic heap data structure -- header. + * Copyright (C) 2009 Chris Hall (GMCH), Highwayman + *. + * This file is part of GNU Zebra. + * + * GNU Zebra is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Zebra; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifndef _ZEBRA_HEAP_H +#define _ZEBRA_HEAP_H + +#include "vector.h" + +/* Macro in case there are particular compiler issues. */ +#ifndef Inline + #define Inline static inline +#endif + +typedef int heap_cmp(p_vector_item* a, p_vector_item*) ; + +enum heap_state { + Heap_Has_Backlink = 0x01, /* Set if backlink set */ +}; + +struct heap +{ + heap_cmp* cmp ; + + enum heap_state state ; + unsigned int backlink_offset ; + + struct vector v ; +}; + +typedef struct heap* heap; + +typedef vector_index heap_backlink_t ; + +/* Prototypes. */ + +extern heap heap_init_new(heap h, vector_index size, heap_cmp* cmp, + int with_backlink, unsigned int backlink_offset) ; +#define heap_init_new_simple(h, size, cmp) \ + heap_init_new(h, size, cmp, 0, 0) +#define heap_init_new_backlinked(h, size, cmp, off) \ + heap_init_new(h, size, cmp, 1, off) + +extern heap heap_re_init(heap h, vector_index size, heap_cmp* cmp, + int with_backlink, unsigned int backlink_offset) ; +#define heap_re_init_simple(h, size, cmp) \ + heap_re_init(h, size, cmp, 0, 0) +#define heap_re_init_backlinked(h, size, cmp, off) \ + heap_re_init(h, size, cmp, 1, off) + +extern heap heap_reset(heap h, int free_structure) ; +extern p_vector_item heap_ream(heap h, int free_structure) ; + +/* Reset heap and free the heap structure. */ +#define heap_reset_free(h) heap_reset(h, 1) ; +/* Reset heap but keep the heap structure. */ +#define heap_reset_keep(h) heap_reset(h, 0) ; +/* Ream out heap and free the heap structure. */ +#define heap_ream_free(h) heap_ream_out(h, 1) ; +/* Ream out heap but keep the heap structure. */ +#define heap_ream_keep(h) heap_ream_out(h, 0) ; + +extern void heap_push_item(heap h, p_vector_item p_v) ; +extern p_vector_item heap_pop_item(heap h) ; +extern p_vector_item heap_top_item(heap h) ; +extern void heap_update_top_item(heap h) ; + +extern void heap_delete_item(heap h, p_vector_item p_v) ; +extern void heap_update_item(heap h, p_vector_item p_v) ; + +extern void heap_push_vector(heap h, vector v, int move_vector) ; +#define heap_push_vector_copy(h, v) \ + heap_push_vector(h, v, 0) +#define heap_push_vector_move(h, v) \ + heap_push_vector(h, v, 1) +extern vector heap_pop_vector(vector v, heap h, int move_heap) ; +#define heap_pop_vector_copy(v, h) \ + heap_pop_vector(v, h, 0) +#define heap_pop_vector_move(v, h) \ + heap_pop_vector(v, h, 1) + +extern vector heap_vector(heap h, int unset_heap_order) ; + +#endif /* _ZEBRA_HEAP_H */ |