| 1 |
root |
1.1 |
/* |
| 2 |
|
|
* libetp implementation |
| 3 |
|
|
* |
| 4 |
|
|
* Copyright (c) 2007,2008,2009,2010,2011,2012,2013,2014,2015 Marc Alexander Lehmann <libetp@schmorp.de> |
| 5 |
|
|
* All rights reserved. |
| 6 |
|
|
* |
| 7 |
|
|
* Redistribution and use in source and binary forms, with or without modifica- |
| 8 |
|
|
* tion, are permitted provided that the following conditions are met: |
| 9 |
|
|
* |
| 10 |
|
|
* 1. Redistributions of source code must retain the above copyright notice, |
| 11 |
|
|
* this list of conditions and the following disclaimer. |
| 12 |
|
|
* |
| 13 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 14 |
|
|
* notice, this list of conditions and the following disclaimer in the |
| 15 |
|
|
* documentation and/or other materials provided with the distribution. |
| 16 |
|
|
* |
| 17 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 18 |
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- |
| 19 |
|
|
* CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 20 |
|
|
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- |
| 21 |
|
|
* CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 22 |
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 23 |
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 |
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- |
| 25 |
|
|
* ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 26 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
|
|
* |
| 28 |
|
|
* Alternatively, the contents of this file may be used under the terms of |
| 29 |
|
|
* the GNU General Public License ("GPL") version 2 or any later version, |
| 30 |
|
|
* in which case the provisions of the GPL are applicable instead of |
| 31 |
|
|
* the above. If you wish to allow the use of your version of this file |
| 32 |
|
|
* only under the terms of the GPL and not to allow others to use your |
| 33 |
|
|
* version of this file under the BSD license, indicate your decision |
| 34 |
|
|
* by deleting the provisions above and replace them with the notice |
| 35 |
|
|
* and other provisions required by the GPL. If you do not delete the |
| 36 |
|
|
* provisions above, a recipient may use your version of this file under |
| 37 |
|
|
* either the BSD or the GPL. |
| 38 |
|
|
*/ |
| 39 |
|
|
|
| 40 |
|
|
#ifndef ETP_H_ |
| 41 |
|
|
#define ETP_H_ |
| 42 |
|
|
|
| 43 |
|
|
#include <sys/types.h> |
| 44 |
|
|
|
| 45 |
|
|
#ifdef __cplusplus |
| 46 |
|
|
extern "C" { |
| 47 |
|
|
#endif |
| 48 |
|
|
|
| 49 |
|
|
#ifndef ETP_REQ_MBMERS |
| 50 |
|
|
#define ETP_REQ_MBMERS |
| 51 |
|
|
#endif |
| 52 |
|
|
|
| 53 |
|
|
#ifndef ETP_API_DECL |
| 54 |
|
|
#define ETP_API_DECL |
| 55 |
|
|
#endif |
| 56 |
|
|
|
| 57 |
|
|
#ifndef ETP_REQ |
| 58 |
|
|
#define ETP_REQ struct etp_req |
| 59 |
|
|
#endif |
| 60 |
|
|
|
| 61 |
|
|
/* request priorities */ |
| 62 |
|
|
enum { |
| 63 |
|
|
ETP_PRI_MIN = -4, |
| 64 |
|
|
ETP_PRI_MAX = 4, |
| 65 |
|
|
ETP_PRI_DEFAULT = 0 |
| 66 |
|
|
}; |
| 67 |
|
|
|
| 68 |
|
|
/* request types - custom types have to start at ETP_TYPE_START */ |
| 69 |
|
|
enum { |
| 70 |
|
|
ETP_TYPE_QUIT = 0, |
| 71 |
|
|
ETP_TYPE_GROUP = 1, |
| 72 |
|
|
ETP_TYPE_START = 2 |
| 73 |
|
|
}; |
| 74 |
|
|
|
| 75 |
|
|
struct etp_req |
| 76 |
|
|
{ |
| 77 |
|
|
ETP_REQ volatile *next; /* private */ |
| 78 |
|
|
|
| 79 |
|
|
ETP_REQ_MEMBERS |
| 80 |
|
|
|
| 81 |
|
|
unsigned char flags; /* reserved */ |
| 82 |
|
|
|
| 83 |
|
|
signed char type;/* ETP_xxx constant */ |
| 84 |
|
|
signed char pri; /* the priority */ |
| 85 |
|
|
#if __i386 || __amd64 |
| 86 |
|
|
unsigned char cancelled; /* ETP */ |
| 87 |
|
|
#else |
| 88 |
|
|
sig_atomic_t cancelled; /* ETP */ |
| 89 |
|
|
#endif |
| 90 |
|
|
|
| 91 |
|
|
int size; /* private */ |
| 92 |
|
|
ETP_REQ *grp, *grp_prev, *grp_next, *grp_first; /* private */ |
| 93 |
|
|
}; |
| 94 |
|
|
|
| 95 |
|
|
/* true if the request was cancelled, useful in the invoke callback */ |
| 96 |
|
|
#define ETP_CANCELLED(req) ((req)->cancelled) |
| 97 |
|
|
|
| 98 |
|
|
typedef struct etp_pool *etp_pool; |
| 99 |
|
|
|
| 100 |
|
|
ETP_API_DECL unsigned int etp_nreqs (etp_pool pool); |
| 101 |
|
|
ETP_API_DECL unsigned int etp_nready (etp_pool pool); |
| 102 |
|
|
ETP_API_DECL unsigned int etp_npending (etp_pool pool); |
| 103 |
|
|
ETP_API_DECL unsigned int etp_nthreads (etp_pool pool); |
| 104 |
|
|
ETP_API_DECL int etp_init (etp_pool pool, void *userdata, void (*want_poll)(void *userdata), void (*done_poll)(void *userdata)); |
| 105 |
|
|
ETP_API_DECL int etp_poll (etp_pool pool); |
| 106 |
|
|
ETP_API_DECL void etp_grp_cancel (etp_pool pool, ETP_REQ *grp); |
| 107 |
|
|
ETP_API_DECL void etp_cancel (etp_pool pool, ETP_REQ *req); |
| 108 |
|
|
ETP_API_DECL void etp_grp_cancel (etp_pool pool, ETP_REQ *grp); |
| 109 |
|
|
ETP_API_DECL void etp_submit (etp_pool pool, ETP_REQ *req); |
| 110 |
root |
1.2 |
ETP_API_DECL void ecb_cold etp_set_max_poll_time (etp_pool pool, double seconds); |
| 111 |
root |
1.1 |
ETP_API_DECL void ecb_cold etp_set_max_poll_reqs (etp_pool pool, unsigned int maxreqs); |
| 112 |
root |
1.2 |
ETP_API_DECL void ecb_cold etp_set_max_idle (etp_pool pool, unsigned int threads); |
| 113 |
root |
1.1 |
ETP_API_DECL void ecb_cold etp_set_idle_timeout (etp_pool pool, unsigned int seconds); |
| 114 |
root |
1.2 |
ETP_API_DECL void ecb_cold etp_set_min_parallel (etp_pool pool, unsigned int threads); |
| 115 |
|
|
ETP_API_DECL void ecb_cold etp_set_max_parallel (etp_pool pool, unsigned int threads); |
| 116 |
root |
1.1 |
|
| 117 |
|
|
#ifdef __cplusplus |
| 118 |
|
|
} |
| 119 |
|
|
#endif |
| 120 |
|
|
|
| 121 |
|
|
#endif |
| 122 |
|
|
|