00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #define ScheduleConsumer(Consumer,First,Last) { \
00039 if ( IsNonNULL(Last) ) \
00040 nlcp_prevbreg(Last) = Consumer; \
00041 else \
00042 First = Consumer; \
00043 Last = Consumer; \
00044 }
00045
00046 #define ANSWER_TEMPLATE nlcp_template(consumer_cpf)
00047
00048 static CPtr sched_answers(CTXTdeclc VariantSF producer_sf, CPtr *last_consumer)
00049 {
00050
00051 CPtr first_sched_cons, last_sched_cons, consumer_cpf;
00052
00053
00054 #ifdef PROFILE
00055 subinst_table[SCHED_ANSWERS][1]++;
00056 #endif
00057 xsb_dbgmsg((LOG_COMPLETION,"scheduling answers for %x\n",
00058 subg_cp_ptr(producer_sf)));
00059 first_sched_cons = last_sched_cons = NULL;
00060 consumer_cpf = subg_asf_list_ptr(producer_sf);
00061
00062
00063 if ( has_answers(producer_sf) && IsNonNULL(consumer_cpf)
00064 && !subg_is_reclaimed(producer_sf)) {
00065
00066 if ( IsSubsumptiveProducer(producer_sf) )
00067 while ( IsNonNULL(consumer_cpf) ) {
00068 SubConsSF consumer_sf;
00069 ALNptr answer_continuation;
00070 BTNptr next_answer;
00071
00072 consumer_sf = (SubConsSF)nlcp_subgoal_ptr(consumer_cpf);
00073
00074 table_pending_answer( nlcp_trie_return(consumer_cpf),
00075 answer_continuation,
00076 next_answer,
00077 consumer_sf,
00078 (SubProdSF)producer_sf,
00079 ANSWER_TEMPLATE,
00080 switch_envs(consumer_cpf),
00081 TPA_NoOp );
00082 if ( IsNonNULL(answer_continuation) )
00083 ScheduleConsumer(consumer_cpf,first_sched_cons,last_sched_cons);
00084 consumer_cpf = nlcp_prevlookup(consumer_cpf);
00085 }
00086 else
00087 while ( IsNonNULL(consumer_cpf) ) {
00088 #ifdef CONC_COMPL
00089 if( int_val(nlcp_tid(consumer_cpf)) != th->tid )
00090 ;
00091 else
00092 #endif
00093 if ( IsNonNULL(ALN_Next(nlcp_trie_return(consumer_cpf))) ) {
00094 xsb_dbgmsg((LOG_SCHED,"Scheduling Answer for: consumer_cpf=%x\n",
00095 (int)consumer_cpf));
00096 ScheduleConsumer(consumer_cpf,first_sched_cons,last_sched_cons);
00097 }
00098 consumer_cpf = nlcp_prevlookup(consumer_cpf);
00099 }
00100
00101 if( last_consumer )
00102 *last_consumer = last_sched_cons;
00103 if( last_sched_cons ) {
00104
00105 nlcp_prevbreg(last_sched_cons) = breg ;
00106 xsb_dbgmsg((LOG_SCHED,
00107 "scheduling fixed point base for last %x at %x @breg %x\n",
00108 last_sched_cons,breg,*tcp_pcreg(breg)));
00109 }
00110 }
00111
00112 return first_sched_cons;
00113 }
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 static CPtr find_fixpoint(CTXTdeclc CPtr leader_csf, CPtr producer_cpf)
00125 {
00126
00127 VariantSF currSubg;
00128 CPtr complFrame;
00129 CPtr last_cons = 0;
00130 CPtr sched_chain = 0, prev_sched = 0, tmp_sched = 0;
00131
00132 #ifdef PROFILE
00133 subinst_table[OUTER_FIXPOINT][1]++;
00134 #endif
00135 xsb_dbgmsg((LOG_COMPLETION,"starting fp: %x\n",
00136 subg_cp_ptr(compl_subgoal_ptr(leader_csf))));
00137
00138 complFrame = openreg;
00139
00140
00141
00142
00143
00144 #ifdef CONC_COMPL
00145 InitThreadDepList(&th->TDL);
00146
00147 while(complFrame <= leader_csf) {
00148 #else
00149 while(complFrame < leader_csf) {
00150 #endif
00151 #ifdef PROFILE
00152 subinst_table[ITER_FIXPOINT][1]++;
00153 #endif
00154 currSubg = compl_subgoal_ptr(complFrame);
00155 xsb_dbgmsg((LOG_COMPLETION,"iterating: %x\n",subg_cp_ptr(currSubg)));
00156
00157
00158
00159 #ifdef CONC_COMPL
00160 if ( IsNonNULL(compl_ext_cons(complFrame)) )
00161 last_cons=tmp_sched=sched_external(CTXTc compl_ext_cons(complFrame));
00162 else
00163 tmp_sched = sched_answers(CTXTc currSubg, &last_cons) ;
00164 if (tmp_sched) {
00165 #else
00166 if ((tmp_sched = sched_answers(CTXTc currSubg, &last_cons))) {
00167 #endif
00168 if (prev_sched) {
00169
00170 nlcp_prevbreg(prev_sched) = tmp_sched;
00171 }
00172 else {
00173 sched_chain = tmp_sched;
00174 }
00175 if( last_cons == NULL ) printf("lc NULL");
00176 prev_sched = last_cons;
00177 }
00178 complFrame = prev_compl_frame(complFrame);
00179 }
00180
00181 if (prev_sched)
00182
00183 nlcp_prevbreg(prev_sched) = producer_cpf;
00184
00185 xsb_dbgmsg((LOG_COMPLETION,"ending fp: %x\n",
00186 subg_cp_ptr(compl_subgoal_ptr(leader_csf))));
00187
00188 return sched_chain;
00189 }