forked from KolibriOS/kolibrios
signaling events, create_event(),
destroy_event(), raise_events(), wait_event() git-svn-id: svn://kolibrios.org@354 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
fcf5e6d6b9
commit
b0776c09ad
@ -323,6 +323,7 @@ virtual at 0
|
||||
end virtual
|
||||
|
||||
APP_OBJ_OFFSET equ 48
|
||||
APP_EV_OFFSET equ 40
|
||||
|
||||
struc CURSOR
|
||||
{;common object header
|
||||
@ -343,6 +344,41 @@ end virtual
|
||||
|
||||
CURSOR_SIZE equ 32
|
||||
|
||||
struc EVENT
|
||||
{
|
||||
.magic dd ? ;'EVNT'
|
||||
.destroy dd ? ;internal destructor
|
||||
.fd dd ? ;next object in list
|
||||
.bk dd ? ;prev object in list
|
||||
.pid dd ? ;owner id
|
||||
|
||||
.id dd ? ;event uid
|
||||
.state dd ? ;internal flags
|
||||
.code dd ?
|
||||
rd 5
|
||||
}
|
||||
EVENT_SIZE equ 52
|
||||
|
||||
virtual at 0
|
||||
EVENT EVENT
|
||||
end virtual
|
||||
|
||||
|
||||
|
||||
struc HEAP_DATA
|
||||
{
|
||||
.mutex rd 1
|
||||
.refcount rd 1
|
||||
.heap_base rd 1
|
||||
.heap_top rd 1
|
||||
.app_mem rd 1
|
||||
}
|
||||
|
||||
HEAP_DATA_SIZE equ 20
|
||||
virtual at 0
|
||||
HEAP_DATA HEAP_DATA
|
||||
end virtual
|
||||
|
||||
struc BOOT_DATA
|
||||
{ .bpp dd ?
|
||||
.scanline dd ?
|
||||
|
@ -35,6 +35,10 @@ iglobal
|
||||
|
||||
szCreateObject db 'CreateObject',0
|
||||
szDestroyObject db 'DestroyObject',0
|
||||
szCreateEvent db 'CreateEvent',0
|
||||
szRaiseEvent db 'RaiseEvent',0
|
||||
szWaitEvent db 'WaitEvent',0
|
||||
szDestroyEvent db 'DestroyEvent',0
|
||||
|
||||
szLoadCursor db 'LoadCursor',0
|
||||
szSetHwCursor db 'SetHwCursor',0
|
||||
@ -76,12 +80,16 @@ kernel_export:
|
||||
dd szKernelAlloc , kernel_alloc
|
||||
dd szKernelFree , kernel_free
|
||||
dd szUserAlloc , user_alloc
|
||||
dd szUserFree , user_free
|
||||
dd szUserFree , user_free
|
||||
dd szKmalloc , malloc
|
||||
dd szKfree , free
|
||||
|
||||
dd szCreateObject , create_kernel_object
|
||||
dd szDestroyObject , destroy_kernel_object
|
||||
dd szCreateEvent , create_event
|
||||
dd szRaiseEvent , raise_event
|
||||
dd szWaitEvent , wait_event
|
||||
dd szDestroyEvent , destroy_event
|
||||
|
||||
dd szLoadCursor , load_cursor
|
||||
dd szSetHwCursor , set_hw_cursor
|
||||
|
@ -1379,11 +1379,6 @@ align 16
|
||||
align 16
|
||||
cur_saved_data rb 4096
|
||||
|
||||
;cursors rb CURSOR_SIZE*64
|
||||
;cursor_map rd 2
|
||||
;cursor_start rd 1
|
||||
;cursor_end rd 1
|
||||
|
||||
def_cursor rd 1
|
||||
hw_cursor rd 1
|
||||
|
||||
@ -1403,16 +1398,11 @@ align 16
|
||||
|
||||
mst MEM_STATE
|
||||
|
||||
; dll_tab rb 32*32
|
||||
; srv_tab rb 36*32
|
||||
mem_block_map rb 512
|
||||
event_map rb 128
|
||||
event_map rb 64
|
||||
mem_block_list rd 64
|
||||
mem_block_mask rd 2
|
||||
|
||||
; dll_map rd 1
|
||||
; srv_map rd 1
|
||||
|
||||
srv.fd rd 1
|
||||
srv.bk rd 1
|
||||
|
||||
@ -1432,7 +1422,7 @@ align 16
|
||||
events rd 1
|
||||
event_start rd 1
|
||||
event_end rd 1
|
||||
|
||||
event_uid rd 1
|
||||
sys_page_map rd 1
|
||||
endg
|
||||
|
||||
|
@ -1002,7 +1002,11 @@ proc set_app_params stdcall,slot:dword, params:dword,\
|
||||
inc dword [TASK_COUNT] ;update number of processes
|
||||
.noinc:
|
||||
shl ebx,8
|
||||
lea edx, [ebx+PROC_BASE+APP_OBJ_OFFSET]
|
||||
lea edx, [ebx+PROC_BASE+APP_EV_OFFSET]
|
||||
mov [PROC_BASE+APPDATA.fd_ev+ebx],edx
|
||||
mov [PROC_BASE+APPDATA.bk_ev+ebx],edx
|
||||
|
||||
add edx, APP_OBJ_OFFSET-APP_EV_OFFSET
|
||||
mov [PROC_BASE+APPDATA.fd_obj+ebx],edx
|
||||
mov [PROC_BASE+APPDATA.bk_obj+ebx],edx
|
||||
|
||||
|
@ -1,24 +1,14 @@
|
||||
struc EVENT
|
||||
{ .code rd 1
|
||||
rd 5
|
||||
.next rd 1 ;+24
|
||||
.prev rd 1 ;+28
|
||||
}
|
||||
EVENT_SIZE equ 32
|
||||
|
||||
virtual at 0
|
||||
EVENT EVENT
|
||||
end virtual
|
||||
|
||||
align 4
|
||||
init_events:
|
||||
stdcall kernel_alloc, 1024*EVENT_SIZE
|
||||
stdcall kernel_alloc, 512*EVENT_SIZE
|
||||
mov [events], eax
|
||||
xor eax, eax
|
||||
mov [event_uid], eax
|
||||
not eax
|
||||
mov edi, event_map
|
||||
mov [event_start], edi
|
||||
mov ecx, 128/4
|
||||
mov ecx, 64/4
|
||||
cld
|
||||
rep stosd
|
||||
mov [event_end], edi
|
||||
@ -43,24 +33,30 @@ proc alloc_event
|
||||
.found:
|
||||
btr [ebx], eax
|
||||
mov [event_start],ebx
|
||||
inc [event_uid]
|
||||
|
||||
sub ebx, event_map
|
||||
lea eax,[eax+ebx*8]
|
||||
|
||||
lea ebx, [eax+eax*4]
|
||||
shl eax,5
|
||||
lea eax,[eax+ebx*4] ;eax*=52 (EVENT_SIZE)
|
||||
add eax, [events]
|
||||
mov ebx, [event_uid]
|
||||
popfd
|
||||
xor ebx, ebx
|
||||
mov [eax+EVENT.next], ebx
|
||||
mov [eax+EVENT.prev], ebx
|
||||
ret
|
||||
endp
|
||||
|
||||
align 4
|
||||
free_event:
|
||||
sub eax, [events]
|
||||
mov ecx, EVENT_SIZE
|
||||
mov ebx, event_map
|
||||
cdq
|
||||
div ecx
|
||||
|
||||
pushfd
|
||||
cli
|
||||
sub eax, [events]
|
||||
shr eax, 5
|
||||
mov ebx, event_map
|
||||
bts [ebx], eax
|
||||
shr eax, 3
|
||||
and eax, not 3
|
||||
@ -74,6 +70,97 @@ free_event:
|
||||
popfd
|
||||
ret
|
||||
|
||||
EVENT_WATCHED equ 0x10000000
|
||||
EVENT_SIGNALED equ 0x20000000
|
||||
MANUAL_RESET equ 0x40000000
|
||||
MANUAL_DESTROY equ 0x80000000
|
||||
|
||||
|
||||
; param
|
||||
; eax= event data
|
||||
; ebx= flags
|
||||
;
|
||||
; retval
|
||||
; eax= event
|
||||
; edx= id
|
||||
|
||||
create_event:
|
||||
.flags equ esp+4
|
||||
.data equ esp
|
||||
|
||||
push ebx
|
||||
push eax
|
||||
|
||||
call alloc_event
|
||||
test eax, eax
|
||||
jz .fail
|
||||
|
||||
mov [eax+APPOBJ.magic], 'EVNT'
|
||||
mov [eax+APPOBJ.destroy], destroy_event
|
||||
mov [eax+EVENT.id], ebx
|
||||
|
||||
mov ebx, [CURRENT_TASK]
|
||||
shl ebx, 5
|
||||
mov ebx, [0x3000+ebx+4]
|
||||
mov [eax+APPOBJ.pid], ebx
|
||||
mov edx, [.flags]
|
||||
mov [eax+EVENT.state], edx
|
||||
|
||||
mov esi, [.data]
|
||||
test esi, esi
|
||||
jz @F
|
||||
lea edi, [eax+EVENT.code]
|
||||
mov ecx, 6
|
||||
cld
|
||||
rep movsd
|
||||
@@:
|
||||
mov ecx, [CURRENT_TASK]
|
||||
shl ecx,8
|
||||
add ecx, PROC_BASE+APP_OBJ_OFFSET
|
||||
|
||||
pushfd
|
||||
cli
|
||||
mov edx, [ecx+APPOBJ.fd]
|
||||
mov [eax+APPOBJ.fd], edx
|
||||
mov [eax+APPOBJ.bk], ecx
|
||||
mov [ecx+APPOBJ.fd], eax
|
||||
mov [edx+APPOBJ.bk], eax
|
||||
popfd
|
||||
mov edx, [eax+EVENT.id]
|
||||
.fail:
|
||||
add esp, 8
|
||||
ret
|
||||
|
||||
restore .flags
|
||||
restore .data
|
||||
|
||||
; param
|
||||
; eax= event
|
||||
; ebx= id
|
||||
|
||||
destroy_event:
|
||||
|
||||
cmp [eax+APPOBJ.magic], 'EVNT'
|
||||
jne .fail
|
||||
cmp [eax+EVENT.id], ebx
|
||||
jne .fail
|
||||
|
||||
mov ebx, [eax+APPOBJ.fd]
|
||||
mov ecx, [eax+APPOBJ.bk]
|
||||
mov [ebx+APPOBJ.bk], ecx
|
||||
mov [ecx+APPOBJ.fd], ebx
|
||||
.internal:
|
||||
xor edx, edx ;clear common header
|
||||
mov [eax], edx
|
||||
mov [eax+4], edx
|
||||
mov [eax+8], edx
|
||||
mov [eax+12], edx
|
||||
mov [eax+16], edx
|
||||
|
||||
call free_event ;release object memory
|
||||
.fail:
|
||||
ret
|
||||
|
||||
align 4
|
||||
proc send_event stdcall pid:dword, event:dword
|
||||
locals
|
||||
@ -90,65 +177,98 @@ proc send_event stdcall pid:dword, event:dword
|
||||
ja .fail
|
||||
|
||||
mov [slot], eax
|
||||
|
||||
call alloc_event
|
||||
test eax, eax
|
||||
jz .fail
|
||||
|
||||
mov edi, eax
|
||||
lea edi, [eax+EVENT.code]
|
||||
mov ecx, 6
|
||||
mov esi, [event]
|
||||
cld
|
||||
rep movsd
|
||||
|
||||
mov esi, eax
|
||||
mov eax, [slot]
|
||||
mov edi, [PROC_BASE+eax+APPDATA.ev_last]
|
||||
mov [esi+EVENT.prev], edi
|
||||
test edi, edi
|
||||
jz .set_last
|
||||
mov [edi+EVENT.next], esi
|
||||
.set_last:
|
||||
mov edx, [PROC_BASE+eax+APPDATA.ev_first]
|
||||
test edx, edx
|
||||
jnz @F
|
||||
mov [PROC_BASE+eax+APPDATA.ev_first], esi
|
||||
@@:
|
||||
mov [PROC_BASE+eax+APPDATA.ev_last], esi
|
||||
inc [PROC_BASE+eax+APPDATA.ev_count]
|
||||
or [PROC_BASE+eax+APPDATA.event_mask], EVENT_EXTENDED
|
||||
mov ecx, [slot]
|
||||
add ecx, PROC_BASE+APP_EV_OFFSET
|
||||
|
||||
mov [eax+APPOBJ.magic], 'EVNT'
|
||||
mov [eax+APPOBJ.destroy], destroy_event
|
||||
mov ebx, [pid]
|
||||
mov [eax+APPOBJ.pid], ebx
|
||||
mov [eax+EVENT.state], EVENT_SIGNALED
|
||||
|
||||
pushfd
|
||||
cli ;insert event into
|
||||
mov edx, [ecx+APPOBJ.fd] ;events list
|
||||
mov [eax+APPOBJ.fd], edx ;and set events flag
|
||||
mov [eax+APPOBJ.bk], ecx
|
||||
mov [ecx+APPOBJ.fd], eax
|
||||
mov [edx+APPOBJ.bk], eax
|
||||
inc [ecx+APPDATA.ev_count-APP_EV_OFFSET]
|
||||
or [ecx+APPDATA.event_mask-APP_EV_OFFSET], EVENT_EXTENDED
|
||||
popfd
|
||||
.fail:
|
||||
ret
|
||||
endp
|
||||
|
||||
; timeout ignored
|
||||
|
||||
align 4
|
||||
proc get_event_ex stdcall, p_ev:dword, timeout:dword
|
||||
|
||||
.wait:
|
||||
mov ebx,[CURRENT_TASK]
|
||||
shl ebx,8
|
||||
cmp [PROC_BASE+ebx+APPDATA.ev_count], 0
|
||||
mov edx,[CURRENT_TASK]
|
||||
shl edx,8
|
||||
cmp [PROC_BASE+edx+APPDATA.ev_count], 0
|
||||
je .switch
|
||||
|
||||
mov esi, [PROC_BASE+ebx+APPDATA.ev_first]
|
||||
mov edx, [esi+EVENT.next]
|
||||
mov [PROC_BASE+ebx+APPDATA.ev_first], edx
|
||||
test edx, edx
|
||||
jz @F
|
||||
mov [edx+EVENT.prev], 0
|
||||
@@:
|
||||
jnz @F
|
||||
mov [PROC_BASE+ebx+APPDATA.ev_last], edx
|
||||
and dword [PROC_BASE+ebx+APPDATA.event_mask], not EVENT_EXTENDED
|
||||
@@:
|
||||
dec [PROC_BASE+ebx+APPDATA.ev_count]
|
||||
add edx, PROC_BASE+APP_EV_OFFSET
|
||||
|
||||
mov eax, esi
|
||||
and dword [esi], 0xFF00FFFF
|
||||
mov edi, [p_ev]
|
||||
mov eax, [edx+EVENT.fd]
|
||||
cmp eax, edx
|
||||
je .switch
|
||||
|
||||
lea esi, [eax+EVENT.code]
|
||||
mov edi, [p_ev] ;copy event data
|
||||
mov ecx, 6
|
||||
cld
|
||||
rep movsd
|
||||
call free_event
|
||||
|
||||
and dword [edi-24], 0xFF00FFFF ;clear priority field
|
||||
;
|
||||
|
||||
test [eax+EVENT.state], MANUAL_RESET
|
||||
jnz .done
|
||||
|
||||
pushfd
|
||||
cli ;remove event from events
|
||||
mov ebx, [eax+APPOBJ.fd] ;list (reset event)
|
||||
mov ecx, [eax+APPOBJ.bk] ;and clear events flag
|
||||
mov [ebx+APPOBJ.bk], ecx ;if no active events
|
||||
mov [ecx+APPOBJ.fd], ebx
|
||||
dec [edx+APPDATA.ev_count-APP_EV_OFFSET]
|
||||
jnz @F
|
||||
and [edx+APPDATA.event_mask-APP_EV_OFFSET], not EVENT_EXTENDED
|
||||
popfd
|
||||
|
||||
test [eax+EVENT.state], MANUAL_DESTROY
|
||||
jz .destroy
|
||||
|
||||
add edx, (APP_OBJ_OFFSET-APP_EV_OFFSET)
|
||||
|
||||
pushfd
|
||||
cli
|
||||
mov edx, [ecx+APPOBJ.fd] ;insert event into
|
||||
mov [eax+APPOBJ.fd], edx ;objects list
|
||||
mov [eax+APPOBJ.bk], ecx
|
||||
mov [ecx+APPOBJ.fd], eax
|
||||
mov [edx+APPOBJ.bk], eax
|
||||
popfd
|
||||
.done:
|
||||
ret
|
||||
|
||||
.destroy:
|
||||
call destroy_event.internal
|
||||
ret
|
||||
.switch:
|
||||
mov eax, [0x3010]
|
||||
@ -157,6 +277,126 @@ proc get_event_ex stdcall, p_ev:dword, timeout:dword
|
||||
jmp .wait
|
||||
endp
|
||||
|
||||
; param
|
||||
; eax= event
|
||||
; ebx= id
|
||||
|
||||
align 4
|
||||
wait_event:
|
||||
.event equ esp
|
||||
push eax
|
||||
.wait:
|
||||
cmp [eax+APPOBJ.magic], 'EVNT'
|
||||
jne .done
|
||||
cmp [eax+EVENT.id], ebx
|
||||
jne .done
|
||||
|
||||
test [eax+EVENT.state], EVENT_SIGNALED
|
||||
jz .switch
|
||||
|
||||
test [eax+EVENT.state], MANUAL_RESET
|
||||
jnz .done
|
||||
|
||||
mov edx,[CURRENT_TASK]
|
||||
shl edx,8
|
||||
add edx, PROC_BASE
|
||||
|
||||
pushfd
|
||||
cli ;remove event from events
|
||||
mov ebx, [eax+APPOBJ.fd] ;list (reset event)
|
||||
mov ecx, [eax+APPOBJ.bk] ;and clear events flag
|
||||
mov [ebx+APPOBJ.bk], ecx ;if no active events
|
||||
mov [ecx+APPOBJ.fd], ebx
|
||||
dec [edx+APPDATA.ev_count]
|
||||
jnz @F
|
||||
and [edx+APPDATA.event_mask], not EVENT_EXTENDED
|
||||
@@:
|
||||
and [eax+EVENT.state], not (EVENT_SIGNALED+EVENT_WATCHED)
|
||||
popfd
|
||||
|
||||
test [eax+EVENT.state], MANUAL_DESTROY
|
||||
jz .destroy
|
||||
|
||||
add edx, APP_OBJ_OFFSET
|
||||
|
||||
pushfd
|
||||
cli
|
||||
mov ecx, [edx+APPOBJ.fd] ;insert event into
|
||||
mov [eax+APPOBJ.fd], ecx ;objects list
|
||||
mov [eax+APPOBJ.bk], edx
|
||||
mov [edx+APPOBJ.fd], eax
|
||||
mov [ecx+APPOBJ.bk], eax
|
||||
popfd
|
||||
.done:
|
||||
add esp, 4
|
||||
ret
|
||||
.destroy:
|
||||
call destroy_event.internal
|
||||
add esp, 4
|
||||
ret
|
||||
.switch:
|
||||
or [eax+EVENT.state], EVENT_WATCHED
|
||||
mov eax, [0x3010]
|
||||
mov [eax+TASKDATA.state], byte 5
|
||||
call change_task
|
||||
mov eax, [.event]
|
||||
jmp .wait
|
||||
restore .event
|
||||
|
||||
; param
|
||||
; eax= event
|
||||
; ebx= id
|
||||
; ecx= flags
|
||||
|
||||
raise_event:
|
||||
.event equ esp
|
||||
push eax
|
||||
|
||||
cmp [eax+APPOBJ.magic], 'EVNT'
|
||||
jne .fail
|
||||
cmp [eax+EVENT.id], ebx
|
||||
jne .fail
|
||||
|
||||
mov eax, [eax+APPOBJ.pid]
|
||||
call pid_to_slot
|
||||
test eax, eax
|
||||
jz .fail
|
||||
|
||||
mov edx, [.event]
|
||||
test [edx+EVENT.state], EVENT_SIGNALED
|
||||
jnz .done
|
||||
|
||||
test ecx, EVENT_WATCHED
|
||||
jz @F
|
||||
test [edx+EVENT.state], EVENT_WATCHED
|
||||
jz .done
|
||||
@@:
|
||||
shl eax, 8
|
||||
add eax, PROC_BASE+APP_EV_OFFSET
|
||||
|
||||
pushfd
|
||||
cli
|
||||
mov ebx, [edx+APPOBJ.fd]
|
||||
mov ecx, [edx+APPOBJ.bk]
|
||||
mov [ebx+APPOBJ.bk], ecx
|
||||
mov [ecx+APPOBJ.fd], ebx
|
||||
|
||||
mov ecx, [eax+APPOBJ.fd]
|
||||
mov [edx+APPOBJ.fd], ecx
|
||||
mov [edx+APPOBJ.bk], eax
|
||||
mov [eax+APPOBJ.fd], edx
|
||||
mov [ecx+APPOBJ.bk], edx
|
||||
or [edx+EVENT.state], EVENT_SIGNALED
|
||||
|
||||
inc [eax+APPDATA.ev_count-APP_EV_OFFSET]
|
||||
or [eax+APPDATA.event_mask-APP_EV_OFFSET], EVENT_EXTENDED
|
||||
popfd
|
||||
.fail:
|
||||
.done:
|
||||
add esp, 4
|
||||
ret
|
||||
restore .event
|
||||
|
||||
sys_getevent:
|
||||
|
||||
call get_event_for_app
|
||||
@ -321,27 +561,26 @@ get_event_for_app:
|
||||
no_stack_event:
|
||||
|
||||
test byte [edi+TASKDATA.event_mask+1], 1 ; DEBUG
|
||||
jz .test_ext
|
||||
jz .test_IRQ
|
||||
mov eax, [0x3000]
|
||||
shl eax, 8
|
||||
test byte [eax+0x80000+APPDATA.event_mask+1], byte 1
|
||||
jz .test_ext
|
||||
jz .test_IRQ
|
||||
and byte [eax+0x80000+APPDATA.event_mask+1], not 1
|
||||
popad
|
||||
mov eax, 9
|
||||
ret
|
||||
|
||||
.test_ext:
|
||||
mov eax, [0x3000]
|
||||
shl eax, 8
|
||||
test dword [eax+0x80000+APPDATA.event_mask], EVENT_EXTENDED
|
||||
jz .test_IRQ
|
||||
mov eax, 10
|
||||
ret
|
||||
;.test_ext:
|
||||
; mov eax, [0x3000]
|
||||
; shl eax, 8
|
||||
; test dword [eax+0x80000+APPDATA.event_mask], EVENT_EXTENDED
|
||||
; jz .test_IRQ
|
||||
; popad
|
||||
; mov eax, 10
|
||||
; ret
|
||||
|
||||
.test_IRQ:
|
||||
|
||||
|
||||
cmp dword [edi+TASKDATA.event_mask], 0xFFFF
|
||||
jbe no_events
|
||||
|
||||
|
@ -176,12 +176,12 @@ struc APPDATA
|
||||
.ev_count dd ? ;+20
|
||||
.fpu_handler dd ? ;+24
|
||||
.sse_handler dd ? ;+28
|
||||
.event dd ? ;+32
|
||||
dd ? ;unused ;+32
|
||||
.heap_base dd ? ;+36
|
||||
.heap_top dd ? ;+40
|
||||
.cursor dd ? ;+44
|
||||
.ev_first dd ? ;+48
|
||||
.ev_last dd ? ;+52
|
||||
.fd_ev dd ? ;+48
|
||||
.bk_ev dd ? ;+52
|
||||
.fd_obj dd ? ;+56
|
||||
.bk_obj dd ? ;+60
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user