Salome HOME
Small fixes in tests.
[modules/yacs.git] / src / bases / ThreadPT.cxx
index 7e6133cc4fc4d446f7849af9f0d02c0bf9d4dd51..352c626a47427a2d15b7f06f34df207b0ac06bf1 100644 (file)
@@ -1,9 +1,9 @@
-// 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
@@ -19,7 +19,7 @@
 
 #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");
 }