diff --git a/src/frontend/dvec.c b/src/frontend/dvec.c index 5bc7b5df6..41177df01 100644 --- a/src/frontend/dvec.c +++ b/src/frontend/dvec.c @@ -1,6 +1,51 @@ + + +#if defined(__MINGW32__) || defined(_MSC_VER) +#include +#endif + #include "ngspice/ngspice.h" #include "ngspice/dvec.h" +/*Use Windows threads if on W32 without pthreads*/ +#ifndef HAVE_LIBPTHREAD + +#if defined(__MINGW32__) || defined(_MSC_VER) +//#if defined(_MSC_VER) +#ifdef SRW +#define mutex_lock(a) AcquireSRWLockExclusive(a) +#define mutex_unlock(a) ReleaseSRWLockExclusive(a) +typedef SRWLOCK mutexType; +#else +#define mutex_lock(a) EnterCriticalSection(a) +#define mutex_unlock(a) LeaveCriticalSection(a) +typedef CRITICAL_SECTION mutexType; +#endif +#define thread_self() GetCurrentThread() +#define threadid_self() GetCurrentThreadId() +typedef HANDLE threadId_t; +#define WIN_THREADS +#define THREADS + +#endif + +#else + +#include +#define mutex_lock(a) pthread_mutex_lock(a) +#define mutex_unlock(a) pthread_mutex_unlock(a) +#define thread_self() pthread_self() +#define threadid_self() 0 //FIXME t.b.d. +typedef pthread_mutex_t mutexType; +typedef pthread_t threadId_t; +#define THREADS +static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; +static bool cont_condition; + +#endif + +extern mutexType vecreallocMutex; + struct dvec *dvec_alloc(/* NOT const -- assigned to char */ char *name, int type, short flags, int length, void *storage) @@ -86,17 +131,24 @@ void dvec_realloc(struct dvec *v, int length, void *storage) v->v_alloc_length = length; } /* end of function dvec_realloc */ - +/* called from plotAddReal(Complex)Value, to increase + storage for result vectors. Locking and unlocking + is done by API functions ng_veclock(), ng_vecunlock(). */ void dvec_extend(struct dvec *v, int length) { +#if defined SHARED_MODULE + mutex_lock(&vecreallocMutex); +#endif if (isreal(v)) { v->v_realdata = TREALLOC(double, v->v_realdata, length); } else { v->v_compdata = TREALLOC(ngcomplex_t, v->v_compdata, length); } - v->v_alloc_length = length; +#if defined SHARED_MODULE + mutex_unlock(&vecreallocMutex); +#endif } /* end of function dvec_extend */ diff --git a/src/sharedspice.c b/src/sharedspice.c index 2685e3686..10145c845 100644 --- a/src/sharedspice.c +++ b/src/sharedspice.c @@ -396,6 +396,7 @@ unsigned int main_id, ng_id, command_id; mutexType triggerMutex; mutexType allocMutex; mutexType fputsMutex; +mutexType vecreallocMutex; #endif /* initialization status */