pte_psp.html 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>PTE on PSP OS</title></head><body>
  3. <meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8"><title></title><meta name="GENERATOR" content="OpenOffice.org 2.3 (Linux)">
  4. <style type="text/css">
  5. <!--
  6. @page { size: 8.5in 11in; margin: 0.79in }
  7. P { margin-bottom: 0.08in }
  8. H1 { margin-bottom: 0.08in }
  9. H1.western { font-family: "Helvetica"; font-size: 16pt }
  10. H1.cjk { font-family: "AR PL ShanHeiSun Uni"; font-size: 16pt }
  11. H1.ctl { font-family: "Tahoma"; font-size: 16pt }
  12. -->
  13. </style>
  14. <p style="margin-bottom: 0in;"><big><big><big><span style="font-weight: bold;">PTE on PSP OS</span></big></big></big></p><p style="margin-bottom: 0in;"><br>
  15. </p>
  16. <p style="margin-bottom: 0in;">All PSP OS objects that are created
  17. require a name to be associated with them. The name must be unique
  18. among objects that currently exist. To accomplish this, any routines
  19. that allocate OS objects (e.g. <font face="Courier New, monospace">OsMutexCreate</font>)
  20. keep a static local variable that acts as a counter and is
  21. incremented every time an object is created. This value is appended
  22. to the name of the resource. For instance &#8220;mutex04&#8221; would be the
  23. name of the fourth mutex created.</p>
  24. <p style="margin-bottom: 0in;"><br>
  25. </p>
  26. <h1 class="western">Thread creation</h1>
  27. <p><font face="Courier New, monospace">OsThreadCreate</font>
  28. allocates a <font face="Courier New, monospace">pspThreadData</font>
  29. structure that contains a semaphore used for cancelling a thread, the
  30. thread's entry point and parameters to the thread's entry point. A
  31. pointer to this structure is stored as a TLS value.</p>
  32. <p style="margin-bottom: 0in;"><font face="Courier New, monospace">OsThreadCreate</font>
  33. calls <font face="Courier New, monospace">sceKernelCreateThread</font>
  34. with a entry point of <font face="Courier New, monospace">pspStubThreadEntry</font>.
  35. The stub entry point retrieves the per thread control structure
  36. (allocated during <font face="Courier New, monospace">OsThreadCreate</font>)
  37. and gets the thread's real entry point and parameters and then calls
  38. the real entry point.</p>
  39. <p style="margin-bottom: 0in;"><br>
  40. </p>
  41. <h1 class="western">Thread Local Storage</h1>
  42. <p style="margin-bottom: 0in;">Unfortunately, PSP OS does not include
  43. <b>any</b> kind of thread local storage functionality. To emulate
  44. TLS, when a new POSIX thread is created, a structure is allocated to
  45. contain TLS keys and values. A pointer to this structure is appended
  46. to the thread name. For instance, a new threads name might be
  47. &#8220;pthread10_80001234&#8221;, where 0x80001234 is the address of the TLS
  48. structure. When a thread wants to access TLS information, it
  49. retrieves the thread's name from the OS, parses the name to extract
  50. the pointer and then utilizes the TLS helper library to set or get
  51. TLS values.
  52. </p>
  53. <p style="margin-bottom: 0in;"><br>
  54. </p>
  55. <p style="margin-bottom: 0in;">Unfortunately, this mechanism only
  56. works for threads that are created through pthread_create; it does
  57. not work for OS threads that are using pthread calls. To emulate
  58. this (at this for one thread) we allocate a single TLS structure
  59. (like the ones associated with each POSIX thread). This &#8220;global&#8221;
  60. TLS structure is used when pthread is called from a non-POSIX OS
  61. thread. This introduces the important limitation that pthread calls
  62. can be made from ONLY ONE non-POSIX OS thread. Behavior when calling
  63. from multiple different non-POSIX OS threads is undefined.</p>
  64. <p style="margin-bottom: 0in;"><br>
  65. </p>
  66. <h1 class="western">Mutexes</h1>
  67. <p style="margin-bottom: 0in;">PSP OS does not supply routines for
  68. mutexes. A counting semaphore initialized to 0 is used.</p>
  69. <p style="margin-bottom: 0in;"><br>
  70. </p>
  71. <h1 class="western">Thread Cancellation</h1>
  72. <p style="margin-bottom: 0in;">Since PSP OS does not natively provide
  73. a way to break out of blocked operations, this functionality is
  74. emulated using a cancellation semaphore that is stored in the per
  75. thread control data. When the user requests that a thread be
  76. cancelled (i.e. <font face="Courier New, monospace">OsThreadCancel</font>
  77. is called) this semaphore is posted to. In
  78. <font face="Courier New, monospace">OsSemaphoreCancellablePend</font>,
  79. the cancellation semaphore as well as the user semaphore are polled
  80. (rather than blocking) and the routine returns if the cancellation
  81. semaphore is posted to. A similar technique is used for
  82. <font face="Courier New, monospace">OsThreadWaitForEnd</font>.</p>
  83. </body></html>