1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/ucx/ucx.h Tue Oct 17 16:15:41 2017 +0200 1.3 @@ -0,0 +1,145 @@ 1.4 +/* 1.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 1.6 + * 1.7 + * Copyright 2017 Olaf Wintermann. All rights reserved. 1.8 + * 1.9 + * Redistribution and use in source and binary forms, with or without 1.10 + * modification, are permitted provided that the following conditions are met: 1.11 + * 1.12 + * 1. Redistributions of source code must retain the above copyright 1.13 + * notice, this list of conditions and the following disclaimer. 1.14 + * 1.15 + * 2. Redistributions in binary form must reproduce the above copyright 1.16 + * notice, this list of conditions and the following disclaimer in the 1.17 + * documentation and/or other materials provided with the distribution. 1.18 + * 1.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 1.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1.29 + * POSSIBILITY OF SUCH DAMAGE. 1.30 + */ 1.31 +/** 1.32 + * Main UCX Header providing most common definitions. 1.33 + * 1.34 + * @file ucx.h 1.35 + * @author Mike Becker 1.36 + * @author Olaf Wintermann 1.37 + */ 1.38 + 1.39 +#ifndef UCX_H 1.40 +#define UCX_H 1.41 + 1.42 +/** Major UCX version as integer constant. */ 1.43 +#define UCX_VERSION_MAJOR 0 1.44 + 1.45 +/** Minor UCX version as integer constant. */ 1.46 +#define UCX_VERSION_MINOR 13 1.47 + 1.48 +#include <stdlib.h> 1.49 +#include <stdint.h> 1.50 + 1.51 +#ifdef _WIN32 1.52 +#if !(defined __ssize_t_defined || defined _SSIZE_T_) 1.53 +#include <BaseTsd.h> 1.54 +typedef SSIZE_T ssize_t; 1.55 +#define __ssize_t_defined 1.56 +#define _SSIZE_T_ 1.57 +#endif /* __ssize_t_defined and _SSIZE_T */ 1.58 +#else /* !_WIN32 */ 1.59 +#include <sys/types.h> 1.60 +#endif /* _WIN32 */ 1.61 + 1.62 +#ifdef __cplusplus 1.63 +#ifndef _Bool 1.64 +#define _Bool bool 1.65 +#define restrict 1.66 +#endif 1.67 +/** Use C naming even when compiling with C++. */ 1.68 +#define UCX_EXTERN extern "C" 1.69 +extern "C" { 1.70 +#else 1.71 +/** Pointless in C. */ 1.72 +#define UCX_EXTERN 1.73 +#endif 1.74 + 1.75 + 1.76 +/** 1.77 + * A function pointer to a destructor function. 1.78 + * @see ucx_mempool_setdestr() 1.79 + * @see ucx_mempool_regdestr() 1.80 + */ 1.81 +typedef void(*ucx_destructor)(void*); 1.82 + 1.83 +/** 1.84 + * Function pointer to a compare function. 1.85 + * 1.86 + * The compare function shall take three arguments: the two values that shall be 1.87 + * compared and optional additional data. 1.88 + * The function shall then return -1 if the first argument is less than the 1.89 + * second argument, 1 if the first argument is greater than the second argument 1.90 + * and 0 if both arguments are equal. If the third argument is 1.91 + * <code>NULL</code>, it shall be ignored. 1.92 + */ 1.93 +typedef int(*cmp_func)(const void*,const void*,void*); 1.94 + 1.95 +/** 1.96 + * Function pointer to a distance function. 1.97 + * 1.98 + * The distance function shall take three arguments: the two values for which 1.99 + * the distance shall be computed and optional additional data. 1.100 + * The function shall then return the signed distance as integer value. 1.101 + */ 1.102 +typedef intmax_t(*distance_func)(const void*,const void*,void*); 1.103 + 1.104 +/** 1.105 + * Function pointer to a copy function. 1.106 + * 1.107 + * The copy function shall create a copy of the first argument and may use 1.108 + * additional data provided by the second argument. If the second argument is 1.109 + * <code>NULL</code>, it shall be ignored. 1.110 + 1.111 + * <b>Attention:</b> if pointers returned by functions of this type may be 1.112 + * passed to <code>free()</code> depends on the implementation of the 1.113 + * respective <code>copy_func</code>. 1.114 + */ 1.115 +typedef void*(*copy_func)(const void*,void*); 1.116 + 1.117 +/** 1.118 + * Function pointer to a write function. 1.119 + * 1.120 + * The signature of the write function shall be compatible to the signature 1.121 + * of standard <code>fwrite</code>, though it may use arbitrary data types for 1.122 + * source and destination. 1.123 + * 1.124 + * The arguments shall contain (in ascending order): a pointer to the source, 1.125 + * the length of one element, the element count and a pointer to the 1.126 + * destination. 1.127 + */ 1.128 +typedef size_t(*write_func)(const void*, size_t, size_t, void*); 1.129 + 1.130 +/** 1.131 + * Function pointer to a read function. 1.132 + * 1.133 + * The signature of the read function shall be compatible to the signature 1.134 + * of standard <code>fread</code>, though it may use arbitrary data types for 1.135 + * source and destination. 1.136 + * 1.137 + * The arguments shall contain (in ascending order): a pointer to the 1.138 + * destination, the length of one element, the element count and a pointer to 1.139 + * the source. 1.140 + */ 1.141 +typedef size_t(*read_func)(void*, size_t, size_t, void*); 1.142 + 1.143 +#ifdef __cplusplus 1.144 +} 1.145 +#endif 1.146 + 1.147 +#endif /* UCX_H */ 1.148 +