Re: Task scheduler sluggish
- Posted by ryanj Jul 03, 2009
- 1129 views
Win32lib has to be modified to be compatible with multitasking. I'm confused about the current condition of win32lib since everything is in a state of flux until 4.0 is released. I remember having problems about a year ago and I got it to work by inserting some task_yield() statements in win32lib.ew. I have no idea if that is now included in the latest release of win32lib. Does anyone know?
I have win32lib.ew (version 0.60.6) with task_yield() inserted in 3 places. I don't remember if it came that way or if I modified my copy...I haven't used it for a while, but it seems to work properly.
Around line 33393:
procedure eventLoop(object pData) sequence temp atom msg atom getRC integer inc integer el integer lTock ActiveEL &= 0 el = length(ActiveEL) -- Allocate a message buffer msg = w32acquire_mem(0, SIZEOF_MSG) lTock = 0 -- message loop while ActiveEL[el] = 0 and vWinMainState = kStarted do if vIdleCheck then while w32Func(xGetQueueStatus, {QS_ALLEVENTS}) = 0 do lTock += 1 if sequence(invokeHandler(Screen, w32HIdle, {lTock, msg})) then -- The user wishes to stop being idle and instead -- use the data they have loaded into the msg structure. lTock = -2 exit end if task_yield() --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< end while if lTock >= 0 then getRC = w32Func( xPeekMessage, { msg, 0, 0, 0, PM_REMOVE } ) if getRC > 0 and peek4u(msg+4) = WM_QUIT then exit end if -- I've decided to ignore the undocumented windows message WM_SYSTIMER ('280') -- so it won't stop the idling tock counting. if lTock > 0 and peek4u(msg+4) != WM_SYSTIMER then -- Signal end of idleness period. VOID = invokeHandler(Screen, w32HIdle, {-1, msg}) lTock = 0 end if else lTock = 0 end if else getRC = w32Func( xGetMessage, { msg, 0, 0, 0 } ) if getRC = 0 or getRC = -1 then exit end if end if -- Gather some entropy for the random integer routine w32Seed = remainder((w32Seed * peek4u(msg+16)) + 1 + peek4u(msg+20) * peek4u(msg+24), #FFFFFFFF) w32Proc( xTranslateMessage, { msg } ) w32Proc( xDispatchMessage, { msg } ) task_yield() --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< end while
And around line 33482:
global procedure doEvents(integer id) atom msg, hWnd if vWinMainState != kStarted then return end if if id = 0 then hWnd = 0 else if validId(id) = w32False then return end if hWnd = getHandle(id) end if -- Allocate a message buffer msg = w32acquire_mem(0, SIZEOF_MSG) if w32Func( xPeekMessage, { msg, hWnd, 0, 0, PM_REMOVE } ) then w32Proc( xTranslateMessage, { msg } ) w32Proc( xDispatchMessage, { msg } ) end if w32release_mem(msg) task_yield() --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< end procedure r_doEvents = routine_id("doEvents")