Subversion Repositories Kolibri OS

Rev

Rev 5596 | Rev 5599 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5596 Rev 5597
Line 5... Line 5...
5
;;                                                              ;;
5
;;                                                              ;;
6
;; Synhronization for MenuetOS.                                 ;;
6
;; Synhronization for MenuetOS.                                 ;;
7
;; Author: Halyavin Andrey, halyavin@land.ru                    ;;
7
;; Author: Halyavin Andrey, halyavin@land.ru                    ;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 9... Line 9...
9
 
9
 
Line 10... Line 10...
10
$Revision: 5596 $
10
$Revision: 5597 $
11
 
11
 
12
align 4
12
align 4
13
;struct futex*  __fastcall create_futex(int *ptr)
13
;struct futex*  __fastcall create_futex(int *ptr)
Line 26... Line 26...
26
        list_init ecx
26
        list_init ecx
27
        mov     [eax+FUTEX.flags], 0
27
        mov     [eax+FUTEX.flags], 0
28
.fail:
28
.fail:
29
        ret
29
        ret
Line -... Line 30...
-
 
30
 
-
 
31
align 4
-
 
32
;int __fastcall destroy_futex(struct futex *futex)
-
 
33
destroy_futex:
-
 
34
        push    esi
-
 
35
        mov     esi, [current_process]
-
 
36
        mov     edx, [ecx+FUTEX.handle]
-
 
37
 
-
 
38
        pushfd
-
 
39
        cli
-
 
40
 
-
 
41
        lea     eax, [ecx+FUTEX.wait_list]
-
 
42
        cmp     eax, [eax+LHEAD.next]
-
 
43
        jne     .fail
-
 
44
 
-
 
45
        mov     eax, [esi+PROC.ht_next]
-
 
46
        mov     [esi+PROC.htab+edx*4], eax
-
 
47
        mov     [esi+PROC.ht_next], edx
-
 
48
        inc     [esi+PROC.ht_free]
-
 
49
 
-
 
50
        popfd
-
 
51
        pop     esi
-
 
52
 
-
 
53
        mov     eax, ecx
-
 
54
        call    free
-
 
55
        xor     eax, eax
-
 
56
        ret
-
 
57
 
-
 
58
.fail:
-
 
59
        popfd
-
 
60
        pop     esi
-
 
61
        mov     eax, -1
-
 
62
        ret
-
 
63
 
30
 
64
 
31
iglobal
65
iglobal
32
align 4
66
align 4
33
f77call:
67
f77call:
-
 
68
        dd f77.futex_init     ;0
34
        dd f77.futex_init     ;0
69
        dd f77.futex_destroy  ;1
35
        dd f77.futex_wait     ;1
70
        dd f77.futex_wait     ;2
36
        dd f77.futex_wake     ;2
71
        dd f77.futex_wake     ;3
37
.end:
72
.end:
Line 38... Line 73...
38
endg
73
endg
39
 
74
 
40
align 4
75
align 4
-
 
76
sys_synchronization:
-
 
77
f77:
-
 
78
        test    ebx, ebx
41
sys_synchronization:
79
        jz      .futex_init
42
f77:
80
 
Line -... Line 81...
-
 
81
        cmp     ebx, (f77call.end-f77call)/4
-
 
82
        jae     .fail
-
 
83
 
-
 
84
        cmp     ecx, STDERR_FILENO
-
 
85
        jbe     .fail
-
 
86
        cmp     ecx, (PROC.pdt_0 - PROC.htab)/4
-
 
87
        jae     .fail
-
 
88
 
-
 
89
        mov     esi, [current_process]
-
 
90
        mov     edi, [esi+PROC.htab+ecx*4]
-
 
91
 
-
 
92
        cmp     [edi+FUTEX.magic], 'FUTX'
-
 
93
        jne     .fail
43
        cmp     ebx, (f77call.end-f77call)/4
94
        cmp     [edi+FUTEX.handle], ecx
Line 44... Line 95...
44
        jae .fail
95
        jne     .fail
45
 
96
 
46
        jmp     dword [f77call+ebx*4]
97
        jmp     dword [f77call+ebx*4]
Line 47... Line -...
47
 
-
 
48
.fail:
98
 
49
        mov     [esp+SYSCALL_STACK._eax], -1
99
.fail:
50
        ret
100
        mov     [esp+SYSCALL_STACK._eax], -1
51
 
101
        ret
52
 
102
 
53
align 4
103
align 4
54
.futex_init:
104
.futex_init:
55
        call    create_futex
105
        call    create_futex
56
        test    eax, eax
106
        test    eax, eax
Line -... Line 107...
-
 
107
        jz      @F
-
 
108
        mov     eax, [eax+FUTEX.handle]
-
 
109
@@:
-
 
110
        mov     [esp+SYSCALL_STACK._eax], eax
-
 
111
        ret
-
 
112
 
-
 
113
 
-
 
114
align 4
-
 
115
;ecx futex handle
-
 
116
;esi current process
-
 
117
;edi futex object
57
        jz      @F
118
.futex_destroy:
58
        mov     eax, [eax+FUTEX.handle]
119
        mov     ecx, edi
-
 
120
        call    destroy_futex
-
 
121
        mov     [esp+SYSCALL_STACK._eax], eax
59
@@:
122
        ret
60
        mov     [esp+SYSCALL_STACK._eax], eax
123
 
61
        ret
-
 
62
 
-
 
63
align 4
-
 
64
;ecx futex handle
-
 
65
;edx control value
-
 
66
.futex_wait:
-
 
67
        cmp     ecx, 3
-
 
68
        jb      .epicfail
-
 
69
        cmp     ecx, (PROC.pdt_0 - PROC.htab)/4
-
 
70
        jae     .epicfail
-
 
71
 
-
 
72
        mov     esi, [current_process]
-
 
73
        mov     edi, [esi+PROC.htab+ecx*4]
-
 
74
 
124
align 4
75
        cmp     [edi+FUTEX.magic], 'FUTX'
-
 
76
        jne     .epicfail
125
;ecx futex handle
77
        cmp     [edi+FUTEX.handle], ecx
126
;esi current process
78
        jne     .epicfail
127
;edi futex object
Line 79... Line 128...
79
 
128
;edx control value
Line 109... Line 158...
109
 
158
 
110
        popfd
159
        popfd
111
        mov     [esp+SYSCALL_STACK._eax], 0
160
        mov     [esp+SYSCALL_STACK._eax], 0
Line 112... Line -...
112
        ret
-
 
113
 
-
 
114
.epicfail:
-
 
115
        mov     [esp+SYSCALL_STACK._eax], -1
-
 
116
        ret
161
        ret
117
 
162
 
-
 
163
align 4
-
 
164
;ecx futex handle
118
align 4
165
;esi current process
119
;ecx futex handle
166
;edi futex object
120
;edx threads count
-
 
121
.futex_wake:
-
 
122
        cmp     ecx, 3
-
 
123
        jb      .epicfail
-
 
124
        cmp     ecx, (PROC.pdt_0 - PROC.htab)/4
-
 
125
        jae     .epicfail
-
 
126
 
-
 
127
        mov     esi, [current_process]
-
 
128
        mov     edi, [esi+PROC.htab+ecx*4]
-
 
129
 
-
 
130
        cmp     [edi+FUTEX.magic], 'FUTX'
-
 
131
        jne     .epicfail
-
 
Line 132... Line 167...
132
        cmp     [edi+FUTEX.handle], ecx
167
;edx threads count
Line 133... Line 168...
133
        jne     .epicfail
168
.futex_wake:
134
 
169
 
Line 135... Line 170...
135
        xor     ecx, ecx
170
        xor     ecx, ecx
136
 
171
 
137
        pushfd
172
        pushfd
138
        cli
173
        cli
139
 
174
 
Line 140... Line 175...
140
        lea     ebx, [edi+FUTEX.wait_list]
175
        lea     ebx, [edi+FUTEX.wait_list]