Commit c56c346d authored by Adam Wujek's avatar Adam Wujek 💬

userspace/wrs_watchdog: improve opening of shmem

Wait 10 seconds to open HAL's shmem, then print message and exit.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 580db1ec
......@@ -51,41 +51,45 @@ int port_num = 0;
int get_nports_from_hal(void)
{
struct hal_shmem_header *h;
struct wrs_shm_head *hal_head;
struct wrs_shm_head *hal_head = NULL;
int hal_nports_local; /* local copy of number of ports */
int ii;
int n_wait = 0;
int ret;
/* wait forever for HAL */
while (!(hal_head = wrs_shm_get(wrs_shm_hal, "",
WRS_SHM_READ | WRS_SHM_LOCKED))) {
if (n_wait > 5) {
/* print if waiting more than 5 seconds, some waiting
* is expected since hal requires few seconds to start
*/
pr_error("unable to open shm for HAL!\n");
}
/* wait for HAL */
while ((ret = wrs_shm_get_and_check(wrs_shm_hal, &hal_head)) != 0) {
n_wait++;
if (n_wait > 10) {
if (ret == 1) {
pr_error("Unable to open HAL's shmem!\n");
}
if (ret == 2) {
pr_error("Unable to read HAL's version!\n");
}
exit(1);
}
sleep(1);
}
h = (void *)hal_head + hal_head->data_off;
n_wait = 0;
while (1) { /* wait forever for HAL to produce consistent nports */
while (1) { /* wait 10 sec for HAL to produce consistent nports */
n_wait++;
ii = wrs_shm_seqbegin(hal_head);
/* Assume number of ports does not change in runtime */
hal_nports_local = h->nports;
if (!wrs_shm_seqretry(hal_head, ii))
break;
if (n_wait > 5) {
/* print if waiting more than 5 seconds, some waiting
if (n_wait > 10) {
/* print if waiting more than 10 seconds, some waiting
* is expected since hal requires few seconds to start
*/
pr_error("Wait for HAL.\n");
exit(1);
}
n_wait++;
sleep(1);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment