Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
aa2f97c8
Commit
aa2f97c8
authored
7 years ago
by
Ken Bannister
Browse files
Options
Downloads
Patches
Plain Diff
net/gcoap: Protect update to open requests with mutex.
parent
24b21dbf
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sys/include/net/gcoap.h
+2
-0
2 additions, 0 deletions
sys/include/net/gcoap.h
sys/net/application_layer/coap/gcoap.c
+4
-0
4 additions, 0 deletions
sys/net/application_layer/coap/gcoap.c
with
6 additions
and
0 deletions
sys/include/net/gcoap.h
+
2
−
0
View file @
aa2f97c8
...
...
@@ -212,6 +212,7 @@
#include
<stdint.h>
#include
<stdatomic.h>
#include
"net/sock/udp.h"
#include
"mutex.h"
#include
"nanocoap.h"
#include
"xtimer.h"
...
...
@@ -439,6 +440,7 @@ typedef struct {
* @brief Container for the state of gcoap itself
*/
typedef
struct
{
mutex_t
lock
;
/**< Shares state attributes safely */
gcoap_listener_t
*
listeners
;
/**< List of registered listeners */
gcoap_request_memo_t
open_reqs
[
GCOAP_REQ_WAITING_MAX
];
/**< Storage for open requests; if first
...
...
This diff is collapsed.
Click to expand it.
sys/net/application_layer/coap/gcoap.c
+
4
−
0
View file @
aa2f97c8
...
...
@@ -585,6 +585,7 @@ kernel_pid_t gcoap_init(void)
_pid
=
thread_create
(
_msg_stack
,
sizeof
(
_msg_stack
),
THREAD_PRIORITY_MAIN
-
1
,
THREAD_CREATE_STACKTEST
,
_event_loop
,
NULL
,
"coap"
);
mutex_init
(
&
_coap_state
.
lock
);
/* Blank lists so we know if an entry is available. */
memset
(
&
_coap_state
.
open_reqs
[
0
],
0
,
sizeof
(
_coap_state
.
open_reqs
));
memset
(
&
_coap_state
.
observers
[
0
],
0
,
sizeof
(
_coap_state
.
observers
));
...
...
@@ -683,6 +684,7 @@ size_t gcoap_req_send2(const uint8_t *buf, size_t len,
assert
(
resp_handler
!=
NULL
);
/* Find empty slot in list of open requests. */
mutex_lock
(
&
_coap_state
.
lock
);
for
(
int
i
=
0
;
i
<
GCOAP_REQ_WAITING_MAX
;
i
++
)
{
if
(
_coap_state
.
open_reqs
[
i
].
state
==
GCOAP_MEMO_UNUSED
)
{
memo
=
&
_coap_state
.
open_reqs
[
i
];
...
...
@@ -690,6 +692,8 @@ size_t gcoap_req_send2(const uint8_t *buf, size_t len,
break
;
}
}
mutex_unlock
(
&
_coap_state
.
lock
);
if
(
memo
)
{
memcpy
(
&
memo
->
hdr_buf
[
0
],
buf
,
GCOAP_HEADER_MAXLEN
);
memo
->
resp_handler
=
resp_handler
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment