Subversion Repositories Kolibri OS

Rev

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

Rev 3 Rev 4
Line 60... Line 60...
60
        cmp   [0xffff], byte 1   ;1
60
        cmp   [0xffff], byte 1   ;1
61
        je   do_not_change_task ;je
61
        je   do_not_change_task ;je
Line 62... Line 62...
62
 
62
 
63
      .waiting_for_termination:
63
      .waiting_for_termination:
64
      .waiting_for_reuse:
-
 
65
      .waiting_on_queue:
64
      .waiting_for_reuse:
66
        add   edi,0x20
65
        add   edi,0x20
Line 67... Line 66...
67
        inc   ebx
66
        inc   ebx
68
 
67
 
69
        mov   al, byte [edi+0xA]
68
        mov   al, byte [edi+0xA]
70
        cmp   al, 3
69
        cmp   al, 3
71
        je    .waiting_for_termination
70
        je    .waiting_for_termination
72
        cmp   al, 4
71
        cmp   al, 4
73
        je    .waiting_for_termination
72
        je    .waiting_for_termination
74
        cmp   al, 9
-
 
75
        je    .waiting_for_reuse
-
 
76
        cmp   al, 16
-
 
77
        je    .waiting_on_queue
-
 
Line 78... Line 73...
78
        cmp   al, 17
73
        cmp   al, 9
79
        je    .waiting_on_queue
74
        je    .waiting_for_reuse
80
 
75
 
81
        cmp   ebx,[0x3004]
76
        cmp   ebx,[0x3004]
Line 88... Line 83...
88
        mov   [0x3000],ebx
83
        mov   [0x3000],ebx
89
        mov   [0x3010],edi
84
        mov   [0x3010],edi
Line 90... Line 85...
90
 
85
 
Line 91... Line 86...
91
      do_not_change_task:
86
      do_not_change_task:
92
 
87
 
93
        mov   edx,[0x3000]
88
        ;mov   edx,[0x3000]
94
        lea   edx,[tss0sys+8*edx]
89
        ;lea   edx,[tss0sys+8*edx]
95
        ;mov   [8*0x40+idts+8+0], word 0
90
        ;mov   [8*0x40+idts+8+0], word 0
96
        ;mov   [8*0x40+idts+8+2],dx
91
        ;mov   [8*0x40+idts+8+2],dx
Line 153... Line 148...
153
        add  edi,0x20
148
        add  edi,0x20
154
        dec  ecx
149
        dec  ecx
155
        jnz  .newupdate
150
        jnz  .newupdate
Line 156... Line 151...
156
 
151
 
157
        ret
-
 
158
 
-
 
159
 
-
 
160
 
-
 
161
;
-
 
162
; Wait queue is 16 bytes
-
 
163
; dd return code                +12
-
 
164
; dd pointer to process         +8
-
 
165
; dd prev                       +4
-
 
166
; dd next                       +0
-
 
167
;
-
 
168
; eax - pointer to pointer to the wait queue
-
 
169
; return:
-
 
170
; ecx - return code
-
 
171
sleep_on_queue:
-
 
172
    sub esp,16          ; reserve space for wait node
-
 
173
    mov ecx,esp         ; ecx=this_node, [eax]=queue
-
 
174
 
-
 
175
    pusha
-
 
176
 
-
 
177
    mov ebx,[0x3010]    ; get pointer to the current process
-
 
178
    mov [ecx+8],ebx
-
 
179
 
-
 
180
    pushf
-
 
181
    cli                 ; adding element to the wait queue must be atomic
-
 
182
 
-
 
183
    mov edi,[eax]       ; edi=queue
-
 
184
    and edi,edi         ; check if queue is empty
-
 
185
    jz .is_empty
-
 
186
 
-
 
187
    ; add element at the end of wait queue
-
 
188
 
-
 
189
    mov edx,[edi+4]     ; get pointer to prev edx=queue->prev
-
 
190
    mov [ecx+4],edx     ; this_node->prev=queue->prev
-
 
191
    mov [ecx+0],edi     ; this_node->next=queue
-
 
192
    mov [edx+0],ecx     ; this_node->prev->next=this_node
-
 
193
    mov [edi+4],ecx     ; queue->prev=this_node
-
 
194
    jmp .added_ok
-
 
195
.is_empty:
-
 
196
    ; set this element as first in the queue
-
 
197
    mov [ecx+0],ecx     ; this_node->next=this_node
-
 
198
    mov [ecx+4],ecx     ; this_node->prev=this_node
-
 
199
    mov [eax],ecx       ; [queue]=this_node
-
 
200
.added_ok:
-
 
201
 
-
 
202
    popf                ; we can safely restore interrupts
-
 
203
 
-
 
204
    mov [ebx+0xa],byte 17 ; set current task state as sleeping
-
 
205
    call change_task    ; schedule new thread
-
 
206
 
-
 
207
    ; someone has called wake_up_queue
-
 
208
 
-
 
209
    pushf               ; disable interrupts
-
 
210
    cli
-
 
211
 
-
 
212
    mov edx,[ecx+0]     ; edx=this_node->next
-
 
213
    mov esi,[ecx+4]     ; esi=this_node->prev
-
 
214
 
-
 
215
    ; check if we need to remove this node from head
-
 
216
    cmp [eax],ecx
-
 
217
    jne .no_head
-
 
218
 
-
 
219
    cmp [ecx+0],ecx ; check if queue is empty
-
 
220
    jne .not_empty
-
 
221
 
-
 
222
    mov [eax],dword 0
-
 
223
    jmp .no_head
-
 
224
 
-
 
225
.not_empty:
-
 
226
    mov [eax],edx
-
 
227
 
-
 
228
    ; remove our node from the queue (this must be atomic)
-
 
229
.no_head:
-
 
230
    mov [edx+4],esi     ; this_node->next->prev=this_node->prev
-
 
231
    mov [esi+0],edx     ; this_node->prev->next=this_node->next
-
 
232
 
-
 
233
    popf
-
 
234
    popa
-
 
235
    add esp,12
-
 
236
    pop ecx
-
 
237
    ret
-
 
238
 
-
 
239
; eax - pointer to the wait queue
-
 
240
; ebx - wake up all (1=yes, 0=no)
-
 
241
; ecx - return code
-
 
242
; return:
-
 
243
; ebx - number of processes woken
-
 
244
wake_up_queue:
-
 
245
    and eax,eax
-
 
246
    jnz .nz
-
 
247
    ret
-
 
248
.nz:
-
 
249
    push eax
-
 
250
    push ebx
-
 
251
    push ecx
-
 
252
    push edx
-
 
253
    push esi
-
 
254
 
-
 
255
    pushf
-
 
256
    cli
-
 
257
 
-
 
258
    xor ebx,ebx
-
 
259
    mov edx,eax
-
 
260
.wake_loop:
-
 
261
 
-
 
262
    mov [edx+12],ecx
-
 
263
    mov esi,[edx+8]
-
 
264
    mov byte [esi+0xa],0
-
 
265
    inc ebx
-
 
266
 
-
 
267
    mov edx,[edx+0]
-
 
268
    cmp edx,eax
-
 
269
    jne .wake_loop
-
 
270
 
-
 
271
    and ebx,ebx
-
 
272
    jz .wake_up_1
-
 
273
 
-
 
274
.return_it:
-
 
275
    popf
-
 
276
    pop esi
-
 
277
    pop edx
-
 
278
    pop ecx
-
 
279
    add esp,4
-
 
280
    pop eax
-
 
281
    ret
-
 
282
.wake_up_1:
-
 
283
    mov [eax+12],ecx
-
 
284
    mov ecx,[eax+8]
-
 
285
    mov byte [ecx+0xa],0
-