Skip to content

Commit 6735cc1

Browse files
nattgrishefloryd
authored andcommitted
Synchronize PDO triggering with the c-open main thread
If a call to trigger a PDO event is done followed by a second job, there's no guarantee that the main thread will have a chance to run and process the PDO job to completion before the common job description struct is overwritten by the next request. Use the semaphore via the completion callback as for all other jobs. Change-Id: I49a59d9e3d69434a984186a12ea8f35b5289d62c
1 parent 62d787b commit 6735cc1

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/co_main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,11 @@ int co_pdo_event (co_client_t * client)
223223
job->client = client;
224224
job->callback = NULL;
225225
job->type = CO_JOB_PDO_EVENT;
226+
job->callback = co_job_callback;
226227

227228
os_mbox_post (net->mbox, job, OS_WAIT_FOREVER);
229+
os_sem_wait (client->sem, OS_WAIT_FOREVER);
230+
228231
return 0;
229232
}
230233

@@ -238,8 +241,11 @@ int co_pdo_obj_event (co_client_t * client, uint16_t index, uint8_t subindex)
238241
job->type = CO_JOB_PDO_OBJ_EVENT;
239242
job->pdo.index = index;
240243
job->pdo.subindex = subindex;
244+
job->callback = co_job_callback;
241245

242246
os_mbox_post (net->mbox, job, OS_WAIT_FOREVER);
247+
os_sem_wait (client->sem, OS_WAIT_FOREVER);
248+
243249
return 0;
244250
}
245251

src/co_pdo.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,10 @@ void co_pdo_job (co_net_t * net, co_job_t * job)
825825
default:
826826
CC_ASSERT (0);
827827
}
828+
829+
job->result = 0;
830+
if (job->callback)
831+
job->callback (job);
828832
}
829833

830834
int co_pdo_init (co_net_t * net)

0 commit comments

Comments
 (0)