Skip to content

Commit

Permalink
ADDED: Support engines in single-threaded version
Browse files Browse the repository at this point in the history
This patch revives an old proof-of-concept option to include engines
in the single threaded version.   The code compiles and tests again.
Added Prolog flag `engines` to indicate the system has engine support.
  • Loading branch information
JanWielemaker committed Jan 30, 2025
1 parent 165d7c2 commit b55bb91
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 6 deletions.
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,13 @@ set(SWIPL_TEST_DIRS unprotected core db attvar debug tabling library
xsb/wfs_tests xsb/table_tests xsb/incremental_tests xsb/nonmt_tests
xsb/sub_tests)
if(MULTI_THREADED)
set(SWIPL_TEST_DIRS ${SWIPL_TEST_DIRS} thread thread_wait signals)
list(APPEND SWIPL_TEST_DIRS thread thread_wait signals)
endif()
if(ENGINES)
list(APPEND SWIPL_TEST_DIRS engines)
endif()
if(O_BIGNUM)
set(SWIPL_TEST_DIRS ${SWIPL_TEST_DIRS} rational)
list(APPEND SWIPL_TEST_DIRS rational)
endif()

add_test(NAME swipl:abi-version
Expand Down
1 change: 1 addition & 0 deletions library/prolog_colour.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2255,6 +2255,7 @@
known_flag(conda).
known_flag(dde).
known_flag(emscripten).
known_flag(engines).
known_flag(executable_format).
known_flag(gc_thread).
known_flag(gmp_version).
Expand Down
5 changes: 5 additions & 0 deletions man/overview.doc
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,11 @@ default emulator.
Format of the SWI-Prolog executable, e.g. \const{elf} for when
\file{swipl} is an ELF binary file.

\prologflagitem{engines}{bool}{r}
True if engines are supported. This is always the case on the
multi-threaded versions. Engines may be enabled on single
threaded versions of SWI-Prolog.

\prologflagitem{exit_status}{integer}{r}
Set by halt/1 to its argument, making the exit status available to
hooks registered with at_halt/1.
Expand Down
6 changes: 5 additions & 1 deletion src/os/pl-prologflag.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Author: Jan Wielemaker
E-mail: [email protected]
WWW: http://www.swi-prolog.org
Copyright (c) 2011-2024, University of Amsterdam
Copyright (c) 2011-2025, University of Amsterdam
VU University Amsterdam
CWI, Amsterdam
SWI-Prolog Solutions b.v.
Expand Down Expand Up @@ -1925,6 +1925,7 @@ initPrologFlags(void)
#endif
#ifdef O_PLMT
setPrologFlag("threads", FT_BOOL, !GD->options.nothreads, 0);
setPrologFlag("engines", FT_BOOL, true, 0);
if ( GD->options.xpce >= 0 )
setPrologFlag("xpce", FT_BOOL, GD->options.xpce, 0);
setPrologFlag("system_thread_id", FT_INTEGER|FF_READONLY, (intptr_t)0);
Expand All @@ -1934,6 +1935,9 @@ initPrologFlags(void)
#else
setPrologFlag("threads", FT_BOOL|FF_READONLY, false, 0);
setPrologFlag("gc_thread", FT_BOOL|FF_READONLY, false, PLFLAG_GCTHREAD);
#ifdef O_ENGINES
setPrologFlag("engines", FT_BOOL, true, 0);
#endif
#endif
#ifdef O_DDE
setPrologFlag("dde", FT_BOOL|FF_READONLY, true, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/pl-global.h
Original file line number Diff line number Diff line change
Expand Up @@ -776,12 +776,12 @@ struct PL_local_data
DefinitionChain local_definitions; /* P_THREAD_LOCAL predicates */
int magic; /* PL_THREAD_MAGIC (checking) */
int exit_requested; /* Thread is asked to exit */
struct _PL_thread_info_t *creator; /* Thread that created me */
uint64_t creator_seq_id; /* Seq id of creater */
#ifdef O_PLMT
simpleMutex scan_lock; /* Hold for asynchronous scans */
thread_wait_for *waiting_for; /* thread_wait/2 info */
alert_channel alert; /* How to alert the thread */
struct _PL_thread_info_t *creator; /* Thread that created me */
uint64_t creator_seq_id; /* Seq id of creater */
double child_cputime; /* Time of completed children */
uint64_t child_inferences; /* Inferences in children */
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/pl-incl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2955,6 +2955,10 @@ static inline int __ptr_to_bool(const intptr_t ptr) { return ptr != 0; }
#define WEAK_TRY_CALL_VOID(Name, ...) \
(WEAK_FUNC(Name) != NULL ? WEAK_FUNC(Name)(__VA_ARGS__) : (void)0)

#if defined(O_ENGINES) && !defined(O_PLMT)
extern struct PL_local_data *PL_current_engine_ptr;
#endif

#include "pl-util.h" /* (Debug) utilities */
#include "pl-alloc.h" /* Allocation primitives */
#include "pl-init.h" /* Declarations needed by pl-init.c */
Expand Down
2 changes: 2 additions & 0 deletions src/pl-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,7 @@ dummy_handler(int sig)
}
#endif

#ifdef O_PLMT
static double
halt_grace_time(void)
{ GET_LD
Expand All @@ -1125,6 +1126,7 @@ halt_grace_time(void)

return t;
}
#endif

int
exitPrologThreads(void)
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion tests/test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Author: Jan Wielemaker and Anjo Anjewierden
E-mail: [email protected]
WWW: http://www.swi-prolog.org
Copyright (c) 1996-2023, University of Amsterdam
Copyright (c) 1996-2025, University of Amsterdam
VU University Amsterdam
CWI, Amsterdam
SWI-Prolog Solutions b.v.
Expand Down Expand Up @@ -1944,6 +1944,8 @@
wide_character_types.
testset(thread) :-
current_prolog_flag(threads, true).
testset(engines) :-
current_prolog_flag(engines, true).
testset(mutex) :-
current_prolog_flag(threads, true).

Expand Down

0 comments on commit b55bb91

Please sign in to comment.