Changeset 4452 for trunk/compiler
- Timestamp:
- 08/29/08 13:30:27 (4 months ago)
- Files:
-
- 1 modified
-
trunk/compiler/logtalk.pl (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/compiler/logtalk.pl
r4451 r4452 6845 6845 '$lgt_tr_body'(threaded_call(Goal, Tag), MTGoal, '$lgt_dbg_goal'(threaded_call(Goal, Tag), MTGoal, DbgCtx), Ctx) :- 6846 6846 !, 6847 '$lgt_ctx_ctx'(Ctx, _, Sender, This, Self, _, _, _),6847 '$lgt_ctx_ctx'(Ctx, _, _, This, Self, _, _, _), 6848 6848 '$lgt_tr_body'(Goal, TGoal, _, Ctx), 6849 6849 ( '$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)) 6852 6852 ), 6853 6853 '$lgt_ctx_dbg_ctx'(Ctx, DbgCtx). … … 6866 6866 '$lgt_tr_body'(threaded_call(Goal), MTGoal, '$lgt_dbg_goal'(threaded_call(Goal), MTGoal, DbgCtx), Ctx) :- 6867 6867 !, 6868 '$lgt_ctx_ctx'(Ctx, _, Sender, This, Self, _, _, _),6868 '$lgt_ctx_ctx'(Ctx, _, _, This, Self, _, _, _), 6869 6869 '$lgt_tr_body'(Goal, TGoal, _, Ctx), 6870 6870 ( '$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, []) 6873 6873 ), 6874 6874 '$lgt_ctx_dbg_ctx'(Ctx, DbgCtx). … … 6891 6891 '$lgt_tr_body'(threaded_once(Goal, Tag), MTGoal, '$lgt_dbg_goal'(threaded_once(Goal, Tag), MTGoal, DbgCtx), Ctx) :- 6892 6892 !, 6893 '$lgt_ctx_ctx'(Ctx, _, Sender, This, Self, _, _, _),6893 '$lgt_ctx_ctx'(Ctx, _, _, This, Self, _, _, _), 6894 6894 '$lgt_tr_body'(Goal, TGoal, _, Ctx), 6895 6895 ( '$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)) 6898 6898 ), 6899 6899 '$lgt_ctx_dbg_ctx'(Ctx, DbgCtx). … … 6912 6912 '$lgt_tr_body'(threaded_once(Goal), MTGoal, '$lgt_dbg_goal'(threaded_once(Goal), MTGoal, DbgCtx), Ctx) :- 6913 6913 !, 6914 '$lgt_ctx_ctx'(Ctx, _, Sender, This, Self, _, _, _),6914 '$lgt_ctx_ctx'(Ctx, _, _, This, Self, _, _, _), 6915 6915 '$lgt_tr_body'(Goal, TGoal, _, Ctx), 6916 6916 ( '$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, []) 6919 6919 ), 6920 6920 '$lgt_ctx_dbg_ctx'(Ctx, DbgCtx). … … 6933 6933 '$lgt_tr_body'(threaded_ignore(Goal), MTGoal, '$lgt_dbg_goal'(threaded_ignore(Goal), MTGoal, DbgCtx), Ctx) :- 6934 6934 !, 6935 '$lgt_ctx_ctx'(Ctx, _, Sender, This, Self, _, _, _),6935 '$lgt_ctx_ctx'(Ctx, _, _, This, Self, _, _, _), 6936 6936 '$lgt_tr_body'(Goal, TGoal, _, Ctx), 6937 6937 ( '$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, _) 6940 6940 ), 6941 6941 '$lgt_ctx_dbg_ctx'(Ctx, DbgCtx). … … 13152 13152 13153 13153 13154 % '$lgt_start_runtime_dispatcher'13155 %13156 % starts up the dispatcher thread13157 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 loop13166 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 exception13171 thread_create(catch(Goal, _, true), _, [detached(true)])13172 ; Option = once(Tag) -> % make thread goal deterministic13173 thread_create('$lgt_mt_det_goal'(Queue, Goal, This, Self, Tag), _, [detached(true)])13174 ; Option = call(Tag) -> % make thread goal non-deterministic13175 thread_create('$lgt_mt_non_det_goal'(Queue, Goal, This, Self, Tag), _, [detached(false)])13176 ),13177 fail.13178 13179 13180 13181 13154 % '$lgt_mt_det_goal'(+atom, +callable, +object_identifier, +object_identifier, @nonvar) 13182 13155 % … … 13185 13158 '$lgt_mt_det_goal'(Return, Goal, This, Self, Tag) :- 13186 13159 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)), 13188 13161 % 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)), 13190 13163 ( catch(Goal, Error, (thread_send_message(Return, '$lgt_reply'(Goal, This, Self, Tag, Error, DetId)), Flag = error)) -> 13191 13164 ( var(Flag) -> … … 13205 13178 '$lgt_mt_non_det_goal'(Return, Goal, This, Self, Tag) :- 13206 13179 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)), 13208 13181 % 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)), 13210 13183 ( catch(Goal, Error, (thread_send_message(Return, '$lgt_reply'(Goal, This, Self, Tag, Error, NonDetId)), Flag = error)), 13211 13184 ( var(Flag) -> … … 13224 13197 13225 13198 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) :- 13231 13204 '$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 thread13239 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)). 13252 13225 13253 13226 … … 13291 13264 % answering thread exists; go ahead and retrieve the solution(s): 13292 13265 thread_get_message(Queue, '$lgt_thread_id'(Type, Goal, This, Self, Tag, Id)), 13293 ( Type == deterministic->13266 ( Type == once -> 13294 13267 '$lgt_mt_det_reply'(Queue, Goal, This, Self, Tag, Id) % detached thread 13295 13268 ; call_cleanup( … … 13816 13789 '$lgt_current_object_'(user, Prefix, _, _, _, _, _, _, _, _, _, _, _) -> 13817 13790 '$lgt_init_object_message_queue'(Prefix), 13818 '$lgt_start_runtime_dispatcher',13819 13791 ( '$lgt_predicate_property'(mutex_create(_, _), built_in) -> 13820 13792 mutex_create(_, [alias('$lgt_threaded_tag')])
