Skip to content

Commit

Permalink
uORBManager.cpp: Change how old / stale semaphore handles are used
Browse files Browse the repository at this point in the history
When the semaphore is released and re-instantiated, do proper cleanup
in g_sem_pool.reserve(). Also remove GlobalSemPool and GlobalLock::set
and replace them with free() which just destroys the mutex.
  • Loading branch information
pussuw committed Oct 6, 2023
1 parent c65fb29 commit 7f009f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
7 changes: 5 additions & 2 deletions platforms/common/uORB/uORBManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,7 @@ int uORB::Manager::orb_poll(orb_poll_struct_t *fds, unsigned int nfds, int timeo
}
}

// recover from releasing multiple times
g_sem_pool.set(lock_idx, 0);
// release the semaphore
g_sem_pool.free(lock_idx);

return err ? -1 : count;
Expand Down Expand Up @@ -518,6 +517,7 @@ void uORB::Manager::GlobalSemPool::free(int8_t i)
{
lock();

_global_sem[i].free();
_global_sem[i].in_use = false;

unlock();
Expand All @@ -543,6 +543,9 @@ int8_t uORB::Manager::GlobalSemPool::reserve()
return -1;
}

// Make sure the semaphore is initialized properly for the new user
_global_sem[i].init();

// Mark this one as in use
_global_sem[i].in_use = true;

Expand Down
15 changes: 4 additions & 11 deletions platforms/common/uORB/uORBManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,6 @@ class Manager
int8_t reserve();
void free(int8_t i);

void set(int8_t i, int val) {_global_sem[i].set(val);}
void take(int8_t i) { do {} while (_global_sem[i].take() != 0); }
int take_interruptible(int8_t i) { return _global_sem[i].take(); }
int take_timedwait(int8_t i, struct timespec *abstime) { return _global_sem[i].take_timedwait(abstime); }
Expand All @@ -658,18 +657,12 @@ class Manager
sem_setprotocol(&_lock, SEM_PRIO_NONE);
#endif
in_use = false;
_callback_ptr = nullptr;
}
void set(int val)
{
px4_sem_destroy(&_sem);
px4_sem_init(&_sem, 1, val);
#if __PX4_NUTTX
sem_setprotocol(&_sem, SEM_PRIO_NONE);
#endif
}
int take() {return px4_sem_wait(&_sem);}
void free() { px4_sem_destroy(&_sem); }
int take() { return px4_sem_wait(&_sem); }
int take_timedwait(struct timespec *abstime) { return px4_sem_timedwait(&_sem, abstime); }
void release() {px4_sem_post(&_sem); }
void release() { px4_sem_post(&_sem); }
int value() { int value; px4_sem_getvalue(&_sem, &value); return value; }
bool in_use{false};

Expand Down

0 comments on commit 7f009f0

Please sign in to comment.