Skip to content

Commit 6c3ab14

Browse files
committed
Add a bit of debug info in Connection pinging
1 parent dd2e34f commit 6c3ab14

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef struct {
3434
MYSQL *mySQLConnection;
3535
volatile BOOL *keepAlivePingThreadActivePointer;
3636
volatile BOOL *keepAliveLastPingSuccessPointer;
37+
void *parentId;
3738
} SPMySQLConnectionPingDetails;
3839

3940
@interface SPMySQLConnection (Ping_and_KeepAlive)

Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#import "SPMySQL Private APIs.h"
3434
#import "Locking.h"
3535
#import <pthread.h>
36+
#include <stdio.h>
3637

3738
@implementation SPMySQLConnection (Ping_and_KeepAlive)
3839

@@ -85,7 +86,7 @@ - (void)_threadedKeepAlive
8586
}
8687

8788
keepAliveThread = [NSThread currentThread];
88-
[keepAliveThread setName:@"SPMySQL connection keepalive monitor thread"];
89+
[keepAliveThread setName:[NSString stringWithFormat:@"SPMySQL connection keepalive monitor thread (id=%p)", self]];
8990

9091
// If the maximum number of ping failures has been reached, determine whether to reconnect.
9192
if (keepAliveLastPingBlocked || keepAlivePingFailures >= 3) {
@@ -158,6 +159,7 @@ - (BOOL)_pingConnectionUsingLoopDelay:(NSUInteger)loopDelay
158159
pingDetails->mySQLConnection = mySQLConnection;
159160
pingDetails->keepAliveLastPingSuccessPointer = &keepAliveLastPingSuccess;
160161
pingDetails->keepAlivePingThreadActivePointer = &keepAlivePingThreadActive;
162+
pingDetails->parentId = self;
161163

162164
// Create a pthread for the ping
163165
pthread_t keepAlivePingThread_t;
@@ -216,9 +218,11 @@ - (BOOL)_pingConnectionUsingLoopDelay:(NSUInteger)loopDelay
216218
*/
217219
void _backgroundPingTask(void *ptr)
218220
{
219-
pthread_setname_np("SPMySQL _backgroundPingTask() worker thread");
220-
221221
SPMySQLConnectionPingDetails *pingDetails = (SPMySQLConnectionPingDetails *)ptr;
222+
223+
char threadNameBuf[80];
224+
snprintf(threadNameBuf, sizeof(threadNameBuf), "SPMySQL _backgroundPingTask() worker thread (id=%p)", pingDetails->parentId);
225+
pthread_setname_np(threadNameBuf);
222226

223227
// Set up a cleanup routine
224228
pthread_cleanup_push(_pingThreadCleanup, pingDetails);

0 commit comments

Comments
 (0)