Subversion Repositories Kolibri OS

Rev

Rev 750 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;; Synhronization for MenuetOS.                                 ;;
  7. ;; Author: Halyavin Andrey, halyavin@land.ru                    ;;
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9.  
  10. $Revision: 750 $
  11.  
  12.  
  13. if ~defined sync_inc
  14. sync_inc_fix:
  15. sync_inc fix sync_inc_fix
  16.  
  17. ;simplest mutex.
  18. macro SimpleMutex name
  19. {
  20. ;  iglobal
  21.     name dd 0
  22.     name#.type = 1
  23. ;  endg
  24. }
  25. macro WaitSimpleMutex name
  26. {
  27.   local start_wait,ok
  28. start_wait=$
  29.   cli
  30.   cmp  [name],dword 0
  31.   jz   ok
  32.   sti
  33.   call change_task
  34.   jmp  start_wait
  35. ok=$
  36.   push eax
  37.   mov  eax,dword [TASK_BASE+second_base_address]
  38.   mov  eax,[eax+TASKDATA.pid]
  39.   mov  [name],eax
  40.   pop  eax
  41.   sti
  42. }
  43. macro ReleaseSimpleMutex name
  44. {
  45.   mov  [name],dword 0
  46. }
  47. macro TryWaitSimpleMutex name  ;result in eax and in flags
  48. {
  49.   local ok,try_end
  50.   cmp  [name],dword 0
  51.   jz   ok
  52.   xor  eax,eax
  53.   jmp  try_end
  54. ok=$
  55.   xor  eax,eax
  56.   inc  eax
  57. try_end=$
  58. }
  59. macro SimpleCriticalSection name
  60. {
  61. ;  iglobal
  62.     name  dd 0
  63.           dd 0
  64.     name#.type=2
  65. ;  endg
  66. }
  67. macro WaitSimpleCriticalSection name
  68. {
  69.   local start_wait,first_wait,inc_counter,end_wait
  70.   push  eax
  71.   mov   eax,[TASK_BASE+second_base_address]
  72.   mov   eax,[eax+TASKDATA.pid]
  73. start_wait=$
  74.   cli
  75.   cmp   [name],dword 0
  76.   jz    first_wait
  77.   cmp   [name],eax
  78.   jz    inc_counter
  79.   sti
  80.   call  change_task
  81.   jmp   start_wait
  82. first_wait=$
  83.   mov   [name],eax
  84.   mov   [name+4],dword 1
  85.   jmp   end_wait
  86. inc_counter=$
  87.   inc   dword [name+4]
  88. end_wait=$
  89.   sti
  90.   pop   eax
  91. }
  92. macro ReleaseSimpleCriticalSection name
  93. {
  94.   local release_end
  95.   dec   dword [name+4]
  96.   jnz   release_end
  97.   mov   [name],dword 0
  98. release_end=$
  99. }
  100. macro TryWaitSimpleCriticalSection name ;result in eax and in flags
  101. {
  102.   local ok,try_end
  103.   mov   eax,[CURRENT_TASK+second_base_address]
  104.   mov   eax,[eax+TASKDATA.pid]
  105.   cmp   [name],eax
  106.   jz    ok
  107.   cmp   [name],0
  108.   jz    ok
  109.   xor   eax,eax
  110.   jmp   try_end
  111. ok=$
  112.   xor   eax,eax
  113.   inc   eax
  114. try_end=$
  115. }
  116. _cli equ call MEM_HeapLock
  117. _sti equ call MEM_HeapUnLock
  118. end if
  119.  
  120.