Changeset 25fe907 in git for Singular/iplib.cc


Ignore:
Timestamp:
Jan 24, 2019, 1:07:07 PM (5 years ago)
Author:
Reimer Behrends <behrends@…>
Branches:
(u'spielwiese', 'd0474371d8c5d8068ab70bfb42719c97936b18a6')
Children:
a3f0feac28fd347ce5b5d091108f9128d7b13554
Parents:
d0c48800963359deb121c3d103d17df80ba21b8e
Message:
Necessary changes for multi-threading.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/iplib.cc

    rd0c488 r25fe907  
    6060extern int yylp_errno;
    6161extern int yylplineno;
    62 extern char *yylp_errlist[];
     62extern const char *yylp_errlist[];
    6363void print_init();
    6464libstackv library_stack;
     
    10881088/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
    10891089#ifdef HAVE_DYNAMIC_LOADING
    1090 BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
     1090#include <map>
     1091#include <string>
     1092#include <pthread.h>
     1093
     1094STATIC_VAR std::map<std::string, void *> *dyn_modules;
     1095
     1096bool registered_dyn_module(char *fullname) {
     1097  if (dyn_modules == NULL)
     1098    return false;
     1099  std::string fname = fullname;
     1100  return !(dyn_modules->count(fname));
     1101}
     1102
     1103void register_dyn_module(char *fullname, void * handle) {
     1104  std::string fname = fullname;
     1105  if (dyn_modules == NULL)
     1106    dyn_modules = new std::map<std::string, void *>();
     1107  dyn_modules->insert(std::pair<std::string, void *>(fname, handle));
     1108}
     1109
     1110void close_all_dyn_modules() {
     1111  for (std::map<std::string, void *>::iterator it = dyn_modules->begin();
     1112       it != dyn_modules->end();
     1113       it++)
     1114  {
     1115    dynl_close(it->second);
     1116  }
     1117  delete dyn_modules;
     1118  dyn_modules = NULL;
     1119}
     1120BOOLEAN load_modules_aux(const char *newlib, char *fullname, BOOLEAN autoexport)
    10911121{
    10921122#ifdef HAVE_STATIC
     
    11431173  }
    11441174  IDPACKAGE(pl)->language = LANG_C;
    1145   if (dynl_check_opened(FullName))
     1175  if (registered_dyn_module(FullName))
    11461176  {
    11471177    if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as C library", fullname);
     
    11781208      currPack->loaded=1;
    11791209      currPack=s; /* reset currPack to previous */
     1210      register_dyn_module(fullname, IDPACKAGE(pl)->handle);
    11801211      RET=FALSE;
    11811212    }
     
    11921223  return RET;
    11931224#endif /*STATIC */
     1225}
     1226
     1227BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport) {
     1228  GLOBAL_VAR static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
     1229  pthread_mutex_lock(&mutex);
     1230  BOOLEAN r = load_modules_aux(newlib, fullname, autoexport);
     1231  pthread_mutex_unlock(&mutex);
     1232  return r;
    11941233}
    11951234#endif /* HAVE_DYNAMIC_LOADING */
Note: See TracChangeset for help on using the changeset viewer.