1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
/*
* Copyright (c) 2001-2002 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 1998-2001 University of Notre Dame.
* All rights reserved.
* Copyright (c) 1994-1998 The Ohio State University.
* All rights reserved.
*
* This file is part of the LAM/MPI software package. For license
* information, see the LICENSE file in the top level directory of the
* LAM/MPI source distribution.
*
* $HEADER$
*
* $Id: lamthreads.c,v 1.3 2003/04/09 17:37:14 brbarret Exp $
*
* Function:
* - LAM interface for threads control in LAM layer
*/
#include <lam_config.h>
#include <lamthreads.h>
/*
* TO-DO: Attribute Interface
*/
/*
* lam_thread_create
*
* FUNCTION: Create a thread
*
* NOTES:
* - Needs attribute argument
*/
int
lam_thread_create(lam_thread_t *new_thread, void *(*start_func)(void *),
void *arg)
{
int ret = 0;
#if LAM_HAVE_POSIX_THREADS
ret = pthread_create(new_thread, NULL, start_func, arg);
#elif LAM_HAVE_SOLARIS_THREADS
ret = thr_create(NULL, 0, start_func, arg, NULL, new_thread);
#else
ret = 1;
#endif
return ret;
}
/*
* lam_thread_exit
*
* Function:
* - terminate calling thread
*
* Notes:
*/
void
lam_thread_exit(void *ret_val)
{
#if LAM_HAVE_POSIX_THREADS
pthread_exit(ret_val);
#elif LAM_HAVE_SOLARIS_THREADS
thr_exit(ret_val);
#endif
}
/*
* lam_thread_join
*
* Function:
* - wait for thread termination
*
* Notes:
*/
int
lam_thread_join(lam_thread_t thread, void **value)
{
int ret;
#if LAM_HAVE_POSIX_THREADS
ret = pthread_join(thread, value);
#elif LAM_HAVE_SOLARIS_THREADS
ret = thr_join(thread, NULL, value);
#else
ret = -1;
#endif
return ret;
}
/*
* lam_thread_self
*
* Function: - get thread specific identifier
* Returns: - thread specific identifier
*/
lam_thread_t
lam_thread_self(void)
{
#if LAM_HAVE_SOLARIS_THREADS
return thr_self();
#elif LAM_HAVE_POSIX_THREADS
return pthread_self();
#else
return -1;
#endif
}
/*
* lam_thread_compare
*
* Function: - compare two thread IDs
* Returns: - 1 if they are the same, 0 otherwise
* - 1 if threading is not enabled (on assumption
* that there is only one thread)
*/
int
lam_thread_compare(lam_thread_t a, lam_thread_t b)
{
#if LAM_HAVE_SOLARIS_THREADS
return (a == b);
#elif LAM_HAVE_POSIX_THREADS
return pthread_equal(a, b);
#else
return (a == b);
#endif
}
|