move util library into ddsrt
As was the plan with the introduction of ddsrt; this includes renaming the identifiers to match the capitalization style and removes old junk. Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
parent
e965df5db7
commit
6c171a890d
62 changed files with 1702 additions and 1869 deletions
359
src/ddsrt/include/dds/ddsrt/avl.h
Normal file
359
src/ddsrt/include/dds/ddsrt/avl.h
Normal file
|
@ -0,0 +1,359 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef DDSRT_AVL_H
|
||||
#define DDSRT_AVL_H
|
||||
|
||||
/* The tree library never performs memory allocations or deallocations internally.
|
||||
|
||||
- Treedef_t: defines the properties of the tree, offsets,
|
||||
comparison functions, augmented structures, flags -- these are
|
||||
related to the code/data structure in which the tree is embedded,
|
||||
and in nearly all cases known at compile time.
|
||||
- avlTree_t: represents the tree, i.e., pointer to the root.
|
||||
- avlNode_t: contains the administrative data for a single node in
|
||||
the tree.
|
||||
|
||||
For a tree node:
|
||||
struct T {
|
||||
avlNode_t avlnode;
|
||||
int key;
|
||||
};
|
||||
by definition, avlnodeoffset == offsetof(struct T, avlnode) and
|
||||
keyoffset = offsetof(struct T, key). The user of the library only
|
||||
ever deals in pointers to (in this case) struct T, never with
|
||||
pointers to the avlNode_t, and the compare function operations on
|
||||
pointers to keys, in this case pointers to "int"s. If you wish, you
|
||||
can also do: keyoffset = 0, in which case the compare function
|
||||
would be operating on struct T's.
|
||||
|
||||
The compare function is assumed to behave just like all compare
|
||||
functions in the C library: < 0, =0, >0 for left argument less
|
||||
than, equal to or greater than the right argument.
|
||||
|
||||
The "augment" function is automatically called whenever some of the
|
||||
children of a node change, as well as when the "augment" function
|
||||
has been called on some of the children. It allows you to maintain
|
||||
a "summary" of the subtree -- currently only used in ddsi2e, in one
|
||||
spot.
|
||||
|
||||
Trees come in various "variants", configured through "treedef"
|
||||
flags:
|
||||
- direct/indirect key: direct meaning the key value is embedded in
|
||||
the structure containing the avlNode_t, indirect meaning a
|
||||
pointer to the key value is. The compare function doesn't deal
|
||||
with tree nodes, but with key values.
|
||||
- re-entrant: in the style of the C library, meaning, the
|
||||
comparison function gets a user-supplied 3rd argument (in
|
||||
particular used by mmstat).
|
||||
- unique keys/duplicate keys: when keys must be unique, some
|
||||
optimizations apply; it is up to the caller to ensure one doesn't
|
||||
violate the uniqueness of the keys (it'll happily crash in insert
|
||||
if you don't); when duplicate keys are allowed, a forward scan of
|
||||
the tree will visit them in the order of insertion.
|
||||
|
||||
For a tree node:
|
||||
struct T {
|
||||
avlnode_t avlnode;
|
||||
char *key;
|
||||
};
|
||||
you could set the "indirect" flag, and then you simply use
|
||||
strcmp(), avoiding the need for passing templates in looking up key
|
||||
values. Much nicer.
|
||||
|
||||
There is also an orthogonal variant that is enforced through the
|
||||
type system -- note that would be possible for all of the above as
|
||||
well, but the number of cases simply explodes and none of the above
|
||||
flags affects the dynamically changing data structures (just the
|
||||
tree definition), unlike this one.
|
||||
|
||||
- the "C" variant keeps track of the number of nodes in the tree to
|
||||
support a "count" operation in O(1) time, but is otherwise
|
||||
identical.
|
||||
|
||||
The various initializer macros and TreedefInit functions should
|
||||
make sense with this.
|
||||
|
||||
All functions for looking up nodes return NULL if there is no node
|
||||
satisfying the requirements.
|
||||
|
||||
- Init: initializes a tree (really just: root = NULL, perhaps count = 0)
|
||||
- Free: calls "freefun" on each node, which may free the node
|
||||
- FreeArg: as "Free", but with an extra, user-supplied, argument
|
||||
- Root: returns the root node
|
||||
- Lookup: returns a node with key value "key" (ref allowdups flag)
|
||||
- LookupIPath: like Lookup, but also filling an IPath_t structure
|
||||
for efficient insertion in case of a failed lookup (or inserting
|
||||
duplicates)
|
||||
- LookupDPath: like Lookup, but also filling a DPath_t structure
|
||||
that helps with deleting a node
|
||||
- LookupPredEq: locates the node with the greatest key value <= "key"
|
||||
- LookupSuccEq: similar, but smallest key value >= "key"
|
||||
- LookupPred: similar, < "key"
|
||||
- LookupSucc: similar, > "key"
|
||||
- Insert: convenience function: LookupIPath ; InsertIPath
|
||||
- Delete: convenience function: LookupDPath ; DeleteDPath
|
||||
- InsertIPath: insert node based on the "path" obtained from LookupIPath
|
||||
- DeleteDPath: delete node, using information in "path" to do so efficiently
|
||||
- SwapNode: replace "oldn" by "newn" without modifying the tree
|
||||
structure (the key need not be equal, but must be
|
||||
FindPred(oldn).key < newn.key < FindSucc(oldn).key, where a
|
||||
non-existing predecessor has key -inf and a non-existing
|
||||
successor has key +inf, and where it is understood that the <
|
||||
operator becomes <= if allowdups is set
|
||||
- AugmentUpdate: to be called when something in "node" changes that
|
||||
affects the subtree "summary" computed by the configured
|
||||
"augment" function
|
||||
- IsEmpty: returns 1 if tree is empty, 0 if not
|
||||
- IsSingleton: returns 1 if tree contains exactly one node, 0 if not
|
||||
- FindMin: returns the node with the smallest key value in the tree
|
||||
- FindMax: similar, largest key value
|
||||
- FindPred: preceding node in in-order treewalk
|
||||
- FindSucc: similar, following node
|
||||
|
||||
- Walk: calls "f" with user-supplied argument "a" once for each
|
||||
node, starting at FindMin and ending at FindMax
|
||||
- ConstWalk: same, but with a const tree
|
||||
- WalkRange: like Walk, but only visiting nodes with key values in
|
||||
range [min,max] (that's inclusive)
|
||||
- ConstWalkRange: same, but with a const tree
|
||||
- WalkRangeReverse: like WalkRange, but in the reverse direction
|
||||
- ConstWalkRangeReverse: same, but with a const tree
|
||||
- IterFirst: starts forward iteration, starting at (and returning) FindMin
|
||||
- IterSuccEq: similar, starting at LookupSuccEq
|
||||
- IterSucc: similar, starting at LookupSucc
|
||||
- IterNext: returns FindSucc(last returned node); may not be called
|
||||
if preceding IterXXX call on same "iter" returned NULL
|
||||
|
||||
That's all there is to it.
|
||||
|
||||
Note that all calls to Walk(f,a) can be rewritten as:
|
||||
for(n=IterFirst(&it); n; n=IterNext(&it)) { f(n,a) }
|
||||
or as
|
||||
for(n=FindMin(); n; n=FindSucc(n)) { f(n,a) }
|
||||
|
||||
The walk functions and iterators may not alter the tree
|
||||
structure. If that is desired, the latter can easily be rewritten
|
||||
as:
|
||||
n=FindMin() ; while(n) { nn=FindSucc(n); f(n,a); n=nn }
|
||||
because FindMin/FindSucc doesn't store any information to allow
|
||||
fast processing. That'll allow every operation, with the obvious
|
||||
exception of f(n) calling Delete(FindSucc(n)).
|
||||
|
||||
Currently, all trees maintain parent pointers, but it may be worth
|
||||
doing a separate set without it, as it reduces the size of
|
||||
avlNode_t. But in that case, the FindMin/FindSucc option would no
|
||||
longer be a reasonable option because it would be prohibitively
|
||||
expensive, whereas the IterFirst/IterNext option are alway
|
||||
efficiently. If one were to do a threaded tree variant, the
|
||||
implemetantion of IterFirst/IterNext would become absolute trivial
|
||||
and faster still, but at the cost of significantly more overhead in
|
||||
memory and updates. */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "dds/export.h"
|
||||
#include "dds/ddsrt/attributes.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define DDSRT_AVL_MAX_TREEHEIGHT (12 * sizeof (void *))
|
||||
|
||||
typedef int (*ddsrt_avl_compare_t) (const void *a, const void *b);
|
||||
typedef int (*ddsrt_avl_compare_r_t) (const void *a, const void *b, void *arg);
|
||||
typedef void (*ddsrt_avl_augment_t) (void *node, const void *left, const void *right);
|
||||
typedef void (*ddsrt_avl_walk_t) (void *node, void *arg);
|
||||
typedef void (*ddsrt_avl_const_walk_t) (const void *node, void *arg);
|
||||
|
||||
typedef struct ddsrt_avl_node {
|
||||
struct ddsrt_avl_node *cs[2]; /* 0 = left, 1 = right */
|
||||
struct ddsrt_avl_node *parent;
|
||||
int height;
|
||||
} ddsrt_avl_node_t;
|
||||
|
||||
#define DDSRT_AVL_TREEDEF_FLAG_INDKEY 1
|
||||
#define DDSRT_AVL_TREEDEF_FLAG_R 2
|
||||
#define DDSRT_AVL_TREEDEF_FLAG_ALLOWDUPS 4
|
||||
|
||||
typedef struct ddsrt_avl_treedef {
|
||||
#if defined (__cplusplus)
|
||||
ddsrt_avl_treedef() {}
|
||||
#endif
|
||||
size_t avlnodeoffset;
|
||||
size_t keyoffset;
|
||||
union {
|
||||
ddsrt_avl_compare_t comparekk;
|
||||
ddsrt_avl_compare_r_t comparekk_r;
|
||||
} u;
|
||||
ddsrt_avl_augment_t augment;
|
||||
uint32_t flags;
|
||||
void *cmp_arg; /* for _r variant */
|
||||
} ddsrt_avl_treedef_t;
|
||||
|
||||
typedef struct ddsrt_avl_ctreedef {
|
||||
ddsrt_avl_treedef_t t;
|
||||
} ddsrt_avl_ctreedef_t;
|
||||
|
||||
typedef struct ddsrt_avl_tree {
|
||||
ddsrt_avl_node_t *root;
|
||||
} ddsrt_avl_tree_t;
|
||||
|
||||
typedef struct ddsrt_avl_ctree {
|
||||
ddsrt_avl_tree_t t;
|
||||
size_t count;
|
||||
} ddsrt_avl_ctree_t;
|
||||
|
||||
typedef struct ddsrt_avl_path {
|
||||
int depth; /* total depth of path */
|
||||
int pnodeidx;
|
||||
ddsrt_avl_node_t *parent; /* (nodeidx == 0 ? NULL : *(path[nodeidx-1])) */
|
||||
ddsrt_avl_node_t **pnode[DDSRT_AVL_MAX_TREEHEIGHT];
|
||||
} ddsrt_avl_path_t;
|
||||
|
||||
typedef struct ddsrt_avl_ipath {
|
||||
ddsrt_avl_path_t p;
|
||||
} ddsrt_avl_ipath_t;
|
||||
|
||||
typedef struct ddsrt_avl_dpath {
|
||||
ddsrt_avl_path_t p;
|
||||
} ddsrt_avl_dpath_t;
|
||||
|
||||
typedef struct ddsrt_avl_iter {
|
||||
const ddsrt_avl_treedef_t *td;
|
||||
ddsrt_avl_node_t *right;
|
||||
ddsrt_avl_node_t **todop;
|
||||
ddsrt_avl_node_t *todo[1+DDSRT_AVL_MAX_TREEHEIGHT];
|
||||
} ddsrt_avl_iter_t;
|
||||
|
||||
typedef struct ddsrt_avl_citer {
|
||||
ddsrt_avl_iter_t t;
|
||||
} ddsrt_avl_citer_t;
|
||||
|
||||
/* avlnodeoffset and keyoffset must both be in [0,2**31-1] */
|
||||
#define DDSRT_AVL_TREEDEF_INITIALIZER(avlnodeoffset, keyoffset, comparekk_, augment) { (avlnodeoffset), (keyoffset), { .comparekk = (comparekk_) }, (augment), 0, 0 }
|
||||
#define DDSRT_AVL_TREEDEF_INITIALIZER_INDKEY(avlnodeoffset, keyoffset, comparekk_, augment) { (avlnodeoffset), (keyoffset), { .comparekk = (comparekk_) }, (augment), DDSRT_AVL_TREEDEF_FLAG_INDKEY, 0 }
|
||||
#define DDSRT_AVL_TREEDEF_INITIALIZER_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk_, augment) { (avlnodeoffset), (keyoffset), { .comparekk = (comparekk_) }, (augment), DDSRT_AVL_TREEDEF_FLAG_ALLOWDUPS, 0 }
|
||||
#define DDSRT_AVL_TREEDEF_INITIALIZER_INDKEY_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk_, augment) { (avlnodeoffset), (keyoffset), { .comparekk = (comparekk_) }, (augment), DDSRT_AVL_TREEDEF_FLAG_INDKEY|DDSRT_AVL_TREEDEF_FLAG_ALLOWDUPS, 0 }
|
||||
#define DDSRT_AVL_TREEDEF_INITIALIZER_R(avlnodeoffset, keyoffset, comparekk_, cmparg, augment) { (avlnodeoffset), (keyoffset), { .comparekk_r = (comparekk_) }, (augment), DDSRT_AVL_TREEDEF_FLAG_R, (cmparg) }
|
||||
#define DDSRT_AVL_TREEDEF_INITIALIZER_INDKEY_R(avlnodeoffset, keyoffset, comparekk_, cmparg, augment) { (avlnodeoffset), (keyoffset), { .comparekk_r = (comparekk_) }, (augment), DDSRT_AVL_TREEDEF_FLAG_INDKEY|DDSRT_AVL_TREEDEF_FLAG_R, (cmparg) }
|
||||
#define DDSRT_AVL_TREEDEF_INITIALIZER_R_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk_, cmparg, augment) { (avlnodeoffset), (keyoffset), { .comparekk_r = (comparekk_) }, (augment), DDSRT_AVL_TREEDEF_FLAG_R|DDSRT_AVL_TREEDEF_FLAG_ALLOWDUPS, (cmparg) }
|
||||
#define DDSRT_AVL_TREEDEF_INITIALIZER_INDKEY_R_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk_, cmparg, augment) { (avlnodeoffset), (keyoffset), { .comparekk_r = (comparekk_) }, (augment), DDSRT_AVL_TREEDEF_FLAG_INDKEY|DDSRT_AVL_TREEDEF_FLAG_R|DDSRT_AVL_TREEDEF_FLAG_ALLOWDUPS, (cmparg) }
|
||||
|
||||
/* Not maintaining # nodes */
|
||||
|
||||
DDS_EXPORT void ddsrt_avl_treedef_init (ddsrt_avl_treedef_t *td, size_t avlnodeoffset, size_t keyoffset, ddsrt_avl_compare_t comparekk, ddsrt_avl_augment_t augment, uint32_t flags) ddsrt_nonnull((1,4));
|
||||
DDS_EXPORT void ddsrt_avl_treedef_init_r (ddsrt_avl_treedef_t *td, size_t avlnodeoffset, size_t keyoffset, ddsrt_avl_compare_r_t comparekk_r, void *cmp_arg, ddsrt_avl_augment_t augment, uint32_t flags) ddsrt_nonnull((1,4));
|
||||
|
||||
DDS_EXPORT void ddsrt_avl_init (const ddsrt_avl_treedef_t *td, ddsrt_avl_tree_t *tree) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void ddsrt_avl_free (const ddsrt_avl_treedef_t *td, ddsrt_avl_tree_t *tree, void (*freefun) (void *node)) ddsrt_nonnull((1,2));
|
||||
DDS_EXPORT void ddsrt_avl_free_arg (const ddsrt_avl_treedef_t *td, ddsrt_avl_tree_t *tree, void (*freefun) (void *node, void *arg), void *arg) ddsrt_nonnull((1,2));
|
||||
|
||||
DDS_EXPORT void *ddsrt_avl_root (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_root_non_empty (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_lookup (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree, const void *key) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_lookup_ipath (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree, const void *key, ddsrt_avl_ipath_t *path) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_lookup_dpath (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree, const void *key, ddsrt_avl_dpath_t *path) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_lookup_pred_eq (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree, const void *key) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_lookup_succ_eq (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree, const void *key) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_lookup_pred (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree, const void *key) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_lookup_succ (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree, const void *key) ddsrt_nonnull_all;
|
||||
|
||||
DDS_EXPORT void ddsrt_avl_insert (const ddsrt_avl_treedef_t *td, ddsrt_avl_tree_t *tree, void *node) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void ddsrt_avl_delete (const ddsrt_avl_treedef_t *td, ddsrt_avl_tree_t *tree, void *node) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void ddsrt_avl_insert_ipath (const ddsrt_avl_treedef_t *td, ddsrt_avl_tree_t *tree, void *node, ddsrt_avl_ipath_t *path) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void ddsrt_avl_delete_dpath (const ddsrt_avl_treedef_t *td, ddsrt_avl_tree_t *tree, void *node, ddsrt_avl_dpath_t *path) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void ddsrt_avl_swap_node (const ddsrt_avl_treedef_t *td, ddsrt_avl_tree_t *tree, void *oldn, void *newn) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void ddsrt_avl_augment_update (const ddsrt_avl_treedef_t *td, void *node) ddsrt_nonnull_all;
|
||||
|
||||
DDS_EXPORT int ddsrt_avl_is_empty (const ddsrt_avl_tree_t *tree) ddsrt_nonnull_all;
|
||||
DDS_EXPORT int ddsrt_avl_is_singleton (const ddsrt_avl_tree_t *tree) ddsrt_nonnull_all;
|
||||
|
||||
DDS_EXPORT void *ddsrt_avl_find_min (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_find_max (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_find_pred (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree, const void *vnode) ddsrt_nonnull((1,2));
|
||||
DDS_EXPORT void *ddsrt_avl_find_succ (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree, const void *vnode) ddsrt_nonnull((1,2));
|
||||
|
||||
DDS_EXPORT void ddsrt_avl_walk (const ddsrt_avl_treedef_t *td, ddsrt_avl_tree_t *tree, ddsrt_avl_walk_t f, void *a) ddsrt_nonnull((1,2,3));
|
||||
DDS_EXPORT void ddsrt_avl_const_walk (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree, ddsrt_avl_const_walk_t f, void *a) ddsrt_nonnull((1,2,3));
|
||||
DDS_EXPORT void ddsrt_avl_walk_range (const ddsrt_avl_treedef_t *td, ddsrt_avl_tree_t *tree, const void *min, const void *max, ddsrt_avl_walk_t f, void *a) ddsrt_nonnull((1,2,3,4,5));
|
||||
DDS_EXPORT void ddsrt_avl_const_walk_range (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree, const void *min, const void *max, ddsrt_avl_const_walk_t f, void *a) ddsrt_nonnull((1,2,3,4,5));
|
||||
DDS_EXPORT void ddsrt_avl_walk_range_reverse (const ddsrt_avl_treedef_t *td, ddsrt_avl_tree_t *tree, const void *min, const void *max, ddsrt_avl_walk_t f, void *a) ddsrt_nonnull((1,2,3));
|
||||
DDS_EXPORT void ddsrt_avl_const_walk_range_reverse (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree, const void *min, const void *max, ddsrt_avl_const_walk_t f, void *a) ddsrt_nonnull((1,2,3));
|
||||
|
||||
DDS_EXPORT void *ddsrt_avl_iter_first (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree, ddsrt_avl_iter_t *iter) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_iter_succ_eq (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree, ddsrt_avl_iter_t *iter, const void *key) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_iter_succ (const ddsrt_avl_treedef_t *td, const ddsrt_avl_tree_t *tree, ddsrt_avl_iter_t *iter, const void *key) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_iter_next (ddsrt_avl_iter_t *iter) ddsrt_nonnull_all;
|
||||
|
||||
/* Maintaining # nodes */
|
||||
|
||||
#define DDSRT_AVL_CTREEDEF_INITIALIZER(avlnodeoffset, keyoffset, comparekk, augment) { DDSRT_AVL_TREEDEF_INITIALIZER (avlnodeoffset, keyoffset, comparekk, augment) }
|
||||
#define DDSRT_AVL_CTREEDEF_INITIALIZER_INDKEY(avlnodeoffset, keyoffset, comparekk, augment) { DDSRT_AVL_TREEDEF_INITIALIZER_INDKEY (avlnodeoffset, keyoffset, comparekk, augment) }
|
||||
#define DDSRT_AVL_CTREEDEF_INITIALIZER_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk, augment) { DDSRT_AVL_TREEDEF_INITIALIZER_ALLOWDUPS (avlnodeoffset, keyoffset, comparekk, augment) }
|
||||
#define DDSRT_AVL_CTREEDEF_INITIALIZER_INDKEY_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk, augment) { DDSRT_AVL_TREEDEF_INITIALIZER_INDKEY_ALLOWDUPS (avlnodeoffset, keyoffset, comparekk, augment) }
|
||||
#define DDSRT_AVL_CTREEDEF_INITIALIZER_R(avlnodeoffset, keyoffset, comparekk, cmparg, augment) { DDSRT_AVL_TREEDEF_INITIALIZER_R (avlnodeoffset, keyoffset, comparekk, cmparg, augment) }
|
||||
#define DDSRT_AVL_CTREEDEF_INITIALIZER_INDKEY_R(avlnodeoffset, keyoffset, comparekk, cmparg, augment) { DDSRT_AVL_TREEDEF_INITIALIZER_INDKEY_R (avlnodeoffset, keyoffset, comparekk, cmparg, augment) }
|
||||
#define DDSRT_AVL_CTREEDEF_INITIALIZER_R_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk, cmparg, augment) { DDSRT_AVL_TREEDEF_INITIALIZER_R_ALLOWDUPS (avlnodeoffset, keyoffset, comparekk, cmparg, augment) }
|
||||
#define DDSRT_AVL_CTREEDEF_INITIALIZER_INDKEY_R_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk, cmparg, augment) { DDSRT_AVL_TREEDEF_INITIALIZER_INDKEY_R_ALLOWDUPS (avlnodeoffset, keyoffset, comparekk, cmparg, augment) }
|
||||
|
||||
DDS_EXPORT void ddsrt_avl_ctreedef_init (ddsrt_avl_ctreedef_t *td, size_t avlnodeoffset, size_t keyoffset, ddsrt_avl_compare_t comparekk, ddsrt_avl_augment_t augment, uint32_t flags) ddsrt_nonnull((1,4));
|
||||
DDS_EXPORT void ddsrt_avl_ctreedef_init_r (ddsrt_avl_ctreedef_t *td, size_t avlnodeoffset, size_t keyoffset, ddsrt_avl_compare_r_t comparekk_r, void *cmp_arg, ddsrt_avl_augment_t augment, uint32_t flags) ddsrt_nonnull((1,4));
|
||||
|
||||
DDS_EXPORT void ddsrt_avl_cinit (const ddsrt_avl_ctreedef_t *td, ddsrt_avl_ctree_t *tree) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void ddsrt_avl_cfree (const ddsrt_avl_ctreedef_t *td, ddsrt_avl_ctree_t *tree, void (*freefun) (void *node)) ddsrt_nonnull((1,2));
|
||||
DDS_EXPORT void ddsrt_avl_cfree_arg (const ddsrt_avl_ctreedef_t *td, ddsrt_avl_ctree_t *tree, void (*freefun) (void *node, void *arg), void *arg) ddsrt_nonnull((1,2));
|
||||
|
||||
DDS_EXPORT void *ddsrt_avl_croot (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_croot_non_empty (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_clookup (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree, const void *key) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_clookup_ipath (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree, const void *key, ddsrt_avl_ipath_t *path) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_clookup_dpath (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree, const void *key, ddsrt_avl_dpath_t *path) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_clookup_pred_eq (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree, const void *key) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_clookup_succ_eq (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree, const void *key) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_clookup_pred (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree, const void *key) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_clookup_succ (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree, const void *key) ddsrt_nonnull_all;
|
||||
|
||||
DDS_EXPORT void ddsrt_avl_cinsert (const ddsrt_avl_ctreedef_t *td, ddsrt_avl_ctree_t *tree, void *node) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void ddsrt_avl_cdelete (const ddsrt_avl_ctreedef_t *td, ddsrt_avl_ctree_t *tree, void *node) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void ddsrt_avl_cinsert_ipath (const ddsrt_avl_ctreedef_t *td, ddsrt_avl_ctree_t *tree, void *node, ddsrt_avl_ipath_t *path) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void ddsrt_avl_cdelete_dpath (const ddsrt_avl_ctreedef_t *td, ddsrt_avl_ctree_t *tree, void *node, ddsrt_avl_dpath_t *path) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void ddsrt_avl_cswap_node (const ddsrt_avl_ctreedef_t *td, ddsrt_avl_ctree_t *tree, void *oldn, void *newn) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void ddsrt_avl_caugment_update (const ddsrt_avl_ctreedef_t *td, void *node) ddsrt_nonnull_all;
|
||||
|
||||
DDS_EXPORT int ddsrt_avl_cis_empty (const ddsrt_avl_ctree_t *tree) ddsrt_nonnull_all;
|
||||
DDS_EXPORT int ddsrt_avl_cis_singleton (const ddsrt_avl_ctree_t *tree) ddsrt_nonnull_all;
|
||||
DDS_EXPORT size_t ddsrt_avl_ccount (const ddsrt_avl_ctree_t *tree) ddsrt_nonnull_all;
|
||||
|
||||
DDS_EXPORT void *ddsrt_avl_cfind_min (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_cfind_max (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_cfind_pred (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree, const void *vnode) ddsrt_nonnull((1,2));
|
||||
DDS_EXPORT void *ddsrt_avl_cfind_succ (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree, const void *vnode) ddsrt_nonnull((1,2));
|
||||
|
||||
DDS_EXPORT void ddsrt_avl_cwalk (const ddsrt_avl_ctreedef_t *td, ddsrt_avl_ctree_t *tree, ddsrt_avl_walk_t f, void *a) ddsrt_nonnull((1,2,3));
|
||||
DDS_EXPORT void ddsrt_avl_cconst_walk (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree, ddsrt_avl_const_walk_t f, void *a) ddsrt_nonnull((1,2,3));
|
||||
DDS_EXPORT void ddsrt_avl_cwalk_range (const ddsrt_avl_ctreedef_t *td, ddsrt_avl_ctree_t *tree, const void *min, const void *max, ddsrt_avl_walk_t f, void *a) ddsrt_nonnull((1,2,3,4,5));
|
||||
DDS_EXPORT void ddsrt_avl_cconst_walk_range (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree, const void *min, const void *max, ddsrt_avl_const_walk_t f, void *a) ddsrt_nonnull((1,2,3,4,5));
|
||||
DDS_EXPORT void ddsrt_avl_cwalk_range_reverse (const ddsrt_avl_ctreedef_t *td, ddsrt_avl_ctree_t *tree, const void *min, const void *max, ddsrt_avl_walk_t f, void *a) ddsrt_nonnull((1,2,3,4,5));
|
||||
DDS_EXPORT void ddsrt_avl_cconst_walk_range_reverse (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree, const void *min, const void *max, ddsrt_avl_const_walk_t f, void *a) ddsrt_nonnull((1,2,3,4,5));
|
||||
|
||||
DDS_EXPORT void *ddsrt_avl_citer_first (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree, ddsrt_avl_citer_t *iter) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_citer_succ_eq (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree, ddsrt_avl_citer_t *iter, const void *key) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_citer_succ (const ddsrt_avl_ctreedef_t *td, const ddsrt_avl_ctree_t *tree, ddsrt_avl_citer_t *iter, const void *key) ddsrt_nonnull_all;
|
||||
DDS_EXPORT void *ddsrt_avl_citer_next (ddsrt_avl_citer_t *iter) ddsrt_nonnull_all;
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DDSRT_AVL_H */
|
31
src/ddsrt/include/dds/ddsrt/expand_envvars.h
Normal file
31
src/ddsrt/include/dds/ddsrt/expand_envvars.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef DDSRT_EXPAND_ENVVARS_H
|
||||
#define DDSRT_EXPAND_ENVVARS_H
|
||||
|
||||
#include "dds/export.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Expands ${X}, ${X:-Y}, ${X:+Y}, ${X:?Y} forms, but not $X */
|
||||
DDS_EXPORT char *ddsrt_expand_envvars(const char *string);
|
||||
|
||||
/* Expands $X, ${X}, ${X:-Y}, ${X:+Y}, ${X:?Y} forms, $ and \ can be escaped with \ */
|
||||
DDS_EXPORT char *ddsrt_expand_envvars_sh(const char *string);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
54
src/ddsrt/include/dds/ddsrt/fibheap.h
Normal file
54
src/ddsrt/include/dds/ddsrt/fibheap.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef DDSRT_FIBHEAP_H
|
||||
#define DDSRT_FIBHEAP_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "dds/export.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct ddsrt_fibheap_node {
|
||||
struct ddsrt_fibheap_node *parent, *children;
|
||||
struct ddsrt_fibheap_node *prev, *next;
|
||||
unsigned mark: 1;
|
||||
unsigned degree: 31;
|
||||
} ddsrt_fibheap_node_t;
|
||||
|
||||
typedef struct ddsrt_fibheap_def {
|
||||
uintptr_t offset;
|
||||
int (*cmp) (const void *va, const void *vb);
|
||||
} ddsrt_fibheap_def_t;
|
||||
|
||||
typedef struct ddsrt_fibheap {
|
||||
ddsrt_fibheap_node_t *roots; /* points to root with min key value */
|
||||
} ddsrt_fibheap_t;
|
||||
|
||||
#define DDSRT_FIBHEAPDEF_INITIALIZER(offset, cmp) { (offset), (cmp) }
|
||||
|
||||
DDS_EXPORT void ddsrt_fibheap_def_init (ddsrt_fibheap_def_t *fhdef, uintptr_t offset, int (*cmp) (const void *va, const void *vb));
|
||||
DDS_EXPORT void ddsrt_fibheap_init (const ddsrt_fibheap_def_t *fhdef, ddsrt_fibheap_t *fh);
|
||||
DDS_EXPORT void *ddsrt_fibheap_min (const ddsrt_fibheap_def_t *fhdef, const ddsrt_fibheap_t *fh);
|
||||
DDS_EXPORT void ddsrt_fibheap_merge (const ddsrt_fibheap_def_t *fhdef, ddsrt_fibheap_t *a, ddsrt_fibheap_t *b);
|
||||
DDS_EXPORT void ddsrt_fibheap_insert (const ddsrt_fibheap_def_t *fhdef, ddsrt_fibheap_t *fh, const void *vnode);
|
||||
DDS_EXPORT void ddsrt_fibheap_delete (const ddsrt_fibheap_def_t *fhdef, ddsrt_fibheap_t *fh, const void *vnode);
|
||||
DDS_EXPORT void *ddsrt_fibheap_extract_min (const ddsrt_fibheap_def_t *fhdef, ddsrt_fibheap_t *fh);
|
||||
DDS_EXPORT void ddsrt_fibheap_decrease_key (const ddsrt_fibheap_def_t *fhdef, ddsrt_fibheap_t *fh, const void *vnode); /* to be called AFTER decreasing the key */
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DDSRT_FIBHEAP_H */
|
104
src/ddsrt/include/dds/ddsrt/hopscotch.h
Normal file
104
src/ddsrt/include/dds/ddsrt/hopscotch.h
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef DDSRT_HOPSCOTCH_H
|
||||
#define DDSRT_HOPSCOTCH_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "dds/export.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Concurrent version */
|
||||
struct ddsrt_chh;
|
||||
struct ddsrt_chh_bucket;
|
||||
struct ddsrt_chh_iter {
|
||||
struct ddsrt_chh_bucket *bs;
|
||||
uint32_t size;
|
||||
uint32_t cursor;
|
||||
};
|
||||
|
||||
/*
|
||||
* The hopscotch hash table is dependent on a proper functioning hash.
|
||||
* If the hash function generates a lot of hash collisions, then it will
|
||||
* not be able to handle that by design.
|
||||
* It is capable of handling some collisions, but not more than 32 per
|
||||
* bucket (less, when other hash values are clustered around the
|
||||
* collision value).
|
||||
* When proper distributed hash values are generated, then hopscotch
|
||||
* works nice and quickly.
|
||||
*/
|
||||
typedef uint32_t (*ddsrt_hh_hash_fn) (const void *);
|
||||
|
||||
/*
|
||||
* Hopscotch needs to be able to compare two elements.
|
||||
* Returns 0 when not equal.
|
||||
*/
|
||||
typedef int (*ddsrt_hh_equals_fn) (const void *, const void *);
|
||||
|
||||
/*
|
||||
* Hopscotch is will resize its internal buckets list when needed. It will
|
||||
* call this garbage collection function with the old buckets list. The
|
||||
* caller has to delete the list when it deems it safe to do so.
|
||||
*/
|
||||
typedef void (*ddsrt_hh_buckets_gc_fn) (void *);
|
||||
|
||||
DDS_EXPORT struct ddsrt_chh *ddsrt_chh_new (uint32_t init_size, ddsrt_hh_hash_fn hash, ddsrt_hh_equals_fn equals, ddsrt_hh_buckets_gc_fn gc_buckets);
|
||||
DDS_EXPORT void ddsrt_chh_free (struct ddsrt_chh * __restrict hh);
|
||||
DDS_EXPORT void *ddsrt_chh_lookup (struct ddsrt_chh * __restrict rt, const void * __restrict template);
|
||||
DDS_EXPORT int ddsrt_chh_add (struct ddsrt_chh * __restrict rt, const void * __restrict data);
|
||||
DDS_EXPORT int ddsrt_chh_remove (struct ddsrt_chh * __restrict rt, const void * __restrict template);
|
||||
DDS_EXPORT void ddsrt_chh_enum_unsafe (struct ddsrt_chh * __restrict rt, void (*f) (void *a, void *f_arg), void *f_arg); /* may delete a */
|
||||
void *ddsrt_chh_iter_first (struct ddsrt_chh * __restrict rt, struct ddsrt_chh_iter *it);
|
||||
void *ddsrt_chh_iter_next (struct ddsrt_chh_iter *it);
|
||||
|
||||
/* Sequential version */
|
||||
struct ddsrt_hh;
|
||||
|
||||
struct ddsrt_hh_iter {
|
||||
struct ddsrt_hh *hh;
|
||||
uint32_t cursor;
|
||||
};
|
||||
|
||||
DDS_EXPORT struct ddsrt_hh *ddsrt_hh_new (uint32_t init_size, ddsrt_hh_hash_fn hash, ddsrt_hh_equals_fn equals);
|
||||
DDS_EXPORT void ddsrt_hh_free (struct ddsrt_hh * __restrict hh);
|
||||
DDS_EXPORT void *ddsrt_hh_lookup (const struct ddsrt_hh * __restrict rt, const void * __restrict template);
|
||||
DDS_EXPORT int ddsrt_hh_add (struct ddsrt_hh * __restrict rt, const void * __restrict data);
|
||||
DDS_EXPORT int ddsrt_hh_remove (struct ddsrt_hh * __restrict rt, const void * __restrict template);
|
||||
DDS_EXPORT void ddsrt_hh_enum (struct ddsrt_hh * __restrict rt, void (*f) (void *a, void *f_arg), void *f_arg); /* may delete a */
|
||||
DDS_EXPORT void *ddsrt_hh_iter_first (struct ddsrt_hh * __restrict rt, struct ddsrt_hh_iter * __restrict iter); /* may delete nodes */
|
||||
DDS_EXPORT void *ddsrt_hh_iter_next (struct ddsrt_hh_iter * __restrict iter);
|
||||
|
||||
/* Sequential version, embedded data */
|
||||
struct ddsrt_ehh;
|
||||
|
||||
struct ddsrt_ehh_iter {
|
||||
struct ddsrt_ehh *hh;
|
||||
uint32_t cursor;
|
||||
};
|
||||
|
||||
DDS_EXPORT struct ddsrt_ehh *ddsrt_ehh_new (size_t elemsz, uint32_t init_size, ddsrt_hh_hash_fn hash, ddsrt_hh_equals_fn equals);
|
||||
DDS_EXPORT void ddsrt_ehh_free (struct ddsrt_ehh * __restrict hh);
|
||||
DDS_EXPORT void *ddsrt_ehh_lookup (const struct ddsrt_ehh * __restrict rt, const void * __restrict template);
|
||||
DDS_EXPORT int ddsrt_ehh_add (struct ddsrt_ehh * __restrict rt, const void * __restrict data);
|
||||
DDS_EXPORT int ddsrt_ehh_remove (struct ddsrt_ehh * __restrict rt, const void * __restrict template);
|
||||
DDS_EXPORT void ddsrt_ehh_enum (struct ddsrt_ehh * __restrict rt, void (*f) (void *a, void *f_arg), void *f_arg); /* may delete a */
|
||||
DDS_EXPORT void *ddsrt_ehh_iter_first (struct ddsrt_ehh * __restrict rt, struct ddsrt_ehh_iter * __restrict iter); /* may delete nodes */
|
||||
DDS_EXPORT void *ddsrt_ehh_iter_next (struct ddsrt_ehh_iter * __restrict iter);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
69
src/ddsrt/include/dds/ddsrt/thread_pool.h
Normal file
69
src/ddsrt/include/dds/ddsrt/thread_pool.h
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef DDSRT_THREAD_POOL_H
|
||||
#define DDSRT_THREAD_POOL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "dds/export.h"
|
||||
#include "dds/ddsrt/sync.h"
|
||||
#include "dds/ddsrt/threads.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct ddsrt_thread_pool_s *ddsrt_thread_pool;
|
||||
|
||||
/*
|
||||
ddsrt_thread_pool_new: Creates a new thread pool. Returns NULL if
|
||||
cannot create initial set of threads. Threads are created with
|
||||
the optional atribute argument. Additional threads may be created
|
||||
on demand up to max_threads.
|
||||
*/
|
||||
|
||||
DDS_EXPORT ddsrt_thread_pool ddsrt_thread_pool_new
|
||||
(
|
||||
uint32_t threads, /* Initial number of threads in pool (can be 0) */
|
||||
uint32_t max_threads, /* Maximum number of threads in pool (0 == infinite) */
|
||||
uint32_t max_queue, /* Maximum number of queued requests (0 == infinite) */
|
||||
ddsrt_threadattr_t * attr /* Attributes used to create pool threads (can be NULL) */
|
||||
);
|
||||
|
||||
/* ddsrt_thread_pool_free: Frees pool, destroying threads. */
|
||||
|
||||
DDS_EXPORT void ddsrt_thread_pool_free (ddsrt_thread_pool pool);
|
||||
|
||||
/* ddsrt_thread_pool_purge: Purge threads from pool back to initial set. */
|
||||
|
||||
DDS_EXPORT void ddsrt_thread_pool_purge (ddsrt_thread_pool pool);
|
||||
|
||||
/*
|
||||
ddsrt_thread_pool_submit: Submit a thread function and associated argument
|
||||
to be invoked by a thread from the pool. If no threads are available a
|
||||
new thread will be created on demand to handle the function unless the
|
||||
pool thread maximum has been reached, in which case the function is queued.
|
||||
Note that if the pool queue has reached it's maximum DDS_RETCODE_TRY_AGAIN is returned.
|
||||
*/
|
||||
|
||||
DDS_EXPORT dds_retcode_t ddsrt_thread_pool_submit
|
||||
(
|
||||
ddsrt_thread_pool pool, /* Thread pool instance */
|
||||
void (*fn) (void *arg), /* Function to be invoked by thread from pool */
|
||||
void * arg /* Argument passed to invoked function */
|
||||
);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DDSRT_THREAD_POOL_H */
|
52
src/ddsrt/include/dds/ddsrt/xmlparser.h
Normal file
52
src/ddsrt/include/dds/ddsrt/xmlparser.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef DDSRT_XMLPARSER_H
|
||||
#define DDSRT_XMLPARSER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "dds/export.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int (*ddsrt_xmlp_proc_elem_open_t) (void *varg, uintptr_t parentinfo, uintptr_t *eleminfo, const char *name);
|
||||
typedef int (*ddsrt_xmlp_proc_attr_t) (void *varg, uintptr_t eleminfo, const char *name, const char *value);
|
||||
typedef int (*ddsrt_xmlp_proc_elem_data_t) (void *varg, uintptr_t eleminfo, const char *data);
|
||||
typedef int (*ddsrt_xmlp_proc_elem_close_t) (void *varg, uintptr_t eleminfo);
|
||||
typedef void (*ddsrt_xmlp_error) (void *varg, const char *msg, int line);
|
||||
|
||||
struct ddsrt_xmlp_callbacks {
|
||||
ddsrt_xmlp_proc_elem_open_t elem_open;
|
||||
ddsrt_xmlp_proc_attr_t attr;
|
||||
ddsrt_xmlp_proc_elem_data_t elem_data;
|
||||
ddsrt_xmlp_proc_elem_close_t elem_close;
|
||||
ddsrt_xmlp_error error;
|
||||
};
|
||||
|
||||
struct ddsrt_xmlp_state;
|
||||
|
||||
DDS_EXPORT struct ddsrt_xmlp_state *ddsrt_xmlp_new_file (FILE *fp, void *varg, const struct ddsrt_xmlp_callbacks *cb);
|
||||
DDS_EXPORT struct ddsrt_xmlp_state *ddsrt_xmlp_new_string (const char *string, void *varg, const struct ddsrt_xmlp_callbacks *cb);
|
||||
DDS_EXPORT void ddsrt_xmlp_set_requireEOF (struct ddsrt_xmlp_state *st, int require_eof);
|
||||
DDS_EXPORT size_t ddsrt_xmlp_get_bufpos (const struct ddsrt_xmlp_state *st);
|
||||
DDS_EXPORT void ddsrt_xmlp_free (struct ddsrt_xmlp_state *st);
|
||||
DDS_EXPORT int ddsrt_xmlp_parse (struct ddsrt_xmlp_state *st);
|
||||
|
||||
DDS_EXPORT int ddsrt_xmlUnescapeInsitu (char *buffer, size_t *n);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue