Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/rf4ce/ctrlm_rf4ce_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <algorithm>
#include <regex>
#include <limits.h>
#include <errno.h>
#include <sys/sysinfo.h>
#include "ctrlm.h"
#include "ctrlm_log.h"
Expand Down Expand Up @@ -411,8 +412,31 @@ ctrlm_hal_result_t ctrlm_obj_network_rf4ce_t::hal_init_request(GThread *ctrlm_ma

// Block until initialization is complete or a timeout occurs
XLOGD_INFO("Waiting for %s initialization...", name_get());
sem_wait(&semaphore_);
sem_destroy(&semaphore_);
struct timespec timeout;
clock_gettime(CLOCK_REALTIME, &timeout);
timeout.tv_sec += 2; // this operation should complete in under 100 ms under normal circumstances

int sem_result = -1;
do {
errno = 0;
sem_result = sem_timedwait(&semaphore_, &timeout);
if(sem_result == -1 && errno == EINTR) {
XLOGD_INFO("interrupted");
} else {
break;
}
} while(1);

if(sem_result == -1) {
if(errno == ETIMEDOUT) {
XLOGD_ERROR("Timeout waiting for %s initialization", name_get());
} else {
XLOGD_ERROR("Error waiting for %s initialization: %s", name_get(), strerror(errno));
}
Comment thread
dwolaver marked this conversation as resolved.
init_result_ = CTRLM_HAL_RESULT_ERROR;
} else {
sem_destroy(&semaphore_);
Comment thread
dwolaver marked this conversation as resolved.
}
Comment thread
dwolaver marked this conversation as resolved.
Comment thread
dwolaver marked this conversation as resolved.

ready_ = (CTRLM_HAL_RESULT_SUCCESS == init_result_);

Expand Down
Loading