Initial programs from intro chapter

This commit is contained in:
Remzi Arpaci-Dusseau
2018-08-15 11:52:29 -05:00
parent 54a012aa8e
commit f90b42f9fa
7 changed files with 165 additions and 0 deletions

21
intro/common.h Normal file
View File

@@ -0,0 +1,21 @@
#ifndef __common_h__
#define __common_h__
#include <sys/time.h>
#include <sys/stat.h>
#include <assert.h>
double GetTime() {
struct timeval t;
int rc = gettimeofday(&t, NULL);
assert(rc == 0);
return (double) t.tv_sec + (double) t.tv_usec/1e6;
}
void Spin(int howlong) {
double t = GetTime();
while ((GetTime() - t) < (double) howlong)
; // do nothing in loop
}
#endif // __common_h__