µGFX library fork

main.c 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "gfx.h"
  2. #if defined(WIN32)
  3. #include <windows.h>
  4. static DWORD nres;
  5. // On Win32 don't use the C library fprintf or write as they crash.
  6. // Maybe we just need to add the multi-thread C library options to the compile.
  7. // Instead we use the Win32 API directly as that always works.
  8. #define DEBUGWRITE(str) WriteFile(GetStdHandle(STD_ERROR_HANDLE), str, strlen(str), &nres, 0)
  9. #else
  10. #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT
  11. #warning "You must alter this demo to define a DEBUGWRITE macro for your platform."
  12. #warning "Be careful of using C library functions as they sometimes crash if they are not expecting stack changes (if possible use a multi-thread aware C library)"
  13. #warning "You might flash LED's instead if that is better for your platform."
  14. #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO
  15. COMPILER_WARNING("You must alter this demo to define a DEBUGWRITE macro for your platform.")
  16. COMPILER_WARNING("Be careful of using C library functions as they sometimes crash if they are not expecting stack changes (if possible use a multi-thread aware C library)")
  17. COMPILER_WARNING("You might flash LED's instead if that is better for your platform.")
  18. #endif
  19. #error "--"
  20. #endif
  21. threadreturn_t heartbeat1(void* param)
  22. {
  23. (void)param;
  24. while (TRUE) {
  25. DEBUGWRITE("thread 1\n");
  26. gfxSleepMilliseconds(500);
  27. }
  28. return (threadreturn_t)0;
  29. }
  30. threadreturn_t heartbeat2(void* param)
  31. {
  32. (void)param;
  33. while (TRUE) {
  34. DEBUGWRITE("thread 2\n");
  35. gfxSleepMilliseconds(900);
  36. }
  37. return (threadreturn_t)0;
  38. }
  39. int main(void)
  40. {
  41. gfxInit();
  42. // Give this plenty of stack. Stack size optimisation should be a production change only
  43. gfxThreadCreate(0, 2048, NORMAL_PRIORITY, heartbeat1, 0);
  44. gfxThreadCreate(0, 2048, NORMAL_PRIORITY, heartbeat2, 0);
  45. while (TRUE) {
  46. DEBUGWRITE("thread main\n");
  47. gfxSleepMilliseconds(1400);
  48. }
  49. }