SDL_systhread.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2022 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_error.h"
  25. #include "SDL_thread.h"
  26. #include "../SDL_systhread.h"
  27. #include "../SDL_thread_c.h"
  28. };
  29. static int object_count;
  30. static int
  31. RunThread(TAny* data)
  32. {
  33. SDL_RunThread((SDL_Thread*)data);
  34. return(0);
  35. }
  36. static TInt
  37. NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2)
  38. {
  39. return ((RThread*)(aPtr1))->Create
  40. (aName,
  41. RunThread,
  42. KDefaultStackSize,
  43. NULL,
  44. aPtr2);
  45. }
  46. int
  47. CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny* aPtr1, TAny* aPtr2)
  48. {
  49. TBuf<16> name;
  50. TInt status = KErrNone;
  51. do
  52. {
  53. object_count++;
  54. name.Format(_L("SDL_%x"), object_count);
  55. status = aFunc(name, aPtr1, aPtr2);
  56. }
  57. while(status == KErrAlreadyExists);
  58. return status;
  59. }
  60. int
  61. SDL_SYS_CreateThread(SDL_Thread *thread)
  62. {
  63. RThread rthread;
  64. TInt status = CreateUnique(NewThread, &rthread, thread);
  65. if (status != KErrNone)
  66. {
  67. delete(((RThread*)(thread->handle)));
  68. thread->handle = NULL;
  69. SDL_SetError("Not enough resources to create thread");
  70. return(-1);
  71. }
  72. rthread.Resume();
  73. thread->handle = rthread.Handle();
  74. return(0);
  75. }
  76. void
  77. SDL_SYS_SetupThread(const char *name)
  78. {
  79. return;
  80. }
  81. SDL_threadID
  82. SDL_ThreadID(void)
  83. {
  84. RThread current;
  85. TThreadId id = current.Id();
  86. return id;
  87. }
  88. int
  89. SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
  90. {
  91. return (0);
  92. }
  93. void
  94. SDL_SYS_WaitThread(SDL_Thread * thread)
  95. {
  96. RThread t;
  97. t.Open(thread->threadid);
  98. if(t.ExitReason() == EExitPending)
  99. {
  100. TRequestStatus status;
  101. t.Logon(status);
  102. User::WaitForRequest(status);
  103. }
  104. t.Close();
  105. }
  106. void
  107. SDL_SYS_DetachThread(SDL_Thread * thread)
  108. {
  109. return;
  110. }
  111. #endif /* SDL_THREAD_NGAGE */
  112. /* vim: ts=4 sw=4
  113. */