Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
paho.mqtt.c
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eclipse
paho.mqtt.c
Commits
2263edc8
Commit
2263edc8
authored
Nov 10, 2015
by
Ian Craggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add mutex locks to correct callback
parent
12b4bca8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
23 deletions
+24
-23
test2.c
test/test2.c
+24
-23
No files found.
test/test2.c
View file @
2263edc8
...
@@ -274,6 +274,28 @@ void myassert(char* filename, int lineno, char* description, int value, char* fo
...
@@ -274,6 +274,28 @@ void myassert(char* filename, int lineno, char* description, int value, char* fo
}
}
#if defined(WIN32) || defined(WIN64)
mutex_type
deliveryCompleted_mutex
=
NULL
;
#else
pthread_mutex_t
deliveryCompleted_mutex_store
=
PTHREAD_MUTEX_INITIALIZER
;
mutex_type
deliveryCompleted_mutex
=
&
deliveryCompleted_mutex_store
;
#endif
void
lock_mutex
(
mutex_type
amutex
)
{
int
rc
=
Thread_lock_mutex
(
amutex
);
if
(
rc
!=
0
)
MyLog
(
LOGA_INFO
,
"Error %s locking mutex"
,
strerror
(
rc
));
}
void
unlock_mutex
(
mutex_type
amutex
)
{
int
rc
=
Thread_unlock_mutex
(
amutex
);
if
(
rc
!=
0
)
MyLog
(
LOGA_INFO
,
"Error %s unlocking mutex"
,
strerror
(
rc
));
}
/*********************************************************************
/*********************************************************************
Test1: multiple threads to single client object
Test1: multiple threads to single client object
...
@@ -287,7 +309,9 @@ MQTTClient_message test1_pubmsg_check = MQTTClient_message_initializer;
...
@@ -287,7 +309,9 @@ MQTTClient_message test1_pubmsg_check = MQTTClient_message_initializer;
void
test1_deliveryComplete
(
void
*
context
,
MQTTClient_deliveryToken
dt
)
void
test1_deliveryComplete
(
void
*
context
,
MQTTClient_deliveryToken
dt
)
{
{
lock_mutex
(
deliveryCompleted_mutex
);
++
test1_deliveryCompleted
;
++
test1_deliveryCompleted
;
unlock_mutex
(
deliveryCompleted_mutex
);
}
}
int
test1_messageArrived
(
void
*
context
,
char
*
topicName
,
int
topicLen
,
MQTTClient_message
*
m
)
int
test1_messageArrived
(
void
*
context
,
char
*
topicName
,
int
topicLen
,
MQTTClient_message
*
m
)
...
@@ -498,31 +522,8 @@ volatile int test2_arrivedcount = 0;
...
@@ -498,31 +522,8 @@ volatile int test2_arrivedcount = 0;
volatile
int
test2_deliveryCompleted
=
0
;
volatile
int
test2_deliveryCompleted
=
0
;
#if defined(WIN32) || defined(WIN64)
mutex_type
deliveryCompleted_mutex
=
NULL
;
#else
pthread_mutex_t
deliveryCompleted_mutex_store
=
PTHREAD_MUTEX_INITIALIZER
;
mutex_type
deliveryCompleted_mutex
=
&
deliveryCompleted_mutex_store
;
#endif
MQTTClient_message
test2_pubmsg
=
MQTTClient_message_initializer
;
MQTTClient_message
test2_pubmsg
=
MQTTClient_message_initializer
;
void
lock_mutex
(
mutex_type
amutex
)
{
int
rc
=
Thread_lock_mutex
(
amutex
);
if
(
rc
!=
0
)
MyLog
(
LOGA_INFO
,
"Error %s locking mutex"
,
strerror
(
rc
));
}
void
unlock_mutex
(
mutex_type
amutex
)
{
int
rc
=
Thread_unlock_mutex
(
amutex
);
if
(
rc
!=
0
)
MyLog
(
LOGA_INFO
,
"Error %s unlocking mutex"
,
strerror
(
rc
));
}
void
test2_deliveryComplete
(
void
*
context
,
MQTTClient_deliveryToken
dt
)
void
test2_deliveryComplete
(
void
*
context
,
MQTTClient_deliveryToken
dt
)
{
{
lock_mutex
(
deliveryCompleted_mutex
);
lock_mutex
(
deliveryCompleted_mutex
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment