Skip to content

Commit c587f38

Browse files
author
Sebastiano Merlino
committed
Solved some compatibility problems in pthread_t usage
1 parent 918dd33 commit c587f38

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/webserver.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,22 @@ struct modded_request
187187

188188
}
189189

190+
struct pthread_t_comparator
191+
{
192+
bool operator()(const pthread_t& t1, const pthread_t& t2) const
193+
{
194+
return pthread_equal(t1, t2);
195+
}
196+
};
197+
190198
struct cache_entry
191199
{
192200
long ts;
193201
int validity;
194202
details::http_response_ptr response;
195203
pthread_rwlock_t elem_guard;
196204
pthread_mutex_t lock_guard;
197-
set<pthread_t> lockers;
205+
set<pthread_t, pthread_t_comparator> lockers;
198206

199207
cache_entry():
200208
ts(-1),
@@ -241,17 +249,18 @@ struct cache_entry
241249
void lock(bool write = false)
242250
{
243251
pthread_mutex_lock(&lock_guard);
244-
if(!lockers.count(pthread_self()))
252+
pthread_t tid = pthread_self();
253+
if(!lockers.count(tid))
245254
{
246255
if(write)
247256
{
248-
lockers.insert(pthread_self());
257+
lockers.insert(tid);
249258
pthread_mutex_unlock(&lock_guard);
250259
pthread_rwlock_wrlock(&elem_guard);
251260
}
252261
else
253262
{
254-
lockers.insert(pthread_self());
263+
lockers.insert(tid);
255264
pthread_mutex_unlock(&lock_guard);
256265
pthread_rwlock_rdlock(&elem_guard);
257266
}
@@ -263,10 +272,13 @@ struct cache_entry
263272
void unlock()
264273
{
265274
pthread_mutex_lock(&lock_guard);
266-
if(lockers.count(pthread_self()))
267275
{
268-
lockers.erase(pthread_self());
269-
pthread_rwlock_unlock(&elem_guard);
276+
pthread_t tid = pthread_self();
277+
if(lockers.count(tid))
278+
{
279+
lockers.erase(tid);
280+
pthread_rwlock_unlock(&elem_guard);
281+
}
270282
}
271283
pthread_mutex_unlock(&lock_guard);
272284
}

0 commit comments

Comments
 (0)