diff options
author | Nikhil Devshatwar | 2020-02-13 05:48:21 -0600 |
---|---|---|
committer | Nikhil Devshatwar | 2020-02-17 06:24:48 -0600 |
commit | 460cdda235d492d5224faa6d47039b91a0141760 (patch) | |
tree | 6a80077627c2023bfe04dc95dedc311d93c2db2f | |
parent | e7e40ece5e97c9811881278b867b109cfb1639d7 (diff) | |
download | statcol-460cdda235d492d5224faa6d47039b91a0141760.tar.gz statcol-460cdda235d492d5224faa6d47039b91a0141760.tar.xz statcol-460cdda235d492d5224faa6d47039b91a0141760.zip |
statcol: Protect remote_service_run using mutex
Signed-off-by: Nikhil Devshatwar <nikhil.nd@ti.com>
-rw-r--r-- | include/statcol.h | 1 | ||||
-rw-r--r-- | statcol.c | 10 |
2 files changed, 10 insertions, 1 deletions
diff --git a/include/statcol.h b/include/statcol.h index cbf7f9d..b8d226a 100644 --- a/include/statcol.h +++ b/include/statcol.h | |||
@@ -39,4 +39,5 @@ struct rpmsg_context { | |||
39 | int fd; | 39 | int fd; |
40 | int port; | 40 | int port; |
41 | struct metric_cpuload *m_cpuload; | 41 | struct metric_cpuload *m_cpuload; |
42 | pthread_mutex_t lock; | ||
42 | }; | 43 | }; |
@@ -145,6 +145,7 @@ void scan_rpmsg_char_nodes(void) { | |||
145 | 145 | ||
146 | debug("rpmsg-char supported in %s\n", core); | 146 | debug("rpmsg-char supported in %s\n", core); |
147 | ctx = &g_rpmsg_contexts[i]; | 147 | ctx = &g_rpmsg_contexts[i]; |
148 | pthread_mutex_init(&ctx->lock, NULL); | ||
148 | 149 | ||
149 | rproc_dev = rproc_device_find_for_name(core); | 150 | rproc_dev = rproc_device_find_for_name(core); |
150 | if (!rproc_dev) | 151 | if (!rproc_dev) |
@@ -199,6 +200,8 @@ int remote_service_run(struct rpmsg_context *ctx, char *service, uint cmd, | |||
199 | if (prm_size > APP_REMOTE_SERVICE_PRM_SIZE_MAX) | 200 | if (prm_size > APP_REMOTE_SERVICE_PRM_SIZE_MAX) |
200 | return -EINVAL; | 201 | return -EINVAL; |
201 | 202 | ||
203 | pthread_mutex_lock(&ctx->lock); | ||
204 | |||
202 | header = (app_service_msg_header_t *)ctx->rpmsg_tx_msg_buf; | 205 | header = (app_service_msg_header_t *)ctx->rpmsg_tx_msg_buf; |
203 | header->cmd = cmd; | 206 | header->cmd = cmd; |
204 | header->flags = flags; | 207 | header->flags = flags; |
@@ -214,19 +217,24 @@ int remote_service_run(struct rpmsg_context *ctx, char *service, uint cmd, | |||
214 | 217 | ||
215 | if (ret < 0) { | 218 | if (ret < 0) { |
216 | printf("ERROR: Fail to send rpmsg_char message to %s\n", ctx->name); | 219 | printf("ERROR: Fail to send rpmsg_char message to %s\n", ctx->name); |
220 | pthread_mutex_unlock(&ctx->lock); | ||
217 | return ret; | 221 | return ret; |
218 | } | 222 | } |
219 | 223 | ||
220 | if (flags & APP_REMOTE_SERVICE_FLAG_NO_WAIT_ACK) | 224 | if (flags & APP_REMOTE_SERVICE_FLAG_NO_WAIT_ACK) { |
225 | pthread_mutex_unlock(&ctx->lock); | ||
221 | return 0; | 226 | return 0; |
227 | } | ||
222 | 228 | ||
223 | /* Read the data after header and copy back to buffer */ | 229 | /* Read the data after header and copy back to buffer */ |
224 | ret = read(ctx->fd, ctx->rpmsg_tx_msg_buf, payload_size); | 230 | ret = read(ctx->fd, ctx->rpmsg_tx_msg_buf, payload_size); |
225 | if (ret < 0 || ret < payload_size) { | 231 | if (ret < 0 || ret < payload_size) { |
226 | printf("ERROR: Fail to send rpmsg_char message to %s\n", ctx->name); | 232 | printf("ERROR: Fail to send rpmsg_char message to %s\n", ctx->name); |
233 | pthread_mutex_unlock(&ctx->lock); | ||
227 | return ret; | 234 | return ret; |
228 | } | 235 | } |
229 | memcpy(prm, (header + 1), prm_size); | 236 | memcpy(prm, (header + 1), prm_size); |
237 | pthread_mutex_unlock(&ctx->lock); | ||
230 | return header->status; | 238 | return header->status; |
231 | } | 239 | } |
232 | 240 | ||