Changeset 4452 for trunk/compiler

Show
Ignore:
Timestamp:
08/29/08 13:30:27 (4 months ago)
Author:
pmoura
Message:

Removed the Logtalk dispatcher thread used for dispatching asynchronous multi-threading calls, simplifying the implementation and improving the performance of the asynchronous built-in multi-threading predicates.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/compiler/logtalk.pl

    r4451 r4452  
    68456845'$lgt_tr_body'(threaded_call(Goal, Tag), MTGoal, '$lgt_dbg_goal'(threaded_call(Goal, Tag), MTGoal, DbgCtx), Ctx) :- 
    68466846    !, 
    6847     '$lgt_ctx_ctx'(Ctx, _, Sender, This, Self, _, _, _), 
     6847    '$lgt_ctx_ctx'(Ctx, _, _, This, Self, _, _, _), 
    68486848    '$lgt_tr_body'(Goal, TGoal, _, Ctx), 
    68496849    (   '$lgt_pp_object_'(_, Prefix, _, _, _, _, _, _, _, _, _) -> 
    6850         MTGoal = ('$lgt_new_threaded_tag'(Tag), '$lgt_mt_dispatch_goal'(Prefix, TGoal, Sender, This, Self, call(Tag))) 
    6851     ;   MTGoal = ('$lgt_new_threaded_tag'(Tag), '$lgt_mt_dispatch_goal'(TGoal, Sender, This, Self, call(Tag))) 
     6850        MTGoal = ('$lgt_new_threaded_tag'(Tag), '$lgt_mt_dispatch_goal'(call, Prefix, TGoal, This, Self, Tag)) 
     6851    ;   MTGoal = ('$lgt_new_threaded_tag'(Tag), '$lgt_mt_dispatch_goal'(call, TGoal, This, Self, Tag)) 
    68526852    ), 
    68536853    '$lgt_ctx_dbg_ctx'(Ctx, DbgCtx). 
     
    68666866'$lgt_tr_body'(threaded_call(Goal), MTGoal, '$lgt_dbg_goal'(threaded_call(Goal), MTGoal, DbgCtx), Ctx) :- 
    68676867    !, 
    6868     '$lgt_ctx_ctx'(Ctx, _, Sender, This, Self, _, _, _), 
     6868    '$lgt_ctx_ctx'(Ctx, _, _, This, Self, _, _, _), 
    68696869    '$lgt_tr_body'(Goal, TGoal, _, Ctx), 
    68706870    (   '$lgt_pp_object_'(_, Prefix, _, _, _, _, _, _, _, _, _) -> 
    6871         MTGoal = '$lgt_mt_dispatch_goal'(Prefix, TGoal, Sender, This, Self, call([])) 
    6872     ;   MTGoal = '$lgt_mt_dispatch_goal'(TGoal, Sender, This, Self, call([])) 
     6871        MTGoal = '$lgt_mt_dispatch_goal'(call, Prefix, TGoal, This, Self, []) 
     6872    ;   MTGoal = '$lgt_mt_dispatch_goal'(call, TGoal, This, Self, []) 
    68736873    ), 
    68746874    '$lgt_ctx_dbg_ctx'(Ctx, DbgCtx). 
     
    68916891'$lgt_tr_body'(threaded_once(Goal, Tag), MTGoal, '$lgt_dbg_goal'(threaded_once(Goal, Tag), MTGoal, DbgCtx), Ctx) :- 
    68926892    !, 
    6893     '$lgt_ctx_ctx'(Ctx, _, Sender, This, Self, _, _, _), 
     6893    '$lgt_ctx_ctx'(Ctx, _, _, This, Self, _, _, _), 
    68946894    '$lgt_tr_body'(Goal, TGoal, _, Ctx), 
    68956895    (   '$lgt_pp_object_'(_, Prefix, _, _, _, _, _, _, _, _, _) -> 
    6896         MTGoal = ('$lgt_new_threaded_tag'(Tag), '$lgt_mt_dispatch_goal'(Prefix, TGoal, Sender, This, Self, once(Tag))) 
    6897     ;   MTGoal = ('$lgt_new_threaded_tag'(Tag), '$lgt_mt_dispatch_goal'(TGoal, Sender, This, Self, once(Tag))) 
     6896        MTGoal = ('$lgt_new_threaded_tag'(Tag), '$lgt_mt_dispatch_goal'(once, Prefix, TGoal, This, Self, Tag)) 
     6897    ;   MTGoal = ('$lgt_new_threaded_tag'(Tag), '$lgt_mt_dispatch_goal'(once, TGoal, This, Self, Tag)) 
    68986898    ), 
    68996899    '$lgt_ctx_dbg_ctx'(Ctx, DbgCtx). 
     
    69126912'$lgt_tr_body'(threaded_once(Goal), MTGoal, '$lgt_dbg_goal'(threaded_once(Goal), MTGoal, DbgCtx), Ctx) :- 
    69136913    !, 
    6914     '$lgt_ctx_ctx'(Ctx, _, Sender, This, Self, _, _, _), 
     6914    '$lgt_ctx_ctx'(Ctx, _, _, This, Self, _, _, _), 
    69156915    '$lgt_tr_body'(Goal, TGoal, _, Ctx), 
    69166916    (   '$lgt_pp_object_'(_, Prefix, _, _, _, _, _, _, _, _, _) -> 
    6917         MTGoal = '$lgt_mt_dispatch_goal'(Prefix, TGoal, Sender, This, Self, once([])) 
    6918     ;   MTGoal = '$lgt_mt_dispatch_goal'(TGoal, Sender, This, Self, once([])) 
     6917        MTGoal = '$lgt_mt_dispatch_goal'(once, Prefix, TGoal, This, Self, []) 
     6918    ;   MTGoal = '$lgt_mt_dispatch_goal'(once, TGoal, This, Self, []) 
    69196919    ), 
    69206920    '$lgt_ctx_dbg_ctx'(Ctx, DbgCtx). 
     
    69336933'$lgt_tr_body'(threaded_ignore(Goal), MTGoal, '$lgt_dbg_goal'(threaded_ignore(Goal), MTGoal, DbgCtx), Ctx) :- 
    69346934    !, 
    6935     '$lgt_ctx_ctx'(Ctx, _, Sender, This, Self, _, _, _), 
     6935    '$lgt_ctx_ctx'(Ctx, _, _, This, Self, _, _, _), 
    69366936    '$lgt_tr_body'(Goal, TGoal, _, Ctx), 
    69376937    (   '$lgt_pp_object_'(_, Prefix, _, _, _, _, _, _, _, _, _) -> 
    6938         MTGoal = '$lgt_mt_dispatch_goal'(Prefix, TGoal, Sender, This, Self, ignore) 
    6939     ;   MTGoal = '$lgt_mt_dispatch_goal'(TGoal, Sender, This, Self, ignore) 
     6938        MTGoal = '$lgt_mt_dispatch_goal'(ignore, Prefix, TGoal, This, Self, _) 
     6939    ;   MTGoal = '$lgt_mt_dispatch_goal'(ignore, TGoal, This, Self, _) 
    69406940    ), 
    69416941    '$lgt_ctx_dbg_ctx'(Ctx, DbgCtx). 
     
    1315213152 
    1315313153 
    13154 % '$lgt_start_runtime_dispatcher' 
    13155 % 
    13156 % starts up the dispatcher thread  
    13157  
    13158 '$lgt_start_runtime_dispatcher' :- 
    13159     thread_create('$lgt_mt_obj_dispatcher', _, [alias(logtalk_dispatcher), detached(false)]). 
    13160  
    13161  
    13162  
    13163 % '$lgt_mt_obj_dispatcher' 
    13164 % 
    13165 % multi-threading message dispatcher processing loop 
    13166  
    13167 '$lgt_mt_obj_dispatcher' :- 
    13168     repeat, 
    13169         thread_get_message('$lgt_goal'(Queue, Goal, This, Self, Option)), 
    13170         (   Option == ignore ->     % don't bother reporting goal success, failure, or exception 
    13171             thread_create(catch(Goal, _, true), _, [detached(true)]) 
    13172         ;   Option = once(Tag) ->   % make thread goal deterministic 
    13173             thread_create('$lgt_mt_det_goal'(Queue, Goal, This, Self, Tag), _, [detached(true)]) 
    13174         ;   Option = call(Tag) ->   % make thread goal non-deterministic 
    13175             thread_create('$lgt_mt_non_det_goal'(Queue, Goal, This, Self, Tag), _, [detached(false)]) 
    13176         ), 
    13177     fail. 
    13178  
    13179  
    13180  
    1318113154% '$lgt_mt_det_goal'(+atom, +callable, +object_identifier, +object_identifier, @nonvar) 
    1318213155% 
     
    1318513158'$lgt_mt_det_goal'(Return, Goal, This, Self, Tag) :- 
    1318613159    thread_self(DetId), 
    13187     thread_send_message(Return, '$lgt_thread_id'(deterministic, Goal, This, Self, Tag, DetId)), 
     13160    thread_send_message(Return, '$lgt_thread_id'(once, Goal, This, Self, Tag, DetId)), 
    1318813161    % signal that the thread running the goal is ready: 
    13189     thread_send_message(Return, '$lgt_ready'(Goal, This, Self, once(Tag))), 
     13162    thread_send_message(Return, '$lgt_det_ready'(Goal, This, Self, Tag)), 
    1319013163    (   catch(Goal, Error, (thread_send_message(Return, '$lgt_reply'(Goal, This, Self, Tag, Error, DetId)), Flag = error)) -> 
    1319113164        (   var(Flag) -> 
     
    1320513178'$lgt_mt_non_det_goal'(Return, Goal, This, Self, Tag) :- 
    1320613179    thread_self(NonDetId), 
    13207     thread_send_message(Return, '$lgt_thread_id'(non_deterministic, Goal, This, Self, Tag, NonDetId)), 
     13180    thread_send_message(Return, '$lgt_thread_id'(call, Goal, This, Self, Tag, NonDetId)), 
    1320813181    % signal that the thread running the goal is ready: 
    13209     thread_send_message(Return, '$lgt_ready'(Goal, This, Self, call(Tag))), 
     13182    thread_send_message(Return, '$lgt_non_det_ready'(Goal, This, Self, Tag)), 
    1321013183    (   catch(Goal, Error, (thread_send_message(Return, '$lgt_reply'(Goal, This, Self, Tag, Error, NonDetId)), Flag = error)), 
    1321113184        (   var(Flag) -> 
     
    1322413197 
    1322513198 
    13226 % '$lgt_mt_dispatch_goal'(@callable, +object_identifier, +object_identifier, +object_identifier, +list) 
    13227 % 
    13228 % sends a goal to the dispatcher thread (this predicate is called from within categories) 
    13229  
    13230 '$lgt_mt_dispatch_goal'(Goal, Sender, This, Self, Option) :- 
     13199% '$lgt_mt_dispatch_goal'(+atom, +object_identifier, +object_identifier, @callable, @tag) 
     13200% 
     13201% creates a thread for proving a goal (this predicate is called from within categories) 
     13202 
     13203'$lgt_mt_dispatch_goal'(Option, Goal, This, Self, Tag) :- 
    1323113204    '$lgt_current_object_'(This, Queue, _, _, _, _, _, _, _, _, _, _, _) -> 
    13232     '$lgt_mt_dispatch_goal'(Queue, Goal, Sender, This, Self, Option). 
    13233  
    13234  
    13235  
    13236 % '$lgt_mt_dispatch_goal'(+message_queue, @callable, +object_identifier, +object_identifier, +object_identifier, +list) 
    13237 % 
    13238 % sends a goal to the dispatcher thread 
    13239  
    13240 '$lgt_mt_dispatch_goal'(Queue, Goal, Sender, This, Self, Option) :- 
    13241     (   thread_property(logtalk_dispatcher, status(running)) -> 
    13242         % ask the Logtalk dispatcher to create a new thread for proving the goal: 
    13243         thread_send_message(logtalk_dispatcher, '$lgt_goal'(Queue, Goal, This, Self, Option)), 
    13244         (   Option == ignore -> 
    13245             true 
    13246         ;   % wait until the thread created for proving the goal is ready before proceeding: 
    13247             thread_get_message(Queue, '$lgt_ready'(Goal, This, Self, Option)) 
    13248         ) 
    13249     ;   % something went terrible wrong with the dispatcher thread: 
    13250         throw(error(existence_error(logtalk_dispatcher, This), Goal, Sender)) 
    13251     ). 
     13205    '$lgt_mt_dispatch_goal'(Option, Queue, Goal, This, Self, Tag). 
     13206 
     13207 
     13208 
     13209% '$lgt_mt_dispatch_goal'(+atom, +message_queue, @callable, +object_identifier, +object_identifier, @tag) 
     13210% 
     13211% creates a thread for proving a goal 
     13212 
     13213'$lgt_mt_dispatch_goal'(ignore, _, Goal, _, _, _) :- 
     13214    thread_create(catch(Goal, _, true), _, [detached(true)]). 
     13215 
     13216'$lgt_mt_dispatch_goal'(call, Queue, Goal, This, Self, Tag) :- 
     13217    thread_create('$lgt_mt_non_det_goal'(Queue, Goal, This, Self, Tag), _, [detached(false)]), 
     13218    % wait until the thread created for proving the goal is ready before proceeding: 
     13219    thread_get_message(Queue, '$lgt_non_det_ready'(Goal, This, Self, Tag)). 
     13220 
     13221'$lgt_mt_dispatch_goal'(once, Queue, Goal, This, Self, Tag) :- 
     13222    thread_create('$lgt_mt_det_goal'(Queue, Goal, This, Self, Tag), _, [detached(true)]), 
     13223    % wait until the thread created for proving the goal is ready before proceeding: 
     13224    thread_get_message(Queue, '$lgt_det_ready'(Goal, This, Self, Tag)). 
    1325213225 
    1325313226 
     
    1329113264        % answering thread exists; go ahead and retrieve the solution(s): 
    1329213265        thread_get_message(Queue, '$lgt_thread_id'(Type, Goal, This, Self, Tag, Id)), 
    13293         (   Type == deterministic -> 
     13266        (   Type == once -> 
    1329413267            '$lgt_mt_det_reply'(Queue, Goal, This, Self, Tag, Id)           % detached thread 
    1329513268        ;   call_cleanup( 
     
    1381613789        '$lgt_current_object_'(user, Prefix, _, _, _, _, _, _, _, _, _, _, _) -> 
    1381713790        '$lgt_init_object_message_queue'(Prefix), 
    13818         '$lgt_start_runtime_dispatcher', 
    1381913791        (   '$lgt_predicate_property'(mutex_create(_, _), built_in) -> 
    1382013792            mutex_create(_, [alias('$lgt_threaded_tag')])