XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_sync_os, xbt, "Synchronization mechanism (OS-level)");
-/* use named sempahore when sem_init() does not work */
+/* use named semaphore when sem_init() does not work */
#if !HAVE_SEM_INIT
static int next_sem_ID = 0;
static xbt_os_mutex_t next_sem_ID_lock;
main_thread = xbt_new(s_xbt_os_thread_t, 1);
main_thread->name = NULL;
main_thread->detached = 0;
- main_thread->name = (char *) "main";
+ main_thread->name = xbt_strdup("main");
main_thread->param = NULL;
main_thread->start_routine = NULL;
main_thread->extra_data = NULL;
// if ((errcode=pthread_key_delete(xbt_self_thread_key)))
// THROWF(system_error,errcode,"pthread_key_delete failed for xbt_self_thread_key");
+ free(main_thread->name);
free(main_thread);
main_thread = NULL;
thread_mod_inited = 0;
const char *xbt_os_thread_self_name(void)
{
xbt_os_thread_t me = xbt_os_thread_self();
- return me ? me->name : "main";
+ return me ? (const char *)me->name : "main";
}
void xbt_os_thread_join(xbt_os_thread_t thread, void **thread_return)
pthread_exit(retval);
}
-xbt_os_thread_t xbt_os_thread_self(void)
+xbt_os_thread_t xbt_os_thread_self(void )
{
if (!thread_mod_inited)
return NULL;
#else /* damn, no sem_init(). Reimplement it */
xbt_os_mutex_acquire(next_sem_ID_lock);
- res->name = bprintf("/%d", ++next_sem_ID);
+ res->name = bprintf("/sg-%d", ++next_sem_ID);
xbt_os_mutex_release(next_sem_ID_lock);
+ sem_unlink(res->name);
res->ps = sem_open(res->name, O_CREAT, 0644, value);
if ((res->ps == (sem_t *) SEM_FAILED) && (errno == ENAMETOOLONG)) {
/* Old darwins only allow 13 chars. Did you create *that* amount of semaphores? */
res->name[13] = '\0';
+ sem_unlink(res->name);
res->ps = sem_open(res->name, O_CREAT, 0644, value);
}
if (res->ps == (sem_t *) SEM_FAILED)
xbt_free(sem);
}
-void xbt_os_sem_get_value(xbt_os_sem_t sem, int *svalue)
-{
- if (sem_getvalue(&(sem->s), svalue) < 0)
- THROWF(system_error, errno, "sem_getvalue() failed: %s",
- strerror(errno));
-}
-
/** @brief Returns the amount of cores on the current host */
int xbt_os_get_numcores(void) {
#ifdef WIN32