-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
GUSTAVO CAMPOS
authored and
GUSTAVO CAMPOS
committed
Aug 24, 2020
1 parent
16c6a68
commit 8486130
Showing
5 changed files
with
124 additions
and
56 deletions.
There are no files selected for viewing
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
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <sys/time.h> | ||
#include <unistd.h> | ||
#include <assert.h> | ||
|
||
#include "CorePartition.h" | ||
|
||
void Thread1(void* pValue) | ||
{ | ||
int nValue = 0; | ||
|
||
while (CorePartition_Yield()) | ||
{ | ||
printf ("Thread %zu: Value [%d] every %u ms\n", CorePartition_GetID(), nValue++, CorePartition_GetNice()); | ||
} | ||
} | ||
|
||
void Thread2(void* pValue) | ||
{ | ||
int nValue = 0; | ||
|
||
while (CorePartition_Yield()) | ||
{ | ||
printf ("Thread %zu: Value [%d] every %u ms\n", CorePartition_GetID(), nValue++, CorePartition_GetNice()); | ||
} | ||
} | ||
|
||
void CorePartition_SleepTicks (uint32_t nSleepTime) | ||
{ | ||
usleep ((useconds_t) nSleepTime * 1000); | ||
} | ||
|
||
uint32_t CorePartition_GetCurrentTick(void) | ||
{ | ||
struct timeval tp; | ||
gettimeofday(&tp, NULL); | ||
|
||
return (uint32_t) tp.tv_sec * 1000 + tp.tv_usec / 1000; //get current timestamp in milliseconds | ||
} | ||
|
||
static void StackOverflowHandler () | ||
{ | ||
printf ("Error, Thread#%zu Stack %zu / %zu max\n", CorePartition_GetID(), CorePartition_GetStackSize(), CorePartition_GetMaxStackSize()); | ||
} | ||
|
||
|
||
int main () | ||
{ | ||
|
||
assert (CorePartition_Start (3)); | ||
|
||
assert (CorePartition_SetStackOverflowHandler (StackOverflowHandler)); | ||
|
||
//Every 1000 cycles with a Stack page of 210 bytes | ||
assert (CorePartition_CreateThread (Thread1, NULL, 210, 1000)); | ||
|
||
//All the time with a Stack page of 150 bytes and | ||
//thread isolation | ||
assert (CorePartition_CreateSecureThread (Thread2, NULL, 150, 2000)); | ||
|
||
assert (CorePartition_CreateSecureThread (Thread2, NULL, 150, 500)); | ||
|
||
CorePartition_Join(); | ||
} |
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
Oops, something went wrong.