-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.c
More file actions
44 lines (35 loc) · 696 Bytes
/
Copy pathdebug.c
File metadata and controls
44 lines (35 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <assert.h>
#include <sched.h>
#include "debug.h"
char debugFlags[256];
int debugYieldOn = 0;
static unsigned int randYieldSeed;
static unsigned int yieldPercent;
void
Debug_Init(char *flags, int yieldpercentage, unsigned int randseed)
{
char *c = flags;
while (*c) {
Debug_SetFlag(*c, 1);
c++;
}
if (yieldpercentage) {
debugYieldOn = 1;
randYieldSeed = randseed;
yieldPercent= yieldpercentage;
}
}
void
Debug_SetFlag(char ch, int val)
{
debugFlags[(int)ch] = val;
}
void
Debug_Yield(void)
{
unsigned int rand = rand_r(&randYieldSeed) % 100;
if (rand < yieldPercent) sched_yield();
}