SDL_systhread.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_internal.h"
  19. #if SDL_THREAD_NGAGE
  20. /* N-Gage thread management routines for SDL */
  21. #include <e32std.h>
  22. extern "C" {
  23. #undef NULL
  24. #include "../SDL_systhread.h"
  25. #include "../SDL_thread_c.h"
  26. };
  27. static int object_count;
  28. static int RunThread(TAny *data)
  29. {
  30. SDL_RunThread((SDL_Thread *)data);
  31. return 0;
  32. }
  33. static TInt NewThread(const TDesC &aName, TAny *aPtr1, TAny *aPtr2)
  34. {
  35. return ((RThread *)(aPtr1))->Create(aName, RunThread, KDefaultStackSize, NULL, aPtr2);
  36. }
  37. int CreateUnique(TInt (*aFunc)(const TDesC &aName, TAny *, TAny *), TAny *aPtr1, TAny *aPtr2)
  38. {
  39. TBuf<16> name;
  40. TInt status = KErrNone;
  41. do {
  42. object_count++;
  43. name.Format(_L("SDL_%x"), object_count);
  44. status = aFunc(name, aPtr1, aPtr2);
  45. } while (status == KErrAlreadyExists);
  46. return status;
  47. }
  48. int SDL_SYS_CreateThread(SDL_Thread *thread)
  49. {
  50. RThread rthread;
  51. TInt status = CreateUnique(NewThread, &rthread, thread);
  52. if (status != KErrNone) {
  53. delete (RThread *)thread->handle;
  54. thread->handle = NULL;
  55. return SDL_SetError("Not enough resources to create thread");
  56. }
  57. rthread.Resume();
  58. thread->handle = rthread.Handle();
  59. return 0;
  60. }
  61. void SDL_SYS_SetupThread(const char *name)
  62. {
  63. return;
  64. }
  65. SDL_threadID
  66. SDL_ThreadID(void)
  67. {
  68. RThread current;
  69. TThreadId id = current.Id();
  70. return id;
  71. }
  72. int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
  73. {
  74. return 0;
  75. }
  76. void SDL_SYS_WaitThread(SDL_Thread *thread)
  77. {
  78. RThread t;
  79. t.Open(thread->threadid);
  80. if (t.ExitReason() == EExitPending) {
  81. TRequestStatus status;
  82. t.Logon(status);
  83. User::WaitForRequest(status);
  84. }
  85. t.Close();
  86. }
  87. void SDL_SYS_DetachThread(SDL_Thread *thread)
  88. {
  89. return;
  90. }
  91. #endif /* SDL_THREAD_NGAGE */
  92. /* vim: ts=4 sw=4
  93. */