Skip to content

Commit

Permalink
Remove recursive mutex & fix unbalanced locking in TestPlatformMgr (p…
Browse files Browse the repository at this point in the history
…roject-chip#1587)

We shouldn't use recursive mutexes for synchronization as they greatly
complicate analysis and maintenance.
  • Loading branch information
mspang authored and kedars committed Jul 21, 2020
1 parent f815825 commit 9987ae5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,7 @@ CHIP_ERROR GenericPlatformManagerImpl_POSIX<ImplClass>::_InitChipStack(void)
{
CHIP_ERROR err = CHIP_NO_ERROR;

#if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
mChipStackLock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
#elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
mChipStackLock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
#else
#error "No defined static initializer for POSIX Threads recursive mutex!"
#endif // defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
mChipStackLock = PTHREAD_MUTEX_INITIALIZER;

// Initialize the Configuration Manager object.
err = ConfigurationMgr().Init();
Expand Down
8 changes: 2 additions & 6 deletions src/platform/tests/TestPlatformMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ static void TestPlatformMgr_StartEventLoopTask(nlTestSuite * inSuite, void * inC
static void TestPlatformMgr_TryLockChipStack(nlTestSuite * inSuite, void * inContext)
{
bool locked = PlatformMgr().TryLockChipStack();
NL_TEST_ASSERT(inSuite, locked);

PlatformMgr().LockChipStack();
locked = PlatformMgr().TryLockChipStack();
PlatformMgr().UnlockChipStack();
NL_TEST_ASSERT(inSuite, locked);
if (locked)
PlatformMgr().UnlockChipStack();
}

static int sEventRecieved = 0;
Expand Down

0 comments on commit 9987ae5

Please sign in to comment.