Add helper functions for thread testing.
This commit is contained in:
parent
0009ee0b80
commit
ce8a0f09a4
@ -194,5 +194,7 @@ void kprintf_bootstrap(void);
|
|||||||
#define DIVROUNDUP(a,b) (((a)+(b)-1)/(b))
|
#define DIVROUNDUP(a,b) (((a)+(b)-1)/(b))
|
||||||
#define ROUNDUP(a,b) (DIVROUNDUP(a,b)*b)
|
#define ROUNDUP(a,b) (DIVROUNDUP(a,b)*b)
|
||||||
|
|
||||||
|
void random_yielder(uint32_t);
|
||||||
|
void random_spinner(uint32_t);
|
||||||
|
|
||||||
#endif /* _LIB_H_ */
|
#endif /* _LIB_H_ */
|
||||||
|
@ -40,6 +40,6 @@
|
|||||||
* testing.
|
* testing.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define KERNEL_PROMPT "OS/161 kernel [? for menu]: "
|
#define KERNEL_PROMPT "OS/161 kernel [? for menu]: "
|
||||||
|
|
||||||
#endif /* _OVERWRITE_H_ */
|
#endif /* _OVERWRITE_H_ */
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <types.h>
|
#include <types.h>
|
||||||
#include <kern/errmsg.h>
|
#include <kern/errmsg.h>
|
||||||
#include <lib.h>
|
#include <lib.h>
|
||||||
|
#include <thread.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Like strdup, but calls kmalloc.
|
* Like strdup, but calls kmalloc.
|
||||||
@ -60,3 +61,27 @@ strerror(int errcode)
|
|||||||
panic("Invalid error code %d\n", errcode);
|
panic("Invalid error code %d\n", errcode);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Helper functions used by testing and problem driver code
|
||||||
|
* to establish better mixtures of threads.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
random_yielder(uint32_t max_yield_count)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
for (i = 0; i < random() % max_yield_count; i++) {
|
||||||
|
thread_yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
random_spinner(uint32_t max_spin_count)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
volatile int spin;
|
||||||
|
for (i = 0; i < random() % max_spin_count; i++) {
|
||||||
|
spin += i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user