mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-15 16:18:22 +01:00
new threading mutex patch from tmishima@jcity.maeda.co.jp
git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/trunk@7705 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
parent
9969a86f94
commit
21898660f9
@ -3,6 +3,8 @@
|
||||
|
||||
#include "IPhreeqc.hpp" // IPhreeqc
|
||||
#include "Phreeqc.h" // Phreeqc
|
||||
#define _INC_PHREEQC_H
|
||||
#include "thread.h"
|
||||
|
||||
#include "Debug.h" // ASSERT
|
||||
#include "ErrorReporter.hxx" // CErrorReporter
|
||||
@ -41,7 +43,7 @@ IPhreeqc::IPhreeqc(void)
|
||||
, PhreeqcPtr(0)
|
||||
, input_file(0)
|
||||
, database_file(0)
|
||||
, Index(IPhreeqc::InstancesIndex++)
|
||||
/* , Index(IPhreeqc::InstancesIndex++) */
|
||||
{
|
||||
char buffer[80];
|
||||
|
||||
@ -53,8 +55,11 @@ IPhreeqc::IPhreeqc(void)
|
||||
ASSERT(this->PhreeqcPtr->phast == 0);
|
||||
this->UnLoadDatabase();
|
||||
|
||||
mutex_lock(&map_lock);
|
||||
this->Index = IPhreeqc::InstancesIndex++;
|
||||
std::map<size_t, IPhreeqc*>::value_type instance(this->Index, this);
|
||||
std::pair<std::map<size_t, IPhreeqc*>::iterator, bool> pr = IPhreeqc::Instances.insert(instance);
|
||||
mutex_unlock(&map_lock);
|
||||
|
||||
::sprintf(buffer, PUNCH_FILENAME_FORMAT, this->Index);
|
||||
this->SelectedOutputFileName = buffer;
|
||||
@ -83,11 +88,13 @@ IPhreeqc::~IPhreeqc(void)
|
||||
delete this->WarningReporter;
|
||||
delete this->ErrorReporter;
|
||||
|
||||
mutex_lock(&map_lock);
|
||||
std::map<size_t, IPhreeqc*>::iterator it = IPhreeqc::Instances.find(this->Index);
|
||||
if (it != IPhreeqc::Instances.end())
|
||||
{
|
||||
IPhreeqc::Instances.erase(it);
|
||||
}
|
||||
mutex_unlock(&map_lock);
|
||||
}
|
||||
|
||||
VRESULT IPhreeqc::AccumulateLine(const char *line)
|
||||
|
||||
@ -885,7 +885,7 @@ protected:
|
||||
friend class IPhreeqcLib;
|
||||
static std::map<size_t, IPhreeqc*> Instances;
|
||||
static size_t InstancesIndex;
|
||||
const size_t Index;
|
||||
size_t Index;
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
/* reset warning C4251 */
|
||||
|
||||
@ -904,9 +904,7 @@ IPhreeqcLib::CreateIPhreeqc(void)
|
||||
IPhreeqc* IPhreeqcPtr;
|
||||
try
|
||||
{
|
||||
mutex_lock(&map_lock);
|
||||
IPhreeqcPtr = new IPhreeqc;
|
||||
mutex_unlock(&map_lock);
|
||||
n = (int) IPhreeqcPtr->Index;
|
||||
}
|
||||
catch(...)
|
||||
@ -924,9 +922,7 @@ IPhreeqcLib::DestroyIPhreeqc(int id)
|
||||
{
|
||||
if (IPhreeqc *ptr = IPhreeqcLib::GetInstance(id))
|
||||
{
|
||||
mutex_lock(&map_lock);
|
||||
delete ptr;
|
||||
mutex_unlock(&map_lock);
|
||||
retval = IPQ_OK;
|
||||
}
|
||||
}
|
||||
@ -961,4 +957,4 @@ IPhreeqcLib::GetInstance(int id)
|
||||
// {
|
||||
// delete ip_list[i];
|
||||
// }
|
||||
//}
|
||||
//}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user