Mercurial > octave
changeset 24538:2b273df71aa0
allow experimenting with thread_local storage
* mk-octave-config-h.sh, oct-conf-post.in.h:
Define OCTAVE_THREAD_LOCAL.
* interpreter.h, interpreter.cc (interpreter::instance):
Tag with OCTAVE_THREAD_LOCAL. Note that error message should be
changed when a thread_local interpreter object is really possible.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 06 Jan 2018 12:23:14 -0500 |
parents | 11729ca6eb81 |
children | 4e2ca22b3cf9 |
files | build-aux/mk-octave-config-h.sh libinterp/corefcn/interpreter.cc libinterp/corefcn/interpreter.h oct-conf-post.in.h |
diffstat | 4 files changed, 24 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/build-aux/mk-octave-config-h.sh Sat Jan 06 13:48:58 2018 -0800 +++ b/build-aux/mk-octave-config-h.sh Sat Jan 06 12:23:14 2018 -0500 @@ -177,6 +177,11 @@ # define OCTAVE_HAVE_F77_INT_TYPE 1 + +# if defined (__cplusplus) && ! defined (OCTAVE_THREAD_LOCAL) +# define OCTAVE_THREAD_LOCAL +# endif + EOF if grep "#define OCTAVE_ENABLE_FLOAT_TRUNCATE 1" $config_h_file > /dev/null; then
--- a/libinterp/corefcn/interpreter.cc Sat Jan 06 13:48:58 2018 -0800 +++ b/libinterp/corefcn/interpreter.cc Sat Jan 06 12:23:14 2018 -0500 @@ -367,9 +367,14 @@ m_history_initialized (false), m_initialized (false) { + // FIXME: When thread_local storage is used by default, this message + // should change to say something like + // + // only one Octave interpreter may be active in any given thread + if (instance) throw std::runtime_error - ("only one Octave interpreter object may be active"); + ("only one Octave interpreter may be active"); instance = this; @@ -529,7 +534,7 @@ octave_interpreter_ready = true; } - interpreter *interpreter::instance = nullptr; + OCTAVE_THREAD_LOCAL interpreter *interpreter::instance = nullptr; interpreter::~interpreter (void) {
--- a/libinterp/corefcn/interpreter.h Sat Jan 06 13:48:58 2018 -0800 +++ b/libinterp/corefcn/interpreter.h Sat Jan 06 12:23:14 2018 -0500 @@ -207,8 +207,14 @@ private: // The interpreter instance; Currently it is only possible to - // have one. - static interpreter *instance; + // have one, so OCTAVE_THREAD_LOCAL will normally be defined to be + // empty. Eventually we would like to allow multiple interpreters + // to be active at once, but they will still be limited to one per + // thread. When that is possible, OCTAVE_THREAD_LOCAL can be + // replaced by the C++ thread_local keyword. For now, use a macro + // to allow experimenting with thread_local storage. + + OCTAVE_THREAD_LOCAL static interpreter *instance; static std::list<std::string> atexit_functions;
--- a/oct-conf-post.in.h Sat Jan 06 13:48:58 2018 -0800 +++ b/oct-conf-post.in.h Sat Jan 06 12:23:14 2018 -0500 @@ -205,6 +205,10 @@ #define OCTAVE_HAVE_F77_INT_TYPE 1 +#if defined (__cplusplus) && ! defined (OCTAVE_THREAD_LOCAL) +# define OCTAVE_THREAD_LOCAL +#endif + /* Tag indicating Octave's autoconf-generated config.h has been included. This symbol is provided because autoconf-generated config.h files do not define a multiple-inclusion guard. See also