Created
June 24, 2016 21:59
-
-
Save cwoodall/5c1db855d896d4476111f273f2f631ea to your computer and use it in GitHub Desktop.
Intersting C++ embedded process runner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdint.h> | |
using namespace std; | |
template <uint32_t f> | |
bool ProcessTask(void); | |
template <uint32_t f> | |
uint32_t RunProcess(uint32_t start) { | |
static uint32_t previous_time{start}; | |
static uint32_t iterations{0}; | |
while (start - previous_time >= 1000000/f) { | |
if (ProcessTask<f>()) { | |
previous_time += 1000000 / f; | |
++iterations; | |
} else { | |
break; | |
} | |
} | |
return iterations; | |
} | |
template <> | |
bool ProcessTask<200>(void) { | |
cout << "foo "; | |
return true; | |
} | |
template <> | |
bool ProcessTask<1000>(void) { | |
cout << "bar "; | |
return true; | |
} | |
template <> | |
bool ProcessTask<400>(void) { | |
cout << "meow" << endl; | |
return true; | |
} | |
int main(void) { | |
for (uint32_t i = 0; i < 1000000; i++) { | |
// if (i%100000) { | |
// cout << "t = " << i<< endl; | |
// } | |
// cout << "> Loop at t = " << i << endl; | |
/*cout << << "> P1 Iterations: " << */ RunProcess<1000>(i*100); | |
/*cout << << "> P2 Iterations: " << */ RunProcess<200>(i*100); | |
/*cout << << "> P3 Iterations: " << */ RunProcess<400>(i*100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
based off of flybrix