/* * libetp implementation * * Copyright (c) 2007,2008,2009,2010,2011,2012,2013,2014,2015 Marc Alexander Lehmann * All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- * tion, 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- * CIAL, 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 OTH- * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License ("GPL") version 2 or any later version, * in which case the provisions of the GPL are applicable instead of * the above. If you wish to allow the use of your version of this file * only under the terms of the GPL and not to allow others to use your * version of this file under the BSD license, indicate your decision * by deleting the provisions above and replace them with the notice * and other provisions required by the GPL. If you do not delete the * provisions above, a recipient may use your version of this file under * either the BSD or the GPL. */ #ifndef ETP_H_ #define ETP_H_ #include #ifdef __cplusplus extern "C" { #endif #ifndef ETP_REQ_MBMERS #define ETP_REQ_MBMERS #endif #ifndef ETP_API_DECL #define ETP_API_DECL #endif #ifndef ETP_REQ #define ETP_REQ struct etp_req #endif /* request priorities */ enum { ETP_PRI_MIN = -4, ETP_PRI_MAX = 4, ETP_PRI_DEFAULT = 0 }; /* request types - custom types have to start at ETP_TYPE_START */ enum { ETP_TYPE_QUIT = 0, ETP_TYPE_GROUP = 1, ETP_TYPE_START = 2 }; struct etp_req { ETP_REQ volatile *next; /* private */ ETP_REQ_MEMBERS unsigned char flags; /* reserved */ signed char type;/* ETP_xxx constant */ signed char pri; /* the priority */ #if __i386 || __amd64 unsigned char cancelled; /* ETP */ #else sig_atomic_t cancelled; /* ETP */ #endif int size; /* private */ ETP_REQ *grp, *grp_prev, *grp_next, *grp_first; /* private */ }; /* true if the request was cancelled, useful in the invoke callback */ #define ETP_CANCELLED(req) ((req)->cancelled) typedef struct etp_pool *etp_pool; ETP_API_DECL unsigned int etp_nreqs (etp_pool pool); ETP_API_DECL unsigned int etp_nready (etp_pool pool); ETP_API_DECL unsigned int etp_npending (etp_pool pool); ETP_API_DECL unsigned int etp_nthreads (etp_pool pool); ETP_API_DECL int etp_init (etp_pool pool, void *userdata, void (*want_poll)(void *userdata), void (*done_poll)(void *userdata)); ETP_API_DECL int etp_poll (etp_pool pool); ETP_API_DECL void etp_grp_cancel (etp_pool pool, ETP_REQ *grp); ETP_API_DECL void etp_cancel (etp_pool pool, ETP_REQ *req); ETP_API_DECL void etp_grp_cancel (etp_pool pool, ETP_REQ *grp); ETP_API_DECL void etp_submit (etp_pool pool, ETP_REQ *req); ETP_API_DECL void ecb_cold etp_set_max_poll_time (etp_pool pool, double seconds); ETP_API_DECL void ecb_cold etp_set_max_poll_reqs (etp_pool pool, unsigned int maxreqs); ETP_API_DECL void ecb_cold etp_set_max_idle (etp_pool pool, unsigned int threads); ETP_API_DECL void ecb_cold etp_set_idle_timeout (etp_pool pool, unsigned int seconds); ETP_API_DECL void ecb_cold etp_set_min_parallel (etp_pool pool, unsigned int threads); ETP_API_DECL void ecb_cold etp_set_max_parallel (etp_pool pool, unsigned int threads); #ifdef __cplusplus } #endif #endif