Subversion Repositories Kolibri OS

Rev

Rev 1 | Rev 379 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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