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