timeout_ext 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/COPYING +510 -0
  4. data/MANIFEST +51 -0
  5. data/README +15 -0
  6. data/Rakefile +28 -0
  7. data/ext/timeout_ext/.gitignore +3 -0
  8. data/ext/timeout_ext/ccan-bits.c +7 -0
  9. data/ext/timeout_ext/ccan/array_size/LICENSE +28 -0
  10. data/ext/timeout_ext/ccan/array_size/_info +46 -0
  11. data/ext/timeout_ext/ccan/array_size/array_size.h +26 -0
  12. data/ext/timeout_ext/ccan/build_assert/LICENSE +28 -0
  13. data/ext/timeout_ext/ccan/build_assert/_info +49 -0
  14. data/ext/timeout_ext/ccan/build_assert/build_assert.h +40 -0
  15. data/ext/timeout_ext/ccan/check_type/LICENSE +28 -0
  16. data/ext/timeout_ext/ccan/check_type/_info +33 -0
  17. data/ext/timeout_ext/ccan/check_type/check_type.h +64 -0
  18. data/ext/timeout_ext/ccan/compiler/LICENSE +28 -0
  19. data/ext/timeout_ext/ccan/compiler/_info +64 -0
  20. data/ext/timeout_ext/ccan/compiler/compiler.h +231 -0
  21. data/ext/timeout_ext/ccan/container_of/LICENSE +28 -0
  22. data/ext/timeout_ext/ccan/container_of/_info +65 -0
  23. data/ext/timeout_ext/ccan/container_of/container_of.h +145 -0
  24. data/ext/timeout_ext/ccan/ilog/LICENSE +28 -0
  25. data/ext/timeout_ext/ccan/ilog/_info +50 -0
  26. data/ext/timeout_ext/ccan/ilog/ilog.c +141 -0
  27. data/ext/timeout_ext/ccan/ilog/ilog.h +151 -0
  28. data/ext/timeout_ext/ccan/list/LICENSE +17 -0
  29. data/ext/timeout_ext/ccan/list/_info +72 -0
  30. data/ext/timeout_ext/ccan/list/list.h +842 -0
  31. data/ext/timeout_ext/ccan/str/LICENSE +28 -0
  32. data/ext/timeout_ext/ccan/str/_info +52 -0
  33. data/ext/timeout_ext/ccan/str/str.h +228 -0
  34. data/ext/timeout_ext/ccan/str/str_debug.h +30 -0
  35. data/ext/timeout_ext/ccan/time/LICENSE +17 -0
  36. data/ext/timeout_ext/ccan/time/_info +57 -0
  37. data/ext/timeout_ext/ccan/time/time.c +138 -0
  38. data/ext/timeout_ext/ccan/time/time.h +753 -0
  39. data/ext/timeout_ext/ccan/timer/LICENSE +510 -0
  40. data/ext/timeout_ext/ccan/timer/_info +79 -0
  41. data/ext/timeout_ext/ccan/timer/design.txt +76 -0
  42. data/ext/timeout_ext/ccan/timer/timer.c +524 -0
  43. data/ext/timeout_ext/ccan/timer/timer.h +211 -0
  44. data/ext/timeout_ext/depend +17 -0
  45. data/ext/timeout_ext/extconf.rb +50 -0
  46. data/ext/timeout_ext/licenses/BSD-MIT +17 -0
  47. data/ext/timeout_ext/licenses/CC0 +28 -0
  48. data/ext/timeout_ext/licenses/LGPL-2.1 +510 -0
  49. data/ext/timeout_ext/missing/stdbool/stdbool.h +20 -0
  50. data/ext/timeout_ext/timeout_ext.c +114 -0
  51. data/test/test_timeout_ext.rb +44 -0
  52. data/timeout_ext.gemspec +30 -0
  53. metadata +126 -0
@@ -0,0 +1,28 @@
1
+ Statement of Purpose
2
+
3
+ The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
4
+
5
+ Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
6
+
7
+ For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
8
+
9
+ 1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
10
+
11
+ the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
12
+ moral rights retained by the original author(s) and/or performer(s);
13
+ publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
14
+ rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
15
+ rights protecting the extraction, dissemination, use and reuse of data in a Work;
16
+ database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
17
+ other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
18
+
19
+ 2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
20
+
21
+ 3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
22
+
23
+ 4. Limitations and Disclaimers.
24
+
25
+ No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
26
+ Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
27
+ Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
28
+ Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.
@@ -0,0 +1,50 @@
1
+ /**
2
+ * ilog - Integer logarithm.
3
+ *
4
+ * ilog_32() and ilog_64() compute the minimum number of bits required to store
5
+ * an unsigned 32-bit or 64-bit value without any leading zero bits.
6
+ *
7
+ * This can also be thought of as the location of the highest set bit, with
8
+ * counting starting from one (so that 0 returns 0, 1 returns 1, and 2**31
9
+ * returns 32).
10
+ *
11
+ * When the value is known to be non-zero ilog32_nz() and ilog64_nz() can
12
+ * compile into as few as two instructions, one of which may get optimized out
13
+ * later.
14
+ *
15
+ * STATIC_ILOG_32 and STATIC_ILOG_64 allow computation on compile-time
16
+ * constants, so other compile-time constants can be derived from them.
17
+ *
18
+ * Example:
19
+ * #include <stdio.h>
20
+ * #include <limits.h>
21
+ * #include <ccan/ilog/ilog.h>
22
+ *
23
+ * int main(void){
24
+ * int i;
25
+ * printf("ilog32(0x%08X)=%i\n",0,ilog32(0));
26
+ * for(i=1;i<=STATIC_ILOG_32(USHRT_MAX);i++){
27
+ * uint32_t v;
28
+ * v=(uint32_t)1U<<(i-1);
29
+ * //Here we know v is non-zero, so we can use ilog32_nz().
30
+ * printf("ilog32(0x%08X)=%i\n",v,ilog32_nz(v));
31
+ * }
32
+ * return 0;
33
+ * }
34
+ *
35
+ * License: CC0 (Public domain)
36
+ * Author: Timothy B. Terriberry <tterribe@xiph.org>
37
+ */
38
+ #include "config.h"
39
+ #include <string.h>
40
+ #include <stdio.h>
41
+
42
+ int main(int _argc,const char *_argv[]){
43
+ /*Expect exactly one argument.*/
44
+ if(_argc!=2)return 1;
45
+ if(strcmp(_argv[1],"depends")==0){
46
+ printf("ccan/compiler\n");
47
+ return 0;
48
+ }
49
+ return 1;
50
+ }
@@ -0,0 +1,141 @@
1
+ /*(C) Timothy B. Terriberry (tterribe@xiph.org) 2001-2009 CC0 (Public domain).
2
+ * See LICENSE file for details. */
3
+ #include "ilog.h"
4
+ #include <limits.h>
5
+
6
+ /*The fastest fallback strategy for platforms with fast multiplication appears
7
+ to be based on de Bruijn sequences~\cite{LP98}.
8
+ Tests confirmed this to be true even on an ARM11, where it is actually faster
9
+ than using the native clz instruction.
10
+ Define ILOG_NODEBRUIJN to use a simpler fallback on platforms where
11
+ multiplication or table lookups are too expensive.
12
+
13
+ @UNPUBLISHED{LP98,
14
+ author="Charles E. Leiserson and Harald Prokop",
15
+ title="Using de {Bruijn} Sequences to Index a 1 in a Computer Word",
16
+ month=Jun,
17
+ year=1998,
18
+ note="\url{http://supertech.csail.mit.edu/papers/debruijn.pdf}"
19
+ }*/
20
+ static UNNEEDED const unsigned char DEBRUIJN_IDX32[32]={
21
+ 0, 1,28, 2,29,14,24, 3,30,22,20,15,25,17, 4, 8,
22
+ 31,27,13,23,21,19,16, 7,26,12,18, 6,11, 5,10, 9
23
+ };
24
+
25
+ /* We always compile these in, in case someone takes address of function. */
26
+ #undef ilog32_nz
27
+ #undef ilog32
28
+ #undef ilog64_nz
29
+ #undef ilog64
30
+
31
+ int ilog32(uint32_t _v){
32
+ /*On a Pentium M, this branchless version tested as the fastest version without
33
+ multiplications on 1,000,000,000 random 32-bit integers, edging out a
34
+ similar version with branches, and a 256-entry LUT version.*/
35
+ # if defined(ILOG_NODEBRUIJN)
36
+ int ret;
37
+ int m;
38
+ ret=_v>0;
39
+ m=(_v>0xFFFFU)<<4;
40
+ _v>>=m;
41
+ ret|=m;
42
+ m=(_v>0xFFU)<<3;
43
+ _v>>=m;
44
+ ret|=m;
45
+ m=(_v>0xFU)<<2;
46
+ _v>>=m;
47
+ ret|=m;
48
+ m=(_v>3)<<1;
49
+ _v>>=m;
50
+ ret|=m;
51
+ ret+=_v>1;
52
+ return ret;
53
+ /*This de Bruijn sequence version is faster if you have a fast multiplier.*/
54
+ # else
55
+ int ret;
56
+ ret=_v>0;
57
+ _v|=_v>>1;
58
+ _v|=_v>>2;
59
+ _v|=_v>>4;
60
+ _v|=_v>>8;
61
+ _v|=_v>>16;
62
+ _v=(_v>>1)+1;
63
+ ret+=DEBRUIJN_IDX32[_v*0x77CB531U>>27&0x1F];
64
+ return ret;
65
+ # endif
66
+ }
67
+
68
+ int ilog32_nz(uint32_t _v)
69
+ {
70
+ return ilog32(_v);
71
+ }
72
+
73
+ int ilog64(uint64_t _v){
74
+ # if defined(ILOG_NODEBRUIJN)
75
+ uint32_t v;
76
+ int ret;
77
+ int m;
78
+ ret=_v>0;
79
+ m=(_v>0xFFFFFFFFU)<<5;
80
+ v=(uint32_t)(_v>>m);
81
+ ret|=m;
82
+ m=(v>0xFFFFU)<<4;
83
+ v>>=m;
84
+ ret|=m;
85
+ m=(v>0xFFU)<<3;
86
+ v>>=m;
87
+ ret|=m;
88
+ m=(v>0xFU)<<2;
89
+ v>>=m;
90
+ ret|=m;
91
+ m=(v>3)<<1;
92
+ v>>=m;
93
+ ret|=m;
94
+ ret+=v>1;
95
+ return ret;
96
+ # else
97
+ /*If we don't have a 64-bit word, split it into two 32-bit halves.*/
98
+ # if LONG_MAX<9223372036854775807LL
99
+ uint32_t v;
100
+ int ret;
101
+ int m;
102
+ ret=_v>0;
103
+ m=(_v>0xFFFFFFFFU)<<5;
104
+ v=(uint32_t)(_v>>m);
105
+ ret|=m;
106
+ v|=v>>1;
107
+ v|=v>>2;
108
+ v|=v>>4;
109
+ v|=v>>8;
110
+ v|=v>>16;
111
+ v=(v>>1)+1;
112
+ ret+=DEBRUIJN_IDX32[v*0x77CB531U>>27&0x1F];
113
+ return ret;
114
+ /*Otherwise do it in one 64-bit operation.*/
115
+ # else
116
+ static const unsigned char DEBRUIJN_IDX64[64]={
117
+ 0, 1, 2, 7, 3,13, 8,19, 4,25,14,28, 9,34,20,40,
118
+ 5,17,26,38,15,46,29,48,10,31,35,54,21,50,41,57,
119
+ 63, 6,12,18,24,27,33,39,16,37,45,47,30,53,49,56,
120
+ 62,11,23,32,36,44,52,55,61,22,43,51,60,42,59,58
121
+ };
122
+ int ret;
123
+ ret=_v>0;
124
+ _v|=_v>>1;
125
+ _v|=_v>>2;
126
+ _v|=_v>>4;
127
+ _v|=_v>>8;
128
+ _v|=_v>>16;
129
+ _v|=_v>>32;
130
+ _v=(_v>>1)+1;
131
+ ret+=DEBRUIJN_IDX64[_v*0x218A392CD3D5DBF>>58&0x3F];
132
+ return ret;
133
+ # endif
134
+ # endif
135
+ }
136
+
137
+ int ilog64_nz(uint64_t _v)
138
+ {
139
+ return ilog64(_v);
140
+ }
141
+
@@ -0,0 +1,151 @@
1
+ /* CC0 (Public domain) - see LICENSE file for details */
2
+ #if !defined(_ilog_H)
3
+ # define _ilog_H (1)
4
+ # include "config.h"
5
+ # include <stdint.h>
6
+ # include <limits.h>
7
+ # include <ccan/compiler/compiler.h>
8
+
9
+ /**
10
+ * ilog32 - Integer binary logarithm of a 32-bit value.
11
+ * @_v: A 32-bit value.
12
+ * Returns floor(log2(_v))+1, or 0 if _v==0.
13
+ * This is the number of bits that would be required to represent _v in two's
14
+ * complement notation with all of the leading zeros stripped.
15
+ * Note that many uses will resolve to the fast macro version instead.
16
+ *
17
+ * See Also:
18
+ * ilog32_nz(), ilog64()
19
+ *
20
+ * Example:
21
+ * // Rounds up to next power of 2 (if not a power of 2).
22
+ * static uint32_t round_up32(uint32_t i)
23
+ * {
24
+ * assert(i != 0);
25
+ * return 1U << ilog32(i-1);
26
+ * }
27
+ */
28
+ int ilog32(uint32_t _v) CONST_FUNCTION;
29
+
30
+ /**
31
+ * ilog32_nz - Integer binary logarithm of a non-zero 32-bit value.
32
+ * @_v: A 32-bit value.
33
+ * Returns floor(log2(_v))+1, or undefined if _v==0.
34
+ * This is the number of bits that would be required to represent _v in two's
35
+ * complement notation with all of the leading zeros stripped.
36
+ * Note that many uses will resolve to the fast macro version instead.
37
+ * See Also:
38
+ * ilog32(), ilog64_nz()
39
+ * Example:
40
+ * // Find Last Set (ie. highest bit set, 0 to 31).
41
+ * static uint32_t fls32(uint32_t i)
42
+ * {
43
+ * assert(i != 0);
44
+ * return ilog32_nz(i) - 1;
45
+ * }
46
+ */
47
+ int ilog32_nz(uint32_t _v) CONST_FUNCTION;
48
+
49
+ /**
50
+ * ilog64 - Integer binary logarithm of a 64-bit value.
51
+ * @_v: A 64-bit value.
52
+ * Returns floor(log2(_v))+1, or 0 if _v==0.
53
+ * This is the number of bits that would be required to represent _v in two's
54
+ * complement notation with all of the leading zeros stripped.
55
+ * Note that many uses will resolve to the fast macro version instead.
56
+ * See Also:
57
+ * ilog64_nz(), ilog32()
58
+ */
59
+ int ilog64(uint64_t _v) CONST_FUNCTION;
60
+
61
+ /**
62
+ * ilog64_nz - Integer binary logarithm of a non-zero 64-bit value.
63
+ * @_v: A 64-bit value.
64
+ * Returns floor(log2(_v))+1, or undefined if _v==0.
65
+ * This is the number of bits that would be required to represent _v in two's
66
+ * complement notation with all of the leading zeros stripped.
67
+ * Note that many uses will resolve to the fast macro version instead.
68
+ * See Also:
69
+ * ilog64(), ilog32_nz()
70
+ */
71
+ int ilog64_nz(uint64_t _v) CONST_FUNCTION;
72
+
73
+ /**
74
+ * STATIC_ILOG_32 - The integer logarithm of an (unsigned, 32-bit) constant.
75
+ * @_v: A non-negative 32-bit constant.
76
+ * Returns floor(log2(_v))+1, or 0 if _v==0.
77
+ * This is the number of bits that would be required to represent _v in two's
78
+ * complement notation with all of the leading zeros stripped.
79
+ * This macro should only be used when you need a compile-time constant,
80
+ * otherwise ilog32 or ilog32_nz are just as fast and more flexible.
81
+ *
82
+ * Example:
83
+ * #define MY_PAGE_SIZE 4096
84
+ * #define MY_PAGE_BITS (STATIC_ILOG_32(PAGE_SIZE) - 1)
85
+ */
86
+ #define STATIC_ILOG_32(_v) (STATIC_ILOG5((uint32_t)(_v)))
87
+
88
+ /**
89
+ * STATIC_ILOG_64 - The integer logarithm of an (unsigned, 64-bit) constant.
90
+ * @_v: A non-negative 64-bit constant.
91
+ * Returns floor(log2(_v))+1, or 0 if _v==0.
92
+ * This is the number of bits that would be required to represent _v in two's
93
+ * complement notation with all of the leading zeros stripped.
94
+ * This macro should only be used when you need a compile-time constant,
95
+ * otherwise ilog64 or ilog64_nz are just as fast and more flexible.
96
+ */
97
+ #define STATIC_ILOG_64(_v) (STATIC_ILOG6((uint64_t)(_v)))
98
+
99
+ /* Private implementation details */
100
+
101
+ /*Note the casts to (int) below: this prevents "upgrading"
102
+ the type of an entire expression to an (unsigned) size_t.*/
103
+ #if INT_MAX>=2147483647 && HAVE_BUILTIN_CLZ
104
+ #define builtin_ilog32_nz(v) \
105
+ (((int)sizeof(unsigned)*CHAR_BIT) - __builtin_clz(v))
106
+ #elif LONG_MAX>=2147483647L && HAVE_BUILTIN_CLZL
107
+ #define builtin_ilog32_nz(v) \
108
+ (((int)sizeof(unsigned)*CHAR_BIT) - __builtin_clzl(v))
109
+ #endif
110
+
111
+ #if INT_MAX>=9223372036854775807LL && HAVE_BUILTIN_CLZ
112
+ #define builtin_ilog64_nz(v) \
113
+ (((int)sizeof(unsigned)*CHAR_BIT) - __builtin_clz(v))
114
+ #elif LONG_MAX>=9223372036854775807LL && HAVE_BUILTIN_CLZL
115
+ #define builtin_ilog64_nz(v) \
116
+ (((int)sizeof(unsigned long)*CHAR_BIT) - __builtin_clzl(v))
117
+ #elif HAVE_BUILTIN_CLZLL
118
+ #define builtin_ilog64_nz(v) \
119
+ (((int)sizeof(unsigned long long)*CHAR_BIT) - __builtin_clzll(v))
120
+ #endif
121
+
122
+ #ifdef builtin_ilog32_nz
123
+ #define ilog32(_v) (builtin_ilog32_nz(_v)&-!!(_v))
124
+ #define ilog32_nz(_v) builtin_ilog32_nz(_v)
125
+ #else
126
+ #define ilog32_nz(_v) ilog32(_v)
127
+ #define ilog32(_v) (IS_COMPILE_CONSTANT(_v) ? STATIC_ILOG_32(_v) : ilog32(_v))
128
+ #endif /* builtin_ilog32_nz */
129
+
130
+ #ifdef builtin_ilog64_nz
131
+ #define ilog64(_v) (builtin_ilog64_nz(_v)&-!!(_v))
132
+ #define ilog64_nz(_v) builtin_ilog64_nz(_v)
133
+ #else
134
+ #define ilog64_nz(_v) ilog64(_v)
135
+ #define ilog64(_v) (IS_COMPILE_CONSTANT(_v) ? STATIC_ILOG_64(_v) : ilog64(_v))
136
+ #endif /* builtin_ilog64_nz */
137
+
138
+ /* Macros for evaluating compile-time constant ilog. */
139
+ # define STATIC_ILOG0(_v) (!!(_v))
140
+ # define STATIC_ILOG1(_v) (((_v)&0x2)?2:STATIC_ILOG0(_v))
141
+ # define STATIC_ILOG2(_v) (((_v)&0xC)?2+STATIC_ILOG1((_v)>>2):STATIC_ILOG1(_v))
142
+ # define STATIC_ILOG3(_v) \
143
+ (((_v)&0xF0)?4+STATIC_ILOG2((_v)>>4):STATIC_ILOG2(_v))
144
+ # define STATIC_ILOG4(_v) \
145
+ (((_v)&0xFF00)?8+STATIC_ILOG3((_v)>>8):STATIC_ILOG3(_v))
146
+ # define STATIC_ILOG5(_v) \
147
+ (((_v)&0xFFFF0000)?16+STATIC_ILOG4((_v)>>16):STATIC_ILOG4(_v))
148
+ # define STATIC_ILOG6(_v) \
149
+ (((_v)&0xFFFFFFFF00000000ULL)?32+STATIC_ILOG5((_v)>>32):STATIC_ILOG5(_v))
150
+
151
+ #endif /* _ilog_H */
@@ -0,0 +1,17 @@
1
+ Permission is hereby granted, free of charge, to any person obtaining a copy
2
+ of this software and associated documentation files (the "Software"), to deal
3
+ in the Software without restriction, including without limitation the rights
4
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5
+ copies of the Software, and to permit persons to whom the Software is
6
+ furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in
9
+ all copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
17
+ THE SOFTWARE.
@@ -0,0 +1,72 @@
1
+ #include "config.h"
2
+ #include <stdio.h>
3
+ #include <string.h>
4
+
5
+ /**
6
+ * list - double linked list routines
7
+ *
8
+ * The list header contains routines for manipulating double linked lists.
9
+ * It defines two types: struct list_head used for anchoring lists, and
10
+ * struct list_node which is usually embedded in the structure which is placed
11
+ * in the list.
12
+ *
13
+ * Example:
14
+ * #include <err.h>
15
+ * #include <stdio.h>
16
+ * #include <stdlib.h>
17
+ * #include <ccan/list/list.h>
18
+ *
19
+ * struct parent {
20
+ * const char *name;
21
+ * struct list_head children;
22
+ * unsigned int num_children;
23
+ * };
24
+ *
25
+ * struct child {
26
+ * const char *name;
27
+ * struct list_node list;
28
+ * };
29
+ *
30
+ * int main(int argc, char *argv[])
31
+ * {
32
+ * struct parent p;
33
+ * struct child *c;
34
+ * int i;
35
+ *
36
+ * if (argc < 2)
37
+ * errx(1, "Usage: %s parent children...", argv[0]);
38
+ *
39
+ * p.name = argv[1];
40
+ * list_head_init(&p.children);
41
+ * p.num_children = 0;
42
+ * for (i = 2; i < argc; i++) {
43
+ * c = malloc(sizeof(*c));
44
+ * c->name = argv[i];
45
+ * list_add(&p.children, &c->list);
46
+ * p.num_children++;
47
+ * }
48
+ *
49
+ * printf("%s has %u children:", p.name, p.num_children);
50
+ * list_for_each(&p.children, c, list)
51
+ * printf("%s ", c->name);
52
+ * printf("\n");
53
+ * return 0;
54
+ * }
55
+ *
56
+ * License: BSD-MIT
57
+ * Author: Rusty Russell <rusty@rustcorp.com.au>
58
+ */
59
+ int main(int argc, char *argv[])
60
+ {
61
+ if (argc != 2)
62
+ return 1;
63
+
64
+ if (strcmp(argv[1], "depends") == 0) {
65
+ printf("ccan/str\n");
66
+ printf("ccan/container_of\n");
67
+ printf("ccan/check_type\n");
68
+ return 0;
69
+ }
70
+
71
+ return 1;
72
+ }