Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6929 → Rev 6928

/kernel/trunk/posix/pipe.inc
7,9 → 7,6
 
$Revision: 6917 $
 
F_READ equ 0x0001 ; file opened for reading
F_WRITE equ 0x0002 ; file opened for writing
 
O_CLOEXEC equ 0x40000
PIPE_BUFFER_SIZE equ 4096
 
99,12 → 96,10
 
mov [eax+FILED.magic], 'PIPE'
mov [eax+FILED.destroy], 0
mov [eax+FILED.mode], F_READ
mov [eax+FILED.file], ebp
 
mov [edx+FILED.magic], 'PIPE'
mov [edx+FILED.destroy], 0
mov [edx+FILED.mode], F_WRITE
mov [edx+FILED.file], ebp
 
mov eax, [eax+FILED.handle]
130,9 → 125,8
.err_0:
add esp, 5*4
.fail:
mov eax, ebp
mov [esp+SYSCALL_STACK._eax], ebp
pop ebp
mov [esp+SYSCALL_STACK._eax], eax
ret
 
purge .pipeflags
142,18 → 136,18
purge .intpipe
 
 
; edx dst_buf
; esi read count
; edx buf
; esi count
; ebp pipe
 
align 4
pipe_read:
 
mov edi, edx
 
.again:
lea ecx, [ebp+PIPE.pipe_lock]
call mutex_lock
.again:
 
xor eax, eax
cmp eax, [ebp+PIPE.writers]
je .eof
176,31 → 170,11
and esi, 0xFFF
mov [ebp+PIPE.read_end], esi
 
lea ecx, [ebp+PIPE.wlist]
cmp ecx, [ebp+PIPE.wlist.next]
je @F
 
mov ecx, [ecx+MUTEX_WAITER.task]
mov [ecx+TASKDATA.state], 0 ;activate writer task
@@:
cmp [ebp+PIPE.count], 0
je @F
 
lea eax, [ebp+PIPE.rlist]
cmp eax, [ebp+PIPE.rlist.next]
je @F
 
mov eax, [eax+MUTEX_WAITER.task]
mov [eax+TASKDATA.state], 0 ;activate reader task
@@:
lea ecx, [ebp+PIPE.pipe_lock]
call mutex_unlock
ret
 
.wait:
pushfd
cli
 
sub esp, sizeof.MUTEX_WAITER
mov ebx, [TASK_BASE]
mov [esp+MUTEX_WAITER.task], ebx
214,12 → 188,8
mov [ebx+TASKDATA.state], 1
call change_task
 
lea ecx, [ebp+PIPE.pipe_lock]
call mutex_lock
 
list_del esp
add esp, sizeof.MUTEX_WAITER
popfd
jmp .again
 
.eof:
228,85 → 198,49
call mutex_unlock
ret
 
; edx src_buf
; esi write count
; edx buf
; esi count
; ebp pipe
 
align 4
pipe_write:
mov edi, edx
 
.written equ esp
 
push 0 ;written
mov ebx, esi ;ebx = write count
mov esi, edx ;esi = src
 
.again:
lea ecx, [ebp+PIPE.pipe_lock]
call mutex_lock
.again:
 
xor eax, eax
cmp eax, [ebp+PIPE.readers]
je .epipe
 
mov ecx, 4096
sub ecx, [ebp+PIPE.count]
jz .wait ;wait if buffer full
mov ecx, [ebp+PIPE.count]
sub ecx, 4096
jz .wait
 
.check_count:
cmp ecx, ebx
cmp ecx, esi
jb .write
mov ecx, ebx
mov ecx, esi
.write:
mov esi, edi
mov edi, [ebp+PIPE.buffer]
add edi, [ebp+PIPE.write_end]
add [.written], ecx
sub ebx, ecx
mov [esp+SYSCALL_STACK._eax], ecx
add [ebp+PIPE.count], ecx
 
cld
rep movsb
and edi, 0xFFF
mov [ebp+PIPE.write_end], edi
 
pushfd
cli
 
lea eax, [ebp+PIPE.rlist]
cmp eax, [ebp+PIPE.rlist.next]
je @F
 
mov eax, [eax+MUTEX_WAITER.task]
mov [eax+TASKDATA.state], 0 ;activate reader task
@@:
cmp [ebp+PIPE.count], 4096
je @F
 
lea ecx, [ebp+PIPE.wlist]
cmp ecx, [ebp+PIPE.wlist.next]
je @F
 
mov ecx, [eax+MUTEX_WAITER.task]
mov [ecx+TASKDATA.state], 0 ;activate writer task
@@:
popfd
 
lea ecx, [ebp+PIPE.pipe_lock]
call mutex_unlock
 
test ebx, ebx
jnz .again
 
pop eax ; written
mov [esp+SYSCALL_STACK._eax], eax
ret
 
.wait:
pushfd
cli
 
sub esp, sizeof.MUTEX_WAITER
mov ecx, [TASK_BASE]
mov [esp+MUTEX_WAITER.task], ecx
mov ebx, [TASK_BASE]
mov [esp+MUTEX_WAITER.task], ebx
lea edx, [ebp+PIPE.wlist]
 
list_add_tail esp, edx ;esp= new waiter, edx= list head
314,23 → 248,17
lea ecx, [ebp+PIPE.pipe_lock]
call mutex_unlock
 
mov [ecx+TASKDATA.state], 1
mov [ebx+TASKDATA.state], 1
call change_task
 
lea ecx, [ebp+PIPE.pipe_lock]
call mutex_lock
 
list_del esp
add esp, sizeof.MUTEX_WAITER
popfd
jmp .again
 
.epipe:
mov [esp+SYSCALL_STACK._eax], -EPIPE
lea ecx, [ebp+PIPE.pipe_lock]
call mutex_unlock
 
add esp, 4
mov [esp+SYSCALL_STACK._eax], -EPIPE
ret
 
align 4
/kernel/trunk/posix/posix.inc
88,9 → 88,6
cmp [ebp+FILED.handle], ecx
jne .fail
 
test [ebp+FILED.mode], F_READ
jz .fail
 
mov ebp, [ebp+FILED.file]
mov eax, [ebp]
jmp dword [eax+FILEOP_READ*4]
117,8 → 114,6
jne .fail
cmp [ebp+FILED.handle], ecx
jne .fail
test [ebp+FILED.mode], F_WRITE
jz .fail
 
mov ebp, [ebp+FILED.file]
mov eax, [ebp]
/kernel/trunk/const.inc
418,7 → 418,6
magic rd 1
handle rd 1
destroy rd 1
mode rd 1
file rd 1
ends