Skip to content

Commit 30b949c

Browse files
committed
Replace trans_proto_stats.lock with std::mutex and std::lock_guard
1 parent a75b42d commit 30b949c

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

contrib/udp2/ic_common/udp2/ic_udp2.cpp

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,11 @@ CursorICHistoryTable::prune(uint32 icId) {
293293
}
294294

295295
#ifdef TRANSFER_PROTOCOL_STATS
296-
typedef enum TransProtoEvent TransProtoEvent;
297-
enum TransProtoEvent
296+
typedef enum TransProtoEvent
298297
{
299298
TPE_DATA_PKT_SEND,
300299
TPE_ACK_PKT_QUERY
301-
};
300+
} TransProtoEvent;
302301

303302
typedef struct TransProtoStatEntry TransProtoStatEntry;
304303
struct TransProtoStatEntry
@@ -322,7 +321,7 @@ struct TransProtoStatEntry
322321
typedef struct TransProtoStats TransProtoStats;
323322
struct TransProtoStats
324323
{
325-
pthread_mutex_t lock;
324+
std::mutex lock;
326325
TransProtoStatEntry *head;
327326
TransProtoStatEntry *tail;
328327
uint64 count;
@@ -335,7 +334,7 @@ struct TransProtoStats
335334

336335
static TransProtoStats trans_proto_stats =
337336
{
338-
PTHREAD_MUTEX_INITIALIZER, NULL, NULL, 0
337+
{}, NULL, NULL, 0
339338
};
340339

341340
/*
@@ -345,7 +344,7 @@ static TransProtoStats trans_proto_stats =
345344
void
346345
TransProtoStats::init()
347346
{
348-
pthread_mutex_lock(&this->lock);
347+
std::lock_guard<std::mutex> guard(this->lock);
349348

350349
while (this->head) {
351350
TransProtoStatEntry *cur = this->head;
@@ -358,8 +357,6 @@ TransProtoStats::init()
358357
this->tail = NULL;
359358
this->count = 0;
360359
this->startTime = getCurrentTime();
361-
362-
pthread_mutex_unlock(&this->lock);
363360
}
364361

365362
void
@@ -373,7 +370,7 @@ TransProtoStats::update(TransProtoEvent event, icpkthdr *pkt)
373370
memset(entry, 0, sizeof(*entry));
374371

375372
/* change the list */
376-
pthread_mutex_lock(&this->lock);
373+
std::lock_guard<std::mutex> guard(this->lock);
377374
if (this->count == 0) {
378375
/* 1st element */
379376
this->head = entry;
@@ -393,19 +390,17 @@ TransProtoStats::update(TransProtoEvent event, icpkthdr *pkt)
393390
* Other attributes can be added on demand new->cwnd =
394391
* snd_control_info.cwnd; new->capacity = conn->capacity;
395392
*/
396-
397-
pthread_mutex_unlock(&this->lock);
398393
}
399394

400-
static void
395+
void
401396
TransProtoStats::dump()
402397
{
403398
char tmpbuf[32];
404399

405-
snprintf(tmpbuf, 32, "%d." UINT64_FORMAT "txt", global_param.MyProcPid, getCurrentTime());
400+
snprintf(tmpbuf, 32, "%d.%lu.txt", global_param.MyProcPid, getCurrentTime());
406401
FILE *ofile = fopen(tmpbuf, "w+");
407402

408-
pthread_mutex_lock(&this->lock);
403+
std::lock_guard<std::mutex> guard(this->lock);
409404
while (this->head)
410405
{
411406
TransProtoStatEntry *cur = NULL;
@@ -419,9 +414,6 @@ TransProtoStats::dump()
419414
}
420415

421416
this->tail = NULL;
422-
423-
pthread_mutex_unlock(&this->lock);
424-
425417
fclose(ofile);
426418
}
427419

@@ -1540,10 +1532,6 @@ InitMotionUDPIFC(int *listenerSocketFd, int32 *listenerPort)
15401532
snd_control_info.minCwnd = 0;
15411533
snd_control_info.ackBuffer = (icpkthdr *)ic_malloc0(MIN_PACKET_SIZE);
15421534

1543-
#ifdef TRANSFER_PROTOCOL_STATS
1544-
initMutex(&trans_proto_stats.lock);
1545-
#endif
1546-
15471535
/* Start up our rx-thread */
15481536

15491537
/*

0 commit comments

Comments
 (0)