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
|
/*1:*/
#line 9 "./sthread.cweb"
#include <cstring>
#include "sthread.h"
#ifdef HAVE_PTHREAD
namespace sthread{
template<>
int thread_group<posix> ::max_parallel_threads= 2;
template<>
int detach_thread_group<posix> ::max_parallel_threads= 2;
/*2:*/
#line 32 "./sthread.cweb"
/*3:*/
#line 41 "./sthread.cweb"
void*posix_thread_function(void*c);
template<>
void thread_traits<posix> ::run(_Ctype*c)
{
pthread_create(&(c->getThreadIden()),NULL,posix_thread_function,(void*)c);
}
void*posix_detach_thread_function(void*c);
template<>
void thread_traits<posix> ::detach_run(_Dtype*c)
{
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
pthread_create(&(c->getThreadIden()),&attr,posix_detach_thread_function,(void*)c);
pthread_attr_destroy(&attr);
}
template<>
void thread_traits<posix> ::exit()
{
pthread_exit(NULL);
}
template<>
void thread_traits<posix> ::join(_Ctype*c)
{
pthread_join(c->getThreadIden(),NULL);
}
/*:3*/
#line 33 "./sthread.cweb"
;
/*4:*/
#line 75 "./sthread.cweb"
template<>
void mutex_traits<posix> ::init(pthread_mutex_t&m)
{
pthread_mutex_init(&m,NULL);
}
template<>
void mutex_traits<posix> ::lock(pthread_mutex_t&m)
{
pthread_mutex_lock(&m);
}
template<>
void mutex_traits<posix> ::unlock(pthread_mutex_t&m)
{
pthread_mutex_unlock(&m);
}
/*:4*/
#line 34 "./sthread.cweb"
;
/*5:*/
#line 95 "./sthread.cweb"
template<>
void cond_traits<posix> ::init(_Tcond&cond)
{
pthread_cond_init(&cond,NULL);
}
template<>
void cond_traits<posix> ::broadcast(_Tcond&cond)
{
pthread_cond_broadcast(&cond);
}
template<>
void cond_traits<posix> ::wait(_Tcond&cond,_Tmutex&mutex)
{
pthread_cond_wait(&cond,&mutex);
}
template<>
void cond_traits<posix> ::destroy(_Tcond&cond)
{
pthread_cond_destroy(&cond);
}
/*:5*/
#line 35 "./sthread.cweb"
;
/*6:*/
#line 124 "./sthread.cweb"
static posix_synchro::mutex_map_t posix_mm;
PosixSynchro::PosixSynchro(const void*c,const char*id)
:posix_synchro(c,id,posix_mm){}
/*:6*/
#line 36 "./sthread.cweb"
;
/*7:*/
#line 132 "./sthread.cweb"
void*posix_thread_function(void*c)
{
thread_traits<posix> ::_Ctype*ct=
(thread_traits<posix> ::_Ctype*)c;
try{
ct->operator()();
}catch(...){
ct->exit();
}
return NULL;
}
/*:7*/
#line 37 "./sthread.cweb"
;
/*8:*/
#line 146 "./sthread.cweb"
void*posix_detach_thread_function(void*c)
{
thread_traits<posix> ::_Dtype*ct=
(thread_traits<posix> ::_Dtype*)c;
condition_counter<posix> *counter= ct->counter;
try{
ct->operator()();
}catch(...){
ct->exit();
}
if(counter)
counter->decrease();
return NULL;
}
/*:8*/
#line 38 "./sthread.cweb"
;
/*:2*/
#line 19 "./sthread.cweb"
;
}
#else
namespace sthread{
template<>
int thread_group<empty> ::max_parallel_threads= 1;
template<>
int detach_thread_group<empty> ::max_parallel_threads= 1;
/*9:*/
#line 167 "./sthread.cweb"
template<>
void thread_traits<empty> ::run(_Ctype*c)
{
c->operator()();
}
template<>
void thread_traits<empty> ::detach_run(_Dtype*c)
{
c->operator()();
}
template<>
void thread_traits<empty> ::exit()
{
}
template<>
void thread_traits<empty> ::join(_Ctype*c)
{
}
template<>
void mutex_traits<empty> ::init(Empty&m)
{
}
template<>
void mutex_traits<empty> ::lock(Empty&m)
{
}
template<>
void mutex_traits<empty> ::unlock(Empty&m)
{
}
template<>
void cond_traits<empty> ::init(_Tcond&cond)
{
}
template<>
void cond_traits<empty> ::broadcast(_Tcond&cond)
{
}
template<>
void cond_traits<empty> ::wait(_Tcond&cond,_Tmutex&mutex)
{
}
template<>
void cond_traits<empty> ::destroy(_Tcond&cond)
{
}
/*:9*/
#line 27 "./sthread.cweb"
;
}
#endif
/*:1*/
|