root/src/noit_defines.h

Revision 3347d53135a735b1a63caebd183d91dae3088dd3, 4.0 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 3 years ago)

Do away with the initial stutter and randomness as it was and equally
space checks out in 20ms buckets with jitter within those buckets.

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007-2009, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  *       notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  *       copyright notice, this list of conditions and the following
13  *       disclaimer in the documentation and/or other materials provided
14  *       with the distribution.
15  *     * Neither the name OmniTI Computer Consulting, Inc. nor the names
16  *       of its contributors may be used to endorse or promote products
17  *       derived from this software without specific prior written
18  *       permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _NOIT_DEFINES_H
34 #define _NOIT_DEFINES_H
35
36 #include "noit_config.h"
37
38 #ifndef __FUNCTION__
39 #define __FUNCTION__ __func__
40 #endif
41
42 #define API_EXPORT(type) extern type
43
44 static inline int compare_timeval(struct timeval a, struct timeval b) {
45   if (a.tv_sec < b.tv_sec) return -1;
46   if (a.tv_sec > b.tv_sec) return 1;
47   if (a.tv_usec < b.tv_usec) return -1;
48   if (a.tv_usec > b.tv_usec) return 1;
49   return 0;
50 }
51
52 static inline void sub_timeval(struct timeval a, struct timeval b,
53                                struct timeval *out)
54 {
55   out->tv_usec = a.tv_usec - b.tv_usec;
56   if (out->tv_usec < 0L) {
57     a.tv_sec--;
58     out->tv_usec += 1000000L;
59   }
60   out->tv_sec = a.tv_sec - b.tv_sec;
61   if (out->tv_sec < 0L) {
62     out->tv_sec++;
63     out->tv_usec -= 1000000L;
64   }
65 }
66
67 static inline double sub_timeval_d(struct timeval a, struct timeval b)
68 {
69   struct timeval d;
70   sub_timeval(a,b,&d);
71   return (double)d.tv_sec + (double)d.tv_usec / 1000000.0;
72 }
73
74 static inline void add_timeval(struct timeval a, struct timeval b,
75                                struct timeval *out)
76 {
77   out->tv_usec = a.tv_usec + b.tv_usec;
78   if (out->tv_usec > 1000000L) {
79     a.tv_sec++;
80     out->tv_usec -= 1000000L;
81   }
82   out->tv_sec = a.tv_sec + b.tv_sec;
83 }
84
85 #undef UUID_STR_LEN
86 #define UUID_STR_LEN 36
87 #ifndef HAVE_UUID_UNPARSE_LOWER
88 /* Sigh, need to implement out own */
89 #include <uuid/uuid.h>
90 #include <ctype.h>
91 static inline void uuid_unparse_lower(uuid_t in, char *out) {
92   int i;
93   uuid_unparse(in, out);
94   for(i=0;i<36;i++) out[i] = tolower(out[i]);
95 }
96 #endif
97
98 #ifdef HAVE_TERMIO_H
99 #define USE_TERMIO
100 #endif
101
102 #ifndef MIN
103 #define MIN(x,y)  ((x) < (y) ? (x) : (y))
104 #endif
105 #ifndef MAX
106 #define MAX(x,y)  ((x) > (y) ? (x) : (y))
107 #endif
108 #ifndef SUN_LEN
109 #define SUN_LEN(ptr) (sizeof(*(ptr)) - sizeof((ptr)->sun_path) + strlen((ptr)->sun_path))
110 #endif
111
112 /* This is for udns */
113 #ifdef HAVE_INET_PTON
114 #ifdef HAVE_INET_NTOP
115 #define HAVE_INET_PTON_NTOP 1
116 #endif
117 #endif
118 /* udns checks for IPv6, noit doesn't work without it */
119 #define HAVE_IPv6
120
121 #if defined(__sun) && !defined(HAVE_POSIX_READDIR_R)
122 #define portable_readdir_r(a,b,c) (((*(c)) = readdir_r(a,b)) == NULL)
123 #else
124 #define portable_readdir_r readdir_r
125 #endif
126 #include "noitedit/strlcpy.h"
127
128 #define UUID_REGEX "[0-9a-fA-F]{4}(?:[0-9a-fA-F]{4}-){4}[0-9a-fA-F]{12}"
129 #include <uuid/uuid.h>
130 struct uuid_dummy { uuid_t foo; };
131 #define UUID_SIZE sizeof(struct uuid_dummy)
132
133 #endif
Note: See TracBrowser for help on using the browser.