Added common include for simple C programs, and threads-intro code
This commit is contained in:
21
include/common.h
Normal file
21
include/common.h
Normal 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__
|
||||
Reference in New Issue
Block a user