From 65a702a88b87da310095527bdf0aaa6ab80d34b3 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Tue, 6 Nov 2018 06:24:59 +0000 Subject: [PATCH] enhanced callback functions for os2 --- moo/kernel/Http.moo | 4 ++-- moo/kernel/Mill.moo | 2 ++ moo/kernel/System.moo | 2 +- moo/lib/main.c | 47 +++++++++++++++++++++++++++++++++++++++---- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/moo/kernel/Http.moo b/moo/kernel/Http.moo index ff166d5..cb54ced 100644 --- a/moo/kernel/Http.moo +++ b/moo/kernel/Http.moo @@ -421,7 +421,7 @@ class MyObject(Object) [ | ss | httpd start: %( - SocketAddress fromString: ('[::]:' & base_port asString), + ## SocketAddress fromString: ('[::]:' & base_port asString), SocketAddress fromString: ('0.0.0.0:' & (base_port + 1) asString) ). @@ -463,7 +463,7 @@ httpd connect: addr. [ | ss | httpd start: %( - SocketAddress fromString: '[::]:7777', + ## SocketAddress fromString: '[::]:7777', SocketAddress fromString: '0.0.0.0:7776' ). diff --git a/moo/kernel/Mill.moo b/moo/kernel/Mill.moo index b6b3fbd..98af232 100644 --- a/moo/kernel/Mill.moo +++ b/moo/kernel/Mill.moo @@ -84,6 +84,7 @@ class MyObject(Object) [Exception hash dump] ensure: ['xxxx' dump]. ] on: Exception do: [:ex | ('Exception caught - ' & ex asString) dump ].*) +(* ffi := FFI new: '/lib64/libc.so.6'. if (ffi isError) { @@ -96,6 +97,7 @@ class MyObject(Object) (ffi call: #printf signature: 's|iis)i' arguments: #(S'A=>%d B=>%d Hello, world %s\n' 1 2 'jump down')) dump. ffi close. }. +*) (('abcd' == 'abcd') ifTrue: [1] ifFalse: [2]) dump. } diff --git a/moo/kernel/System.moo b/moo/kernel/System.moo index 52008c4..c9f3666 100644 --- a/moo/kernel/System.moo +++ b/moo/kernel/System.moo @@ -261,7 +261,7 @@ TODO: how to pass all variadic arguments to another variadic methods??? class SmallPointer(Object) { method(#primitive) asString. - + method(#primitive) getInt8 (offset). method(#primitive) getInt16 (offset). method(#primitive) getInt32 (offset). diff --git a/moo/lib/main.c b/moo/lib/main.c index b28ecac..43246b6 100644 --- a/moo/lib/main.c +++ b/moo/lib/main.c @@ -61,6 +61,7 @@ #elif defined(__OS2__) # define INCL_DOSMODULEMGR # define INCL_DOSPROCESS +# define INCL_DOSSEMAPHORES # define INCL_DOSEXCEPTIONS # define INCL_DOSMISC # define INCL_DOSDATETIME @@ -2588,6 +2589,44 @@ static VOID CALLBACK arrange_process_switching (LPVOID arg, DWORD timeLow, DWORD if (g_moo) moo_switchprocess (g_moo); } +#elif defined(__OS2__) +static TID g_tick_tid; +static HEV g_tick_sem; +static HTIMER g_tick_timer; +static int g_tick_done = 0; + +static void EXPENTRY os2_wait_for_timer_event (ULONG x) +{ + APIRET rc; + ULONG count; + + rc = DosCreateEventSem (NULL, &g_tick_sem, DC_SEM_SHARED, FALSE); + if (rc != NO_ERROR) + { + /* xxxx */ + } + + rc = DosStartTimer (1L, (HSEM)g_tick_sem, &g_tick_timer); + if (rc != NO_ERROR) + { + } + + while (!g_tick_done) + { + rc = DosWaitEventSem((HSEM)g_tick_sem, 5000L); + DosResetEventSem((HSEM)g_tick_sem, &count); + if (g_moo) moo_switchprocess (g_moo); + } + + DosStopTimer (g_tick_timer); + DosCloseEventSem ((HSEM)g_tick_sem); + + g_tick_timer = NULL; + g_tick_sem = NULL; + DosExit (EXIT_THREAD, 0); +} + + #elif defined(macintosh) static TMTask g_tmtask; @@ -2627,8 +2666,8 @@ static void setup_tick (void) } #elif defined(__OS2__) - /* TODO: */ - #error UNSUPPORTED + /* TODO: Error check */ + DosCreateThread (&g_tick_tid, os2_wait_for_timer_event, 0, 0, 4096); #elif defined(macintosh) @@ -2677,8 +2716,8 @@ static void cancel_tick (void) } #elif defined(__OS2__) - /* TODO: */ - #error UNSUPPORTED + if (g_tick_sem) DosPostEventSem (g_tick_sem); + g_tick_done = 1; #elif defined(macintosh) RmvTime ((QElem*)&g_tmtask);