Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #1 from mquinson/master
[simgrid.git] / src / xbt / xbt_os_thread.c
index 46a0e7e..f7ed95e 100644 (file)
@@ -2,14 +2,14 @@
 /* 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-2014. The SimGrid Team.
+/* Copyright (c) 2007-2015. 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. */
 
 #if defined(WIN32)
-#elif defined(__MACH__)
+#elif defined(__MACH__) && defined(__APPLE__)
 #include <stdint.h>
 #include <sys/types.h>
 #include <sys/sysctl.h>
 #include <unistd.h>
 #endif
 
-#include "internal_config.h"
+#include "src/internal_config.h"
 #include "xbt/sysdep.h"
 #include "xbt/ex.h"
-#include "xbt/ex_interface.h"   /* We play crude games with exceptions */
-#include "portable.h"
+#include "src/xbt/ex_interface.h"   /* We play crude games with exceptions */
+#include "src/portable.h"
 #include "xbt/xbt_os_time.h"    /* Portable time facilities */
 #include "xbt/xbt_os_thread.h"  /* This module */
-#include "xbt_modinter.h"       /* Initialization/finalization of this module */
+#include "src/xbt_modinter.h"       /* Initialization/finalization of this module */
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_sync_os, xbt,
                                 "Synchronization mechanism (OS-level)");
@@ -111,7 +111,7 @@ void xbt_os_thread_mod_preinit(void)
 
   if ((errcode = pthread_setspecific(xbt_self_thread_key, main_thread)))
     THROWF(system_error, errcode,
-           "pthread_setspecific failed for xbt_self_thread_key");
+           "Impossible to set the SimGrid identity descriptor to the main thread (pthread_setspecific failed)");
   
   __xbt_running_ctx_fetch = _os_thread_get_running_ctx;
   __xbt_ex_terminate = _os_thread_ex_terminate;
@@ -729,6 +729,16 @@ static unsigned long xbt_self_thread_key;
 void xbt_os_thread_mod_preinit(void)
 {
   xbt_self_thread_key = TlsAlloc();
+
+  xbt_os_thread_t main_thread = xbt_new0(s_xbt_os_thread_t, 1);
+  main_thread->name = (char *) "main";
+  main_thread->start_routine = NULL;
+  main_thread->param = NULL;
+
+  if (!TlsSetValue(xbt_self_thread_key, main_thread))
+    THROWF(system_error, (int)GetLastError(),
+           "Impossible to set the SimGrid identity descriptor to the main thread (TlsSetValue() failed)");
+
 }
 
 void xbt_os_thread_mod_postexit(void)