-// Copyright (C) 2006-2012 CEA/DEN, EDF R&D
+// Copyright (C) 2006-2021 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "ThreadPT.hxx"
#include "Exception.hxx"
-#ifdef WNT
+#ifdef WIN32
#include <windows.h>
#define usleep(A) Sleep(A/1000)
#else
using namespace YACS::BASES;
-ThreadPT::ThreadPT(ThreadJob funcPtr, void *stack)
+ThreadPT::ThreadPT()
+{
+}
+
+ThreadPT::ThreadPT(ThreadJob funcPtr, void *stack, size_t stackSize)
+{
+ go(funcPtr,stack,stackSize);
+}
+
+void ThreadPT::go(ThreadJob funcPtr, void *stack, size_t stackSize)
{
int err;
void **stackT=(void **) stack;
- err=pthread_create(&_threadId,0,funcPtr,stackT);
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ if (stackSize > 0)
+ {
+ err = pthread_attr_setstacksize(&attr, stackSize);
+ if (err != 0) throw Exception("Error when setting thread stack size");
+ }
+ err = pthread_create(&_threadId, &attr, funcPtr, stackT);
+ pthread_attr_destroy(&attr);
if(err!=0)throw Exception("Error in thread creation");
}