1 /* akbox.h  -  Application Black (K) Box - an inmemory multithreaded logging system
2  * Copyright (c) 2006,2012-2013 Sampo Kellomaki (sampo@iki.fi), All Rights Reserved.
3  * This is confidential unpublished proprietary source code of the author.
4  * NO WARRANTY, not even implied warranties. Contains trade secrets.
5  * Distribution prohibited unless authorized in writing. See file COPYING.
6  * Special grant: akbox.h may be used with zxid open source project under
7  * same licensing terms as zxid itself.
8  * $Id$
9  *
10  * 15.4.2006, created over Easter holiday --Sampo
11  * 16.8.2012, modified license grant to allow use with ZXID.org --Sampo
12  * 15.4.2013, made sure ASBOX_FN returns int so %x format can be used without warnings --Sampo
13  *
14  * See also: ./log-pretty.pl -fn b5be:118   # decodes a FN hash
15  */
16 
17 #ifndef _akbox_h
18 #define _akbox_h
19 
20 /* A macro to compute hash over function name so it can be supplied as an arg to AKBOX and err
21  * functions. A better hash function should be developed. This one has collisions
22  * This hash function may cause compiler preprocessor and/or constant folding to run slowly ;-)
23  * but the slowness is only at compile time and not at runtime. */
24 #define AKBOX_FN(x) ((int)(( sizeof(x) + (x)[0]  \
25 		  + (sizeof(x)>2 ? 2*(x)[1] : 0)      + (sizeof(x)>3 ? 3*(x)[2] : 0) \
26 		  + (sizeof(x)>4 ? 5*(x)[3] : 0)      + (sizeof(x)>5 ? 7*(x)[4] : 0) \
27 		  + (sizeof(x)>6 ? 11*(x)[5] : 0)     + (sizeof(x)>7 ? 13*(x)[6] : 0) \
28 		  + (sizeof(x)>8 ? 17*(x)[7] : 0)     + (sizeof(x)>9 ? 19*(x)[8] : 0) \
29                   \
30 		  + (sizeof(x)>10 ? 23*(x)[9] : 0)    + (sizeof(x)>11 ? 29*(x)[10] : 0) \
31 		  + (sizeof(x)>12 ? 31*(x)[11] : 0)   + (sizeof(x)>13 ? 37*(x)[12] : 0) \
32 		  + (sizeof(x)>14 ? 41*(x)[13] : 0)   + (sizeof(x)>15 ? 43*(x)[14] : 0) \
33 		  + (sizeof(x)>16 ? 47*(x)[15] : 0)   + (sizeof(x)>17 ? 53*(x)[16] : 0) \
34 		  + (sizeof(x)>18 ? 59*(x)[17] : 0)   + (sizeof(x)>19 ? 61*(x)[18] : 0) \
35                   \
36 		  + (sizeof(x)>20 ? 67*(x)[19] : 0)   + (sizeof(x)>21 ? 71*(x)[20] : 0) \
37 		  + (sizeof(x)>22 ? 73*(x)[21] : 0)   + (sizeof(x)>23 ? 79*(x)[22] : 0) \
38 		  + (sizeof(x)>24 ? 83*(x)[23] : 0)   + (sizeof(x)>25 ? 89*(x)[24] : 0) \
39 		  + (sizeof(x)>26 ? 97*(x)[25] : 0)   + (sizeof(x)>27 ? 101*(x)[26] : 0) \
40 		  + (sizeof(x)>28 ? 103*(x)[27] : 0)  + (sizeof(x)>29 ? 107*(x)[28] : 0) \
41                   \
42 		  + (sizeof(x)>30 ? 109*(x)[29] : 0)  + (sizeof(x)>31 ? 113*(x)[30] : 0) \
43 		  + (sizeof(x)>32 ? 127*(x)[31] : 0)  + (sizeof(x)>33 ? 131*(x)[32] : 0) \
44 		  + (sizeof(x)>34 ? 137*(x)[33] : 0)  + (sizeof(x)>35 ? 139*(x)[34] : 0) \
45 		  + (sizeof(x)>36 ? 149*(x)[35] : 0)  + (sizeof(x)>37 ? 151*(x)[36] : 0) \
46 		  + (sizeof(x)>38 ? 157*(x)[37] : 0)  + (sizeof(x)>39 ? 163*(x)[38] : 0) \
47 		  ) & 0x0000ffff))
48 
49 int akbox_fn(const char* fn);
50 
51 #define ak_init(x)
52 #define ak_add_thread(s,f)
53 
54 #define AK_TS(r,a,...)
55 
56 #endif /* _akbox_h */
57