Re: win32lib et multitasking

new topic     » goto parent     » topic index » view thread      » older message » newer message

FWIW, I'm working on changes to FROG that will use the new multi-tasking
features.  Here's one way I found to use the multi-tasking within a win32lib
based program.  Note that this has not been thoroughly tested yet...

-- Here was the old function call that would execute an SQL statement
-- on the host.  This is where my program would appear to the user as
-- "not responding"
--          results = ecadb_execute(sql_system, sql_statement, cpp,
--                               describe_option, sql)
-- I replaced it with this call.  "task_sql" is basically the above 
-- function call.
            task_schedule(task_create(routine_id("task_sql"), 
                        {sql_system,sql_statement,cpp,describe_option,sql}),
                        1)
-- How many tasks are running?
            task_l = length(task_list())        
            msg = acquire_mem(0, SIZEOF_MSG)
-- Now I drop into a translate/dispatch message loop to keep the 
-- program responding while I wait for the return results. When the 
-- task count drops to 1 (main task) I drop out of this loop.
            -- Process message loop until end of program
            while w32Func( xGetMessage, { msg, 0, 0, 0 } ) and task_l > 1 do
                w32Proc( xTranslateMessage, { msg } )
                w32Proc( xDispatchMessage, { msg } )
                task_yield()                    
                task_l = length(task_list())                
            end while


Now way down in the bowels of the ecadb_execute function I open the DLL with
Daniel Kluss' TDLL routines:

cwbdb = open_tdll("cwbdb.dll")

Then I defined the C function in cwbdb.dll with his define_t_func:

-- Old approach
--  xcwbDB_Fetch = define_c_func(cwbdb,
--          "cwbDB_Fetch", {C_ULONG, C_ULONG}, C_UINT)
-- New approach
    xcwbDB_Fetch = define_t_func(cwbdb,
            "cwbDB_Fetch", {C_ULONG, C_ULONG}, C_UINT)

Then I call the function using his t_func:

global function cwbDB_Fetch(atom request_handle, atom error_handle)
--  cwbDB_EURtnCode = c_func(xcwbDB_Fetch,
--              {request_handle, error_handle})
    cwbDB_EURtnCode = t_func(xcwbDB_Fetch,
                {request_handle, error_handle})
    return {cwbDB_EURtnCode}
end function


I realized once I had made these changes that I was going to have to rework a
lot of my code to use this approach but frankly it's worth it.  All this to say
that using tasking with e,xisting win32lib GUI programs is not going to be a
trivial matter.  Take the time to analyze what changes your program will need.

Jonas Temple
http://www.yhti.net/~jktemple

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu