Changeset 6 for trunk

Show
Ignore:
Timestamp:
04/03/06 00:50:06 (3 years ago)
Author:
scottmc
Message:

Event loop functioning

Basic segfault when event loop returns and queue is empty, process should go
into idle at that state.

Location:
trunk/sagot
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/sagot/src/sagot_glib_eventloop.c

    r5 r6  
    2525 
    2626static JSFunctionSpec eventloop_methods[] = { 
    27     {"run",         sagot_eventloop_run, 0,0,0 }, 
    28     {"quit",        sagot_eventloop_quit, 0,0,0 }, 
     27    {"run",         sagot_eventloop_run,        0,0,0 }, 
     28    {"quit",        sagot_eventloop_quit,       0,0,0 }, 
     29    {"yield",       sagot_eventloop_yield,      1,0,0 }, 
    2930}; 
    3031 
     
    8283    JSContext *cx = qitem->cx; 
    8384    jsval *argv = qitem->argv; 
     85    jsval argc = qitem->argc; 
    8486 
    8587    JSObject *fobj = JSVAL_TO_OBJECT(argv[0]); 
     
    8991 
    9092    jsval *rval; 
    91     JS_CallFunction(cx, parent, function, qitem->argc, argv, rval);  
     93    jsval *args = g_malloc(sizeof(jsval *) * (argc - 1)); 
    9294 
    93     JS_RemoveRoot(cx, rval); 
    94     JS_RemoveRoot(cx, argv); 
     95    for (int i = 1; i < argc; i++) { 
     96        args[i - 1] = argv[i]; 
     97    } 
     98 
     99    JS_CallFunction(cx, parent, function, qitem->argc, args, rval);  
     100 
     101    return TRUE; 
     102} 
     103 
     104void sagot_eventloop_dispatch_cleanup (void *data) { 
     105    struct queue_item *qitem = (struct queue_item *) data; 
     106 
     107    JS_RemoveRoot(qitem->cx, qitem->argv); 
    95108 
    96109    g_free(qitem); 
    97110} 
    98111 
    99 void sagot_eventloop_dispatch_cleanup (void *data) { 
    100     JSObject *object = (JSObject *) data; 
    101 } 
    102  
    103 static JSBool sagot_eventloop_enqueue (JSContext *cx, JSObject *obj, uintN 
     112static JSBool sagot_eventloop_yield (JSContext *cx, JSObject *obj, uintN 
    104113        argc, jsval *argv, jsval *rval) { 
    105114    GMainLoop *mainloop = (GMainLoop *) JS_GetPrivate(cx, obj); 
     
    115124    if (argc < 1) { 
    116125        JS_ReportError(cx, "EventLoop.enqueue() requires arguments"); 
    117         return JS_FALSE; 
     126        return false; 
    118127    } 
    119128 
     
    126135        JS_AddRoot(cx, argv); 
    127136 
    128         return JS_TRUE; 
     137        return true; 
    129138    } 
    130139 
    131140    JS_ReportError(cx, "argument 1 to enqueue() must be a function"); 
    132141 
    133     return JS_FALSE; 
     142    return false; 
    134143} 
    135144 
  • trunk/sagot/tests/test.js

    r5 r6  
    22var context = new EventContext () 
    33//var loop    = new EventLoop (context) 
    4 //var loop = new EventLoop () 
     4var loop = new EventLoop () 
     5 
     6function hello (foo) { 
     7    print(foo) 
     8} 
     9 
     10loop.yield(hello, "Hello World") 
     11loop.yield(hello, "Hello World") 
     12loop.yield(hello, "Hello World") 
     13loop.yield(hello, "Hello World") 
     14loop.yield(hello, "Hello World") 
    515loop.run() 
    6  
    7 print("HAH");