Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
when parallel ctests are performed, using the default tracing filename may cause...
[simgrid.git] / src / xbt / xbt_os_thread.c
index 2e9e91f..93fee90 100644 (file)
@@ -2,13 +2,13 @@
 /* Used in RL to get win/lin portability, and in SG when CONTEXT_THREAD     */
 /* in SG, when using CONTEXT_UCONTEXT, xbt_os_thread_stub is used instead   */
 
-/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2007-2013. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "gras_config.h"
+#include "internal_config.h"
 #include "xbt/sysdep.h"
 #include "xbt/ex.h"
 #include "xbt/ex_interface.h"   /* We play crude games with exceptions */
@@ -194,8 +194,17 @@ xbt_os_thread_t xbt_os_thread_create(const char *name,
 
 void xbt_os_thread_setstacksize(int stack_size)
 {
+  size_t def=0;
+  if(stack_size<0)xbt_die("stack size is negative, maybe it exceeds MAX_INT?\n");
   pthread_attr_init(&attr);
-  pthread_attr_setstacksize (&attr, stack_size);
+  pthread_attr_getstacksize (&attr, &def);
+  int res = pthread_attr_setstacksize (&attr, stack_size);
+  if ( res!=0 ) {
+    if(res==EINVAL)XBT_WARN("Thread stack size is either < PTHREAD_STACK_MIN, > the max limit of the system, or perhaps not a multiple of PTHREAD_STACK_MIN - The parameter was ignored");
+    else XBT_WARN("unknown error in pthread stacksize setting");
+
+    pthread_attr_setstacksize (&attr, def);
+  }
   thread_attr_inited=1;
 }
 
@@ -321,7 +330,7 @@ void xbt_os_mutex_timedacquire(xbt_os_mutex_t mutex, double delay)
       THROWF(timeout_error, 0, "mutex %p not ready", mutex);
     default:
       THROWF(system_error, errcode,
-             "xbt_mutex_timedacquire(%p) failed: %s", mutex,
+             "xbt_os_mutex_timedacquire(%p) failed: %s", mutex,
              strerror(errcode));
     }
 
@@ -722,9 +731,9 @@ xbt_os_thread_t xbt_os_thread_create(const char *name,
   return t;
 }
 
-void xbt_os_thread_setstacksize(int stack_size)
+void xbt_os_thread_setstacksize(int size)
 {
-  stack_size=stack_size;
+  stack_size = size;
 }
 
 const char *xbt_os_thread_name(xbt_os_thread_t t)
@@ -1225,7 +1234,8 @@ void xbt_os_thread_set_extra_data(void *data)
 
 void *xbt_os_thread_get_extra_data(void)
 {
-  return xbt_os_thread_self()->extra_data;
+  xbt_os_thread_t self = xbt_os_thread_self();
+  return self? self->extra_data : NULL;
 }
 
 xbt_os_rmutex_t xbt_os_rmutex_init(void)