Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
5.4 KiB

  1. #include "precomp.h"
  2. //
  3. // SHM.CPP
  4. // Shared Memory Access, cpi32 and display driver sides both
  5. //
  6. // Copyright(c) Microsoft 1997-
  7. //
  8. #define MLZ_FILE_ZONE ZONE_CORE
  9. //
  10. // WAIT_FOR_BUFFER
  11. //
  12. // Wait until the display driver is accessing the new buffer.
  13. //
  14. // There are logically 8 states for a set of 3 boolean variables. We can
  15. // cut this down to 4 by some simple analysis:
  16. //
  17. // - The overall busy flag overrides the other flags if it is clear.
  18. // - We can never have the display driver in both buffers (it's single
  19. // threaded).
  20. //
  21. // So the 4 states are as follows.
  22. //
  23. // STATE BUSY FLAGS DISPLAY DRIVER STATE
  24. // New Old Overall
  25. //
  26. // 1 0 0 0 Not using shared memory
  27. // 2 0 0 1 Using shared memory (wait to see which)
  28. // 3 1 0 1 Using the new buffer
  29. // 4 0 1 1 Using the old buffer
  30. //
  31. // Obviously we wait while states 2 or 4 hold true....
  32. //
  33. #define WAIT_FOR_BUFFER(MEMORY, NEWBUFFER, OLDBUFFER) \
  34. while ( g_asSharedMemory->MEMORY.busyFlag && \
  35. ( g_asSharedMemory->MEMORY.bufferBusy[OLDBUFFER] || \
  36. !g_asSharedMemory->MEMORY.bufferBusy[NEWBUFFER] ) ) \
  37. { \
  38. TRACE_OUT(("Waiting for SHM")); \
  39. Sleep(0); \
  40. }
  41. //
  42. // SHM_SwitchReadBuffer - see shm.h
  43. //
  44. void SHM_SwitchReadBuffer(void)
  45. {
  46. int oldBuffer;
  47. int newBuffer;
  48. DebugEntry(SHM_SwitchReadBuffer);
  49. //
  50. //
  51. // BUFFER SWITCHING FOR THE DISPLAY DRIVER -> SHARE CORE DATA
  52. //
  53. //
  54. // This is a forced switch. The Share Core calls this function only
  55. // when it wants to force the switching of the buffers used to pass the
  56. // data back from the display driver.
  57. //
  58. //
  59. // �����������������������������������������������������ͻ
  60. // � Kernel to Share Core data block �
  61. // � ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ �
  62. // � ���������������Ŀ ���������������Ŀ �
  63. // � � � BUSY FLAG1 � � �
  64. // � � Share Core � 1 � Display Driver� �
  65. // � � � � � �
  66. // � � (read buffer) � SWITCH � (write buffer)� �
  67. // � � � � � � �
  68. // � � �<�������������>� � �
  69. // � � BUSY FLAG2 � � BUSY FLAG2 � �
  70. // � � 0 � � 1 � �
  71. // � � � IN USE � � �
  72. // � � � � � � �
  73. // � � � �������>� � �
  74. // � � � � � �
  75. // � � � � � �
  76. // � � � COUNT � � �
  77. // � � � 5 � � �
  78. // � ����������������� ����������������� �
  79. // � �
  80. // � �
  81. // �����������������������������������������������������ͼ
  82. //
  83. //
  84. // On entry it is safe to clean out the current read buffer (to leave
  85. // it in a virgin state for the display driver once the buffers have
  86. // switched).
  87. //
  88. // The logic for the switch is as follows.
  89. //
  90. // - Set the new value for the SWITCH pointer
  91. //
  92. // - If the shared memory BUSY FLAG1 is clear we've finished and can
  93. // exit now.
  94. //
  95. // - We can exit as soon as either of the following are true.
  96. //
  97. // - BUSY FLAG1 is clear DDI has finished
  98. // - BUSY FLAG1 is set AND BUSY FLAG2 is set DDI is in new memory
  99. //
  100. //
  101. //
  102. // Check for a valid pointer
  103. //
  104. ASSERT(g_asSharedMemory);
  105. //
  106. // Do that switch...The display driver may be in the middle of an
  107. // access at the moment, so we will test the state afterwards.
  108. //
  109. oldBuffer = g_asSharedMemory->displayToCore.newBuffer;
  110. newBuffer = 1 - oldBuffer;
  111. g_asSharedMemory->displayToCore.newBuffer = newBuffer;
  112. WAIT_FOR_BUFFER(displayToCore, newBuffer, oldBuffer);
  113. DebugExitVOID(SHM_SwitchReadBuffer);
  114. }
  115. //
  116. // SHM_SwitchFastBuffer - see shm.h
  117. //
  118. void SHM_SwitchFastBuffer(void)
  119. {
  120. int oldBuffer;
  121. int newBuffer;
  122. DebugEntry(SHM_SwitchFastBuffer);
  123. //
  124. // Check for a valid pointer
  125. //
  126. ASSERT(g_asSharedMemory);
  127. //
  128. // Do that switch...The display driver may be in the middle of an
  129. // access at the moment, so we will test the state afterwards.
  130. //
  131. oldBuffer = g_asSharedMemory->fastPath.newBuffer;
  132. newBuffer = 1 - oldBuffer;
  133. g_asSharedMemory->fastPath.newBuffer = newBuffer;
  134. //
  135. // Wait for completion
  136. //
  137. WAIT_FOR_BUFFER(fastPath, newBuffer, oldBuffer);
  138. DebugExitVOID(SHM_SwitchFastBuffer);
  139. }