Subversion Repositories Kolibri OS

Rev

Rev 379 | Rev 431 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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