2003-12-22 16:29:21 +00:00
|
|
|
/*
|
2005-11-05 19:57:48 +00:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 20:09:25 +00:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 12:43:37 +00:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2010-08-05 16:25:32 +00:00
|
|
|
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
|
2004-11-22 01:38:40 +00:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-01-07 18:39:35 +00:00
|
|
|
* $HEADER$
|
2003-12-22 16:29:21 +00:00
|
|
|
*/
|
2004-01-07 18:39:35 +00:00
|
|
|
|
2006-02-12 01:33:29 +00:00
|
|
|
#include "opal_config.h"
|
2004-08-18 23:24:27 +00:00
|
|
|
|
2005-08-15 11:02:01 +00:00
|
|
|
#include "opal/threads/threads.h"
|
2006-02-12 01:33:29 +00:00
|
|
|
#include "opal/constants.h"
|
2003-12-22 16:29:21 +00:00
|
|
|
|
2010-08-05 16:25:32 +00:00
|
|
|
bool opal_debug_threads = false;
|
2004-03-03 16:10:26 +00:00
|
|
|
|
2005-07-03 22:45:48 +00:00
|
|
|
static void opal_thread_construct(opal_thread_t *t);
|
2004-11-15 20:03:14 +00:00
|
|
|
|
2005-07-03 22:45:48 +00:00
|
|
|
OBJ_CLASS_INSTANCE(opal_thread_t,
|
2005-07-03 16:06:07 +00:00
|
|
|
opal_object_t,
|
2005-07-03 22:45:48 +00:00
|
|
|
opal_thread_construct, NULL);
|
2004-11-15 20:03:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Constructor
|
|
|
|
*/
|
2005-07-03 22:45:48 +00:00
|
|
|
static void opal_thread_construct(opal_thread_t *t)
|
2004-03-03 16:10:26 +00:00
|
|
|
{
|
|
|
|
t->t_run = 0;
|
2013-09-06 19:03:19 +00:00
|
|
|
#if OPAL_HAVE_POSIX_THREADS
|
2004-03-18 14:17:23 +00:00
|
|
|
t->t_handle = (pthread_t) -1;
|
2004-08-18 23:24:27 +00:00
|
|
|
#endif
|
2004-03-03 16:10:26 +00:00
|
|
|
}
|
2004-08-18 23:24:27 +00:00
|
|
|
|
2013-09-06 19:03:19 +00:00
|
|
|
#if OPAL_HAVE_POSIX_THREADS
|
2004-03-03 16:10:26 +00:00
|
|
|
|
2004-11-15 20:03:14 +00:00
|
|
|
/************************************************************************
|
|
|
|
* POSIX threads
|
|
|
|
************************************************************************/
|
2004-03-03 16:10:26 +00:00
|
|
|
|
2005-07-03 22:45:48 +00:00
|
|
|
int opal_thread_start(opal_thread_t *t)
|
2004-03-03 16:10:26 +00:00
|
|
|
{
|
|
|
|
int rc;
|
2004-08-18 23:24:27 +00:00
|
|
|
|
2009-05-06 20:11:28 +00:00
|
|
|
if (OPAL_ENABLE_DEBUG) {
|
2004-08-18 23:24:27 +00:00
|
|
|
if (NULL == t->t_run || t->t_handle != (pthread_t) -1) {
|
2006-02-12 01:33:29 +00:00
|
|
|
return OPAL_ERR_BAD_PARAM;
|
2004-08-18 23:24:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-18 15:41:40 +00:00
|
|
|
rc = pthread_create(&t->t_handle, NULL, (void*(*)(void*)) t->t_run, t);
|
2004-08-18 23:24:27 +00:00
|
|
|
|
2006-02-12 01:33:29 +00:00
|
|
|
return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR;
|
2004-03-03 16:10:26 +00:00
|
|
|
}
|
|
|
|
|
2004-08-18 23:24:27 +00:00
|
|
|
|
2005-07-03 22:45:48 +00:00
|
|
|
int opal_thread_join(opal_thread_t *t, void **thr_return)
|
2004-03-03 16:10:26 +00:00
|
|
|
{
|
|
|
|
int rc = pthread_join(t->t_handle, thr_return);
|
2007-05-21 16:06:14 +00:00
|
|
|
t->t_handle = (pthread_t) -1;
|
2006-02-12 01:33:29 +00:00
|
|
|
return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR;
|
2004-08-18 23:24:27 +00:00
|
|
|
}
|
|
|
|
|
2004-11-15 20:03:14 +00:00
|
|
|
|
2005-07-03 22:45:48 +00:00
|
|
|
bool opal_thread_self_compare(opal_thread_t *t)
|
2004-08-28 01:15:19 +00:00
|
|
|
{
|
|
|
|
return t->t_handle == pthread_self();
|
|
|
|
}
|
2004-08-18 23:24:27 +00:00
|
|
|
|
2004-11-15 20:03:14 +00:00
|
|
|
|
2005-07-03 22:45:48 +00:00
|
|
|
opal_thread_t *opal_thread_get_self(void)
|
2004-11-15 20:03:14 +00:00
|
|
|
{
|
2005-07-03 22:45:48 +00:00
|
|
|
opal_thread_t *t = OBJ_NEW(opal_thread_t);
|
2004-11-15 20:03:14 +00:00
|
|
|
t->t_handle = pthread_self();
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2010-11-08 19:06:10 +00:00
|
|
|
void opal_thread_kill(opal_thread_t *t, int sig)
|
|
|
|
{
|
|
|
|
pthread_kill(t->t_handle, sig);
|
|
|
|
}
|
|
|
|
|
2004-11-15 20:03:14 +00:00
|
|
|
|
2004-11-16 12:36:56 +00:00
|
|
|
#else
|
|
|
|
|
2004-11-15 20:03:14 +00:00
|
|
|
/************************************************************************
|
|
|
|
* No thread support
|
|
|
|
************************************************************************/
|
|
|
|
|
2005-07-03 22:45:48 +00:00
|
|
|
int opal_thread_start(opal_thread_t *t)
|
2004-08-18 23:24:27 +00:00
|
|
|
{
|
2006-02-12 01:33:29 +00:00
|
|
|
return OPAL_ERROR;
|
2004-03-03 16:10:26 +00:00
|
|
|
}
|
|
|
|
|
2004-08-18 23:24:27 +00:00
|
|
|
|
2005-07-03 22:45:48 +00:00
|
|
|
int opal_thread_join(opal_thread_t *t, void **thr_return)
|
2004-08-18 23:24:27 +00:00
|
|
|
{
|
2006-02-12 01:33:29 +00:00
|
|
|
return OPAL_ERROR;
|
2004-08-18 23:24:27 +00:00
|
|
|
}
|
|
|
|
|
2004-11-15 20:03:14 +00:00
|
|
|
|
2005-07-03 22:45:48 +00:00
|
|
|
bool opal_thread_self_compare(opal_thread_t *t)
|
2004-08-28 01:15:19 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-07-03 22:45:48 +00:00
|
|
|
opal_thread_t *opal_thread_get_self(void)
|
2004-11-15 20:03:14 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-08 19:06:10 +00:00
|
|
|
void opal_thread_kill(opal_thread_t *t, int sig)
|
|
|
|
{
|
|
|
|
}
|
2004-11-15 20:03:14 +00:00
|
|
|
|
2004-08-18 23:24:27 +00:00
|
|
|
#endif
|