From: Terrance S. <ts...@us...> - 2007-04-06 11:41:52
|
Update of /cvsroot/xsb/XSB/emu In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv3790 Modified Files: cinterf.c tr_utils.c tries.c Log Message: Changes and additions to comments only (since at least Barry reads the comments :-) Index: cinterf.c =================================================================== RCS file: /cvsroot/xsb/XSB/emu/cinterf.c,v retrieving revision 1.79 retrieving revision 1.80 diff -u -r1.79 -r1.80 --- cinterf.c 5 Apr 2007 17:26:57 -0000 1.79 +++ cinterf.c 6 Apr 2007 11:41:48 -0000 1.80 @@ -1384,7 +1384,6 @@ /* vector in its second argument, and the argc count as the value of */ /* the function. (Will handle a max of 19 args.) */ /* */ -/* For MT engine, synchronization is done in */ /************************************************************************/ DllExport int call_conv xsb_init_string(char *cmdline_param) { @@ -1481,8 +1480,8 @@ /************************************************************************ xsb_command() passes the command (i.e. query with no variables) to - xsb. The command must be put into xsb's register 1 as a term, by the - caller who uses the c2p_* (and perhaps p2p_*) functions. + XSB. The command must be put into XSB's register 1 as a term, by the + caller who uses the c2p_* (and perhaps p2p_*) functions. It returns XSB_SUCCESS if it succeeds, XSB_FAILURE if it fails, in either case resetting register 1 back to a free variable. It returns @@ -1490,9 +1489,7 @@ Note that because this command depends on the user mucking about with registers via c2p_xxx() it is difficult at best to ensure - synchronization with the XSB thread that is being manipulated. Thus, - this routine should not be used if multiple C threads may call - multiple XSB threads -- perhaps not in the MT engine at all? + synchronization with the XSB thread that is being manipulated. ************************************************************************/ @@ -1526,15 +1523,15 @@ } -/************************************************************************/ -/* */ -/* xsb_command_string(char *goal) passes the command (e.g. a query */ -/* which only succeeds or fails) to xsb. The command must a string */ -/* passed in the argument. It returns 0 if it succeeds, 1 if it */ -/* fails, in either case resetting register 1 back to a free */ -/* variable. It returns 2 if there is an error. */ -/* */ -/************************************************************************/ +/************************************************************************ + + xsb_command_string(char *goal) passes the command (e.g. a query which + only succeeds or fails) to XSB. The command must a string passed in + the argument. It returns XSB_SUCCESS if it succeeds, XSB_FAILURE if + it fails, in either case resetting register 1 back to a free + variable. It returns XSB_ERROR if there is an error. + +************************************************************************/ DllExport int call_conv xsb_command_string(CTXTdeclc char *goal) { @@ -1585,15 +1582,19 @@ /************************************************************************ -xsb_query() submits a query to xsb. The query must have been put into + +xsb_query() submits a query to XSB. The query must have been put into register 1 of XSB by the caller, using p2c_* (and perhaps p2p_*). XSB will evaluate the query and return with the variables in the query bound to the first answer. In addition, register 2 will contain a Prolog term of the form ret(V1,V2,..,Vn) with as many Vi's as variables in the original query and with Vi bound to the value for that variable in the first answer. If the query fails, it returns -XSB_FAILURE If the query succeeds, it returns XSB_SUCCESS. If there is -an error, it returns XSB_ERROR. +XSB_FAILURE. If there is an error, it returns XSB_ERROR. If the +query succeeds, it returns XSB_SUCCESS, and the MT engine locks the +XSB_QUERY mutex for the called thread. The mutex will stay locked +until the query is closed, failed out of, or an error is thrown. + ************************************************************************/ DllExport int call_conv xsb_query(CTXTdecl) @@ -1624,17 +1625,23 @@ } /************************************************************************ - xsb_query_string(char *) submits a query to xsb. The string - must be a goal that will be correctly read by xsb's reader, and it - must be terminated with a period (.). Register 2 may be a variable - or it may be a term of the form ret(X1,X2,...,Xn), where n is the - number of variables in the query. The query will be parsed, and an - answer term of the form ret(Y1,Y2,...,Yn) will be constructed where - Y1, .... Yn are the variables in the parsed goal (in left-to-right - order). This answer term is unified with the argument in register 2. - Then the goal is called. If the goal succeeds, xsb_query_string - returns XSB_SUCCESS and the first answer is in register 2. If it - fails, xsb_query_string returns XSB_FAILURE. + + xsb_query_string(char *) submits a query to xsb. The string must be + a goal that will be correctly read by XSB's reader, and it must be + terminated with a period (.). Register 2 may be a variable or it may + be a term of the form ret(X1,X2,...,Xn), where n is the number of + variables in the query. The query will be parsed, and an answer term + of the form ret(Y1,Y2,...,Yn) will be constructed where Y1, .... Yn + are the variables in the parsed goal (in left-to-right order). This + answer term is unified with the argument in register 2. Then the + goal is called. If the goal fails, xsb_query_string() returns + XSB_FAILURE, and if it throws an error, xsb_query_string() returns + XSB_ERROR. If the goal succeeds, xsb_query_string returns + XSB_SUCCESS and the first answer is in register 2. In addition, in + the MT engine the XSB_QUERY mutex is locked for the called thread. + The mutex will stay locked until the query is closed, failed out of, + or an error is thrown. + ************************************************************************/ DllExport int call_conv xsb_query_string(CTXTdeclc char *goal) @@ -1742,15 +1749,18 @@ } /************************************************************************ -xsb_next() causes xsb to return the next answer. If there is another -answer, xsb_next returns XSB_SUCCESS and the variables in goal term -(in xsb register 1) are bound to the answer values. In addition xsb + +xsb_next() causes XSB to return the next answer. If there is another +answer, xsb_next() returns XSB_SUCCESS and the variables in goal term +(in XSB register 1) are bound to the answer values. In addition xsb register 2 will contain a term of the form ret(V1,V2,...,Vn) where the -Vis are the values for the variables for the next answer. xsb_next +Vis are the values for the variables for the next answer. xsb_next() returns XSB_SUCCESS if the next answer is found, XSB_FAILURE if there are no more answers, and XSB_ERROR if an error is encountered. If XSB_FAILURE or XSB_ERROR is returned, then the query is automatically -closed. +closed, and in the MT engine the XSB_QUERY mutex is unlocked for the +called thread. + ************************************************************************/ DllExport int call_conv xsb_next(CTXTdecl) @@ -1829,10 +1839,14 @@ } /************************************************************************ + xsb_close_query_string() closes the current query, so that no more answers will be returned, and another query can be opened. If the query was correctly closed, it resets xsb registers 1 and 2 to be - variables, and returns 0. If there is some error, it returns 2. + variables, and returns XSB_SUCCESS. If there is some error, it + returns XSB_ERROR. In the MT engine, the XSB_QUERY mutex is also + unlocked for the called thread. + ************************************************************************/ DllExport int call_conv xsb_close_query(CTXTdecl) Index: tr_utils.c =================================================================== RCS file: /cvsroot/xsb/XSB/emu/tr_utils.c,v retrieving revision 1.139 retrieving revision 1.140 diff -u -r1.139 -r1.140 --- tr_utils.c 5 Apr 2007 17:26:57 -0000 1.139 +++ tr_utils.c 6 Apr 2007 11:41:48 -0000 1.140 @@ -1326,7 +1326,13 @@ } /*----------------------------------------------------------------------*/ -/* i_trie_intern(_Term,_Root,_Leaf,_Flag,_Check_CPS,_Expand_or_not) */ +/* i_trie_intern(_Term,_Root,_Leaf,_Flag,_Check_CPS,_Expand_or_not) +* +* If called from trie_intern(), we'll need to check to see whether its +* safe to expand -- hence check_cps_flag; if called from +* bulk_trie_intern() we don't need to check, and expand_flag will be +* set to tell us whether we can expand or not. +*/ void trie_intern(CTXTdecl) { @@ -1414,6 +1420,12 @@ /* * This is builtin #162: TRIE_DISPOSE(+ROOT, +LEAF), to dispose a branch * of the trie rooted at Set_ArrayPtr[ROOT]. + * + * If called within a trie_retractall(), the CPS check will already + * have been done: if it isn't safe to reclaim trie_dispose_nr() would + * have been called; otherwise its safe and we don't need to check + * here. If called from within a trie_unintern() (maybe we should get + * the names straight) we do need to check. */ void trie_dispose(CTXTdecl) @@ -1443,6 +1455,11 @@ } /*----------------------------------------------------------------------*/ +/* + * For interned tries, I'm checking whether there is a trie choice + * point with the same root as the the trie that we want to do + * something with. + */ #define is_trie_instruction(cp_inst) \ ((int) cp_inst >= 0x5c && (int) cp_inst < 0x80) \ @@ -1485,6 +1502,9 @@ /*----------------------------------------------------------------------*/ +/* + * The check of whether this trie is safe to delete has already been done. + */ #define DELETED_SET 1 @@ -1511,7 +1531,12 @@ } -/* +/*----------------------------------------------------------------------*/ +/* + +TLS -- 4/07 I'm keeping these in for now, but they may be taken out +when/if the interned tries evolve. + Changes made by Prasad Rao. Jun 20th 2000 The solution for reclaiming the garbage nodes resulting @@ -1647,28 +1672,6 @@ r -> leaves = p; } - -/* - * This is builtin : TRIE_DISPOSE_NR(+ROOT, +LEAF), to - * mark for disposal a branch - * of the trie rooted at Set_ArrayPtr[ROOT]. - */ -void trie_dispose_nr(CTXTdecl) -{ - BTNptr Leaf; - long Rootidx; - - Rootidx = ptoc_int(CTXTc 1); - Leaf = (BTNptr)ptoc_int(CTXTc 2); - switch_to_trie_assert; - SYS_MUTEX_LOCK(MUTEX_TRIE); - insertLeaf(getIGRnode(CTXTc Rootidx), Leaf); - SYS_MUTEX_UNLOCK(MUTEX_TRIE); - safe_delete_branch(Leaf); - switch_from_trie_assert; -} - - void reclaim_uninterned_nr(CTXTdeclc long rootidx) { IGRptr r = getAndRemoveIGRnode(CTXTc rootidx); @@ -1709,6 +1712,31 @@ } /*----------------------------------------------------------------------*/ +/* + * This is builtin : TRIE_DISPOSE_NR(+ROOT, +LEAF), to + * mark for disposal (safe delete) a branch + * of the trie rooted at Set_ArrayPtr[ROOT]. + */ +void trie_dispose_nr(CTXTdecl) +{ + BTNptr Leaf; + long Rootidx; + + Rootidx = ptoc_int(CTXTc 1); + Leaf = (BTNptr)ptoc_int(CTXTc 2); + switch_to_trie_assert; + SYS_MUTEX_LOCK(MUTEX_TRIE); + insertLeaf(getIGRnode(CTXTc Rootidx), Leaf); + SYS_MUTEX_UNLOCK(MUTEX_TRIE); + safe_delete_branch(Leaf); + switch_from_trie_assert; +} + +/*----------------------------------------------------------------------*/ +/* + * This is builtin : TRIE_UNDISPOSE_NR(+ROOT, +LEAF), to + * unmark a safely deleted branch. + */ void trie_undispose(CTXTdeclc long rootIdx, BTNptr leafn) { @@ -1730,10 +1758,15 @@ } } -/*----------------------------------------------------------------------*/ +/*======================================================================*/ -/* TABLE ABOLISHING AND GARBAGE COLLECTING - * +/* + * TABLE ABOLISHING AND GARBAGE COLLECTING + * =========================== + */ + +/*----------------------------------------------------------------------*/ +/* * When a table is abolished, various checks must be made before its * space can be reclaimed. First, the table must be completed, and * second it must be ensured that there are not any trie choice points Index: tries.c =================================================================== RCS file: /cvsroot/xsb/XSB/emu/tries.c,v retrieving revision 1.95 retrieving revision 1.96 diff -u -r1.95 -r1.96 --- tries.c 5 Apr 2007 17:26:57 -0000 1.95 +++ tries.c 6 Apr 2007 11:41:48 -0000 1.96 @@ -1764,10 +1764,14 @@ } /*----------------------------------------------------------------------*/ - /* * For creating interned tries via buitin "trie_intern". + * These differ from the trie inserts used by tables because there may + * be failure continuations pointing into the trie -- here we need to + * take these continuations into account before we hash. Otherwise + * they are identical to their non interned versions. */ + #define one_interned_node_chk_ins(Found,item,TrieType) { \ \ int count = 0; \ |