src/ucx/ucx.h

changeset 390
d345541018fa
parent 389
92e482410453
child 391
f094a53c1178
     1.1 --- a/src/ucx/ucx.h	Mon Dec 30 09:54:10 2019 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,204 +0,0 @@
     1.4 -/*
     1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     1.6 - *
     1.7 - * Copyright 2017 Mike Becker, 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   2
    1.44 -
    1.45 -/** Minor UCX version as integer constant. */
    1.46 -#define UCX_VERSION_MINOR   1
    1.47 -
    1.48 -/** Version constant which ensures to increase monotonically. */
    1.49 -#define UCX_VERSION (((UCX_VERSION_MAJOR)<<16)|UCX_VERSION_MINOR)
    1.50 -
    1.51 -#include <stdlib.h>
    1.52 -#include <stdint.h>
    1.53 -
    1.54 -#ifdef _WIN32
    1.55 -#if !(defined __ssize_t_defined || defined _SSIZE_T_)
    1.56 -#include <BaseTsd.h>
    1.57 -typedef SSIZE_T ssize_t;
    1.58 -#define __ssize_t_defined
    1.59 -#define _SSIZE_T_
    1.60 -#endif /* __ssize_t_defined and _SSIZE_T */
    1.61 -#else /* !_WIN32 */
    1.62 -#include <sys/types.h>
    1.63 -#endif /* _WIN32 */
    1.64 -
    1.65 -#ifdef	__cplusplus
    1.66 -extern "C" {
    1.67 -#endif
    1.68 -    
    1.69 -
    1.70 -/**
    1.71 - * A function pointer to a destructor function.
    1.72 - * @see ucx_mempool_setdestr()
    1.73 - * @see ucx_mempool_regdestr()
    1.74 - */
    1.75 -typedef void(*ucx_destructor)(void*);
    1.76 -
    1.77 -/**
    1.78 - * Function pointer to a compare function.
    1.79 - * 
    1.80 - * The compare function shall take three arguments: the two values that shall be
    1.81 - * compared and optional additional data.
    1.82 - * The function shall then return -1 if the first argument is less than the
    1.83 - * second argument, 1 if the first argument is greater than the second argument
    1.84 - * and 0 if both arguments are equal. If the third argument is
    1.85 - * <code>NULL</code>, it shall be ignored.
    1.86 - */
    1.87 -typedef int(*cmp_func)(const void*,const void*,void*);
    1.88 -
    1.89 -/**
    1.90 - * Function pointer to a distance function.
    1.91 - * 
    1.92 - * The distance function shall take three arguments: the two values for which
    1.93 - * the distance shall be computed and optional additional data.
    1.94 - * The function shall then return the signed distance as integer value.
    1.95 - */
    1.96 -typedef intmax_t(*distance_func)(const void*,const void*,void*);
    1.97 -
    1.98 -/**
    1.99 - * Function pointer to a copy function.
   1.100 - * 
   1.101 - * The copy function shall create a copy of the first argument and may use
   1.102 - * additional data provided by the second argument. If the second argument is
   1.103 - * <code>NULL</code>, it shall be ignored.
   1.104 -
   1.105 - * <b>Attention:</b> if pointers returned by functions of this type may be
   1.106 - * passed to <code>free()</code> depends on the implementation of the
   1.107 - * respective <code>copy_func</code>.
   1.108 - */
   1.109 -typedef void*(*copy_func)(const void*,void*);
   1.110 -
   1.111 -/**
   1.112 - * Function pointer to a write function.
   1.113 - * 
   1.114 - * The signature of the write function shall be compatible to the signature
   1.115 - * of standard <code>fwrite</code>, though it may use arbitrary data types for
   1.116 - * source and destination.
   1.117 - * 
   1.118 - * The arguments shall contain (in ascending order): a pointer to the source,
   1.119 - * the length of one element, the element count and a pointer to the
   1.120 - * destination.
   1.121 - */
   1.122 -typedef size_t(*write_func)(const void*, size_t, size_t, void*);
   1.123 -
   1.124 -/**
   1.125 - * Function pointer to a read function.
   1.126 - * 
   1.127 - * The signature of the read function shall be compatible to the signature
   1.128 - * of standard <code>fread</code>, though it may use arbitrary data types for
   1.129 - * source and destination.
   1.130 - * 
   1.131 - * The arguments shall contain (in ascending order): a pointer to the
   1.132 - * destination, the length of one element, the element count and a pointer to
   1.133 - * the source.
   1.134 - */
   1.135 -typedef size_t(*read_func)(void*, size_t, size_t, void*);
   1.136 -
   1.137 -
   1.138 -
   1.139 -#if __GNUC__ >= 5 || defined(__clang__)
   1.140 -#define UCX_MUL_BUILTIN
   1.141 -
   1.142 -#if __WORDSIZE == 32
   1.143 -/**
   1.144 - * Alias for <code>__builtin_umul_overflow</code>.
   1.145 - * 
   1.146 - * Performs a multiplication of size_t values and checks for overflow.
   1.147 - * 
   1.148 - * @param a first operand
   1.149 - * @param b second operand
   1.150 - * @param result a pointer to a size_t, where the result should
   1.151 - * be stored
   1.152 - * @return zero, if no overflow occurred and the result is correct, non-zero
   1.153 - * otherwise
   1.154 - */
   1.155 -#define ucx_szmul(a, b, result) __builtin_umul_overflow(a, b, result)
   1.156 -#else /* __WORDSIZE != 32 */
   1.157 -/**
   1.158 - * Alias for <code>__builtin_umull_overflow</code>.
   1.159 - * 
   1.160 - * Performs a multiplication of size_t values and checks for overflow.
   1.161 - * 
   1.162 - * @param a first operand
   1.163 - * @param b second operand
   1.164 - * @param result a pointer to a size_t, where the result should
   1.165 - * be stored
   1.166 - * @return zero, if no overflow occurred and the result is correct, non-zero
   1.167 - * otherwise
   1.168 - */
   1.169 -#define ucx_szmul(a, b, result) __builtin_umull_overflow(a, b, result)
   1.170 -#endif /* __WORDSIZE */
   1.171 -
   1.172 -#else /* no GNUC or clang bultin */
   1.173 -
   1.174 -/**
   1.175 - * Performs a multiplication of size_t values and checks for overflow.
   1.176 -  *
   1.177 - * @param a first operand
   1.178 - * @param b second operand
   1.179 - * @param result a pointer to a size_t, where the result should
   1.180 - * be stored
   1.181 - * @return zero, if no overflow occurred and the result is correct, non-zero
   1.182 - * otherwise
   1.183 - */
   1.184 -#define ucx_szmul(a, b, result) ucx_szmul_impl(a, b, result)
   1.185 -
   1.186 -/**
   1.187 - * Performs a multiplication of size_t values and checks for overflow.
   1.188 - *
   1.189 - * This is a custom implementation in case there is no compiler builtin
   1.190 - * available.
   1.191 - *
   1.192 - * @param a first operand
   1.193 - * @param b second operand
   1.194 - * @param result a pointer to a size_t where the result should be stored
   1.195 - * @return zero, if no overflow occurred and the result is correct, non-zero
   1.196 - * otherwise
   1.197 - */
   1.198 -int ucx_szmul_impl(size_t a, size_t b, size_t *result);
   1.199 -
   1.200 -#endif
   1.201 -
   1.202 -#ifdef	__cplusplus
   1.203 -}
   1.204 -#endif
   1.205 -
   1.206 -#endif	/* UCX_H */
   1.207 -

mercurial