示例#1
0
文件: glplib1a.c 项目: ecotox/pacfm
/*----------------------------------------------------------------------
-- Copyright (C) 2000, 2001, 2002, 2003, 2004 Andrew Makhorin,
-- Department for Applied Informatics, Moscow Aviation Institute,
-- Moscow, Russia. All rights reserved. E-mail: <*****@*****.**>.
--
-- This file is part of GLPK (GNU Linear Programming Kit).
--
-- GLPK is free software; you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2, or (at your option)
-- any later version.
--
-- GLPK is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
-- License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with GLPK; see the file COPYING. If not, write to the Free
-- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-- 02111-1307, USA.
----------------------------------------------------------------------*/

#include <windows.h>
#include "glplib.h"

static DWORD dwTlsIndex;

#if defined(_MSC_VER)         /* Microsoft Visual C++ */
BOOL APIENTRY DllMain
#elif defined(__BORLANDC__)   /* Borland C++ */
BOOL WINAPI DllEntryPoint
#else
#error Unknown configuration
#endif
(     HINSTANCE hinstDLL,     /* DLL module handle */
      DWORD fdwReason,        /* reason called */
      LPVOID lpvReserved      /* reserved */
)
{     switch (fdwReason)
      {  /* The DLL is loading due to process initialization or a call
            to LoadLibrary. */
         case DLL_PROCESS_ATTACH:
            /* Allocate a TLS index. */
            dwTlsIndex = TlsAlloc();
            if (dwTlsIndex == 0xFFFFFFFF) return FALSE;
            /* Initialize the index for first thread. */
            TlsSetValue(dwTlsIndex, NULL);
#if 0
            /* Initialize GLPK library environment. */
            lib_init_env();
#endif
            break;
         /* The attached process creates a new thread. */
         case DLL_THREAD_ATTACH:
            /* Initialize the TLS index for this thread. */
            TlsSetValue(dwTlsIndex, NULL);
#if 0
            /* Initialize GLPK library environment. */
            lib_init_env();
#endif
            break;
         /* The thread of the attached process terminates. */
         case DLL_THREAD_DETACH:
            /* Free GLPK library environment. */
            lib_free_env();
            break;
         /* The DLL is unloading due to process termination or call to
            FreeLibrary. */
         case DLL_PROCESS_DETACH:
            /* Free GLPK library environment. */
            lib_free_env();
            /* Release the TLS index. */
            TlsFree(dwTlsIndex);
            break;
         default:
            break;
      }
      return TRUE;
}
示例#2
0
BOOL APIENTRY DllMain
(     HINSTANCE hinstDLL,  /* DLL module handle */
      DWORD fdwReason,     /* reason called */
      LPVOID lpvReserved   /* reserved */
)
{     switch (fdwReason)
      {  /* the DLL is loading due to process initialization or a call
            to LoadLibrary */
         case DLL_PROCESS_ATTACH:
            /* allocate a TLS index */
            dwTlsIndex = TlsAlloc();
            if (dwTlsIndex == 0xFFFFFFFF) return FALSE;
            /* initialize the index for first thread */
            TlsSetValue(dwTlsIndex, NULL);
            /* initialize GLPK library environment */
            lib_init_env();
            break;
         /* the attached process creates a new thread */
         case DLL_THREAD_ATTACH:
            /* initialize the TLS index for this thread */
            TlsSetValue(dwTlsIndex, NULL);
            /* initialize GLPK library environment */
            lib_init_env();
            break;
         /* the thread of the attached process terminates */
         case DLL_THREAD_DETACH:
            /* free GLPK library environment */
            lib_free_env();
            break;
         /* the DLL is unloading due to process termination or call to
            FreeLibrary */
         case DLL_PROCESS_DETACH:
            /* free GLPK library environment */
            lib_free_env();
            /* release the TLS index */
            TlsFree(dwTlsIndex);
            break;
         default:
            break;
      }
      return TRUE;
}
示例#3
0
LIBENV *lib_link_env(void)
{     LIBENV *env = lib_get_ptr();
      /* check if the environment has been initialized */
      if (env == NULL)
      {  /* not initialized yet; perform initialization */
         if (lib_init_env() != 0)
         {  /* initialization failed; display an error message */
            fprintf(stderr, "GLPK library initialization failed.\n");
            fflush(stderr);
            /* and abnormally terminate the program */
            abort();
         }
         /* initialization successful; obtain the pointer */
         env = lib_get_ptr();
      }
      return env;
}