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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
/*
* $Id$
*/
/************************************************************************
* *
* Copyright (C) 2002 *
* Internet2 *
* All Rights Reserved *
* *
************************************************************************/
/*
* File: Pthread.c
*
* Author: Jeff Boote
* Internet2
*
* Date: Tue Apr 23 14:01:41 2002
*
* Description:
*
*
* Based on code from UCAR DCS tools. Copyright information
* from UCAR follows:
*
* Copyright 2012, University Corporation for Atmospheric Research.
*
* This software may be used, subject to the terms of OSI's BSD-2 Clause
* License located at http://www.opensource.org/licenses/bsd-license.php/
*/
#include "Pthread.h"
#include <stdio.h>
#ifdef I2THREADS_ENABLE
int I2ThreadCreate(
I2Thread_T *thread,
I2ThreadAttr_T *attr,
void *(*start)(void *),
void *arg,
const char *msg
) {
int rc;
rc = pthread_create(thread, attr, start, arg);
#ifdef DEBUG
fprintf(
stderr, "Created thread (%lx), rc=%d, msg=%s\n",
(unsigned long) *thread, rc, msg
);
#endif
if (rc < 0) return(-1);
return(0);
}
int I2ThreadJoin(
I2Thread_T thread,
void **retval,
const char *msg
) {
int rc;
rc = pthread_join(thread, retval);
#ifdef DEBUG
fprintf(
stderr, "Joined thread (%lx), rc=%d, msg=%s\n",
(unsigned long) thread, rc, msg
);
#endif
return(0);
}
I2Thread_T I2ThreadSelf()
{
return(pthread_self());
}
int I2ThreadMutexInit(
I2ThreadMutex_T *mutex,
I2ThreadMutexattr_T *attr
) {
return(pthread_mutex_init(mutex, attr));
}
int I2ThreadMutexLock(
I2ThreadMutex_T *mutex
) {
return(pthread_mutex_lock(mutex));
}
int I2ThreadMutexUnlock(
I2ThreadMutex_T *mutex
) {
return(pthread_mutex_unlock(mutex));
}
int I2ThreadAttrInit(
I2ThreadAttr_T *attr
) {
return(pthread_attr_init(attr));
}
int I2ThreadAttrSetDetatchState(
I2ThreadAttr_T *attr,
int detach
) {
return(pthread_attr_setdetachstate(attr, detach));
}
int I2ThreadCondDestroy(
I2ThreadCond_T *cond
) {
return(pthread_cond_destroy(cond));
}
int I2ThreadMutexDestroy(
I2ThreadMutex_T *mutex
) {
return(pthread_mutex_destroy(mutex));
}
int I2ThreadCondInit(
I2ThreadCond_T *cond,
I2ThreadCondattr_T *attr
) {
return(pthread_cond_init(cond, attr));
}
int I2ThreadCondSignal(
I2ThreadCond_T *cond
) {
return(pthread_cond_signal(cond));
}
int I2ThreadCondWait(
I2ThreadCond_T *cond,
I2ThreadMutex_T *mutex
) {
return(pthread_cond_wait(cond, mutex));
}
#else /* I2THREADS_ENABLE */
/*
* Hopefully we don't need these - but if macro versions don't work
* they are still here...
*/
#if defined(NOT) && NOT
int I2ThreadCreate(
I2Thread_T *thread,
I2ThreadAttr_T *attr,
void *(*start)(void *),
void *arg,
const char *msg
) {
*thread = (I2Thread_T)NULL;
start(arg);
return(0);
}
int I2ThreadJoin(
I2Thread_T thread,
void **retval,
const char *msg
) {
return(0);
}
I2Thread_T I2ThreadSelf()
{
return(0);
}
int I2ThreadMutexInit(
I2ThreadMutex_T *mutex,
I2ThreadMutexattr_T *attr
) {
return(0);
}
int I2ThreadMutexLock(
I2ThreadMutex_T *mutex
) {
return(0);
}
int I2ThreadMutexUnlock(
I2ThreadMutex_T *mutex
) {
return(0);
}
int I2ThreadAttrInit(
I2ThreadAttr_T *attr
) {
return(0);
}
int I2ThreadAttrSetDetatchState(
I2ThreadAttr_T *attr,
int detach
) {
return(0);
}
int I2ThreadCondDestroy(
I2ThreadCond_T *cond
) {
return(0);
}
int I2ThreadMutexDestroy(
I2ThreadMutex_T *mutex
) {
return(0);
}
int I2ThreadCondInit(
I2ThreadCond_T *cond,
I2ThreadCondattr_T *attr
) {
return(0);
}
int I2ThreadCondSignal(
I2ThreadCond_T *cond
) {
return(0);
}
int I2ThreadCondWait(
I2ThreadCond_T *cond,
I2ThreadMutex_T *mutex
) {
return(0);
}
#endif /* NOT */
#endif
|