aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Jackson2006-02-20 17:09:00 -0600
committerAdam Jackson2006-02-20 17:09:00 -0600
commit22e41ef08338ae6dd59acbe6d4d8e50d83672816 (patch)
tree29bc22ae9a7be2d54b974500e92366122e1c60a3 /libdrm/xf86drmRandom.c
parent0a211db23c0d7e22946aa25f22e9aeab6783b617 (diff)
downloadexternal-libgbm-22e41ef08338ae6dd59acbe6d4d8e50d83672816.tar.gz
external-libgbm-22e41ef08338ae6dd59acbe6d4d8e50d83672816.tar.xz
external-libgbm-22e41ef08338ae6dd59acbe6d4d8e50d83672816.zip
Formatting cleanup, dead code removal. Remove N() namespacing macro,
useless. Remove SIGIO handling functions as they're server-only and properly belong in libdri.
Diffstat (limited to 'libdrm/xf86drmRandom.c')
-rw-r--r--libdrm/xf86drmRandom.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/libdrm/xf86drmRandom.c b/libdrm/xf86drmRandom.c
index 301aaf4c..3f5bf611 100644
--- a/libdrm/xf86drmRandom.c
+++ b/libdrm/xf86drmRandom.c
@@ -94,8 +94,6 @@
94# endif 94# endif
95#endif 95#endif
96 96
97#define N(x) drm##x
98
99#define RANDOM_MAGIC 0xfeedbeef 97#define RANDOM_MAGIC 0xfeedbeef
100#define RANDOM_DEBUG 0 98#define RANDOM_DEBUG 0
101 99
@@ -118,13 +116,13 @@ typedef struct RandomState {
118} RandomState; 116} RandomState;
119 117
120#if RANDOM_MAIN 118#if RANDOM_MAIN
121extern void *N(RandomCreate)(unsigned long seed); 119extern void *drmRandomCreate(unsigned long seed);
122extern int N(RandomDestroy)(void *state); 120extern int drmRandomDestroy(void *state);
123extern unsigned long N(Random)(void *state); 121extern unsigned long drmRandom(void *state);
124extern double N(RandomDouble)(void *state); 122extern double drmRandomDouble(void *state);
125#endif 123#endif
126 124
127void *N(RandomCreate)(unsigned long seed) 125void *drmRandomCreate(unsigned long seed)
128{ 126{
129 RandomState *state; 127 RandomState *state;
130 128
@@ -154,13 +152,13 @@ void *N(RandomCreate)(unsigned long seed)
154 return state; 152 return state;
155} 153}
156 154
157int N(RandomDestroy)(void *state) 155int drmRandomDestroy(void *state)
158{ 156{
159 RANDOM_FREE(state); 157 RANDOM_FREE(state);
160 return 0; 158 return 0;
161} 159}
162 160
163unsigned long N(Random)(void *state) 161unsigned long drmRandom(void *state)
164{ 162{
165 RandomState *s = (RandomState *)state; 163 RandomState *s = (RandomState *)state;
166 long hi; 164 long hi;
@@ -174,11 +172,11 @@ unsigned long N(Random)(void *state)
174 return s->seed; 172 return s->seed;
175} 173}
176 174
177double N(RandomDouble)(void *state) 175double drmRandomDouble(void *state)
178{ 176{
179 RandomState *s = (RandomState *)state; 177 RandomState *s = (RandomState *)state;
180 178
181 return (double)N(Random)(state)/(double)s->m; 179 return (double)drmRandom(state)/(double)s->m;
182} 180}
183 181
184#if RANDOM_MAIN 182#if RANDOM_MAIN
@@ -188,15 +186,15 @@ static void check_period(long seed)
188 unsigned long initial; 186 unsigned long initial;
189 void *state; 187 void *state;
190 188
191 state = N(RandomCreate)(seed); 189 state = drmRandomCreate(seed);
192 initial = N(Random)(state); 190 initial = drmRandom(state);
193 ++count; 191 ++count;
194 while (initial != N(Random)(state)) { 192 while (initial != drmRandom(state)) {
195 if (!++count) break; 193 if (!++count) break;
196 } 194 }
197 printf("With seed of %10ld, period = %10lu (0x%08lx)\n", 195 printf("With seed of %10ld, period = %10lu (0x%08lx)\n",
198 seed, count, count); 196 seed, count, count);
199 N(RandomDestroy)(state); 197 drmRandomDestroy(state);
200} 198}
201 199
202int main(void) 200int main(void)
@@ -205,14 +203,14 @@ int main(void)
205 int i; 203 int i;
206 unsigned long rand; 204 unsigned long rand;
207 205
208 state = N(RandomCreate)(1); 206 state = drmRandomCreate(1);
209 for (i = 0; i < 10000; i++) { 207 for (i = 0; i < 10000; i++) {
210 rand = N(Random)(state); 208 rand = drmRandom(state);
211 } 209 }
212 printf("After 10000 iterations: %lu (%lu expected): %s\n", 210 printf("After 10000 iterations: %lu (%lu expected): %s\n",
213 rand, state->check, 211 rand, state->check,
214 rand - state->check ? "*INCORRECT*" : "CORRECT"); 212 rand - state->check ? "*INCORRECT*" : "CORRECT");
215 N(RandomDestroy)(state); 213 drmRandomDestroy(state);
216 214
217 printf("Checking periods...\n"); 215 printf("Checking periods...\n");
218 check_period(1); 216 check_period(1);