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
12b4bca8
Commit
12b4bca8
authored
Nov 10, 2015
by
Ian Craggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Protect delivery complete count from multiple access
parent
7c03c4ad
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
0 deletions
+31
-0
test2.c
test/test2.c
+31
-0
No files found.
test/test2.c
View file @
12b4bca8
...
...
@@ -495,12 +495,39 @@ Test2: multiple client objects used from multiple threads
*********************************************************************/
volatile
int
test2_arrivedcount
=
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
;
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
)
{
lock_mutex
(
deliveryCompleted_mutex
);
++
test2_deliveryCompleted
;
unlock_mutex
(
deliveryCompleted_mutex
);
}
int
test2_messageArrived
(
void
*
context
,
char
*
topicName
,
int
topicLen
,
MQTTClient_message
*
m
)
...
...
@@ -651,6 +678,10 @@ int main(int argc, char** argv)
int
rc
=
0
;
int
(
*
tests
[])()
=
{
NULL
,
test1
};
int
i
;
#if defined(WIN32) || defined(WIN64)
deliveryCompleted_mutex
=
CreateMutex
(
NULL
,
0
,
NULL
);
#endif
xml
=
fopen
(
"TEST-test2.xml"
,
"w"
);
fprintf
(
xml
,
"<testsuite name=
\"
test1
\"
tests=
\"
%d
\"
>
\n
"
,
(
int
)(
ARRAY_SIZE
(
tests
)
-
1
));
...
...
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