Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #623, add debug messages for mutex double locks #634

Merged
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/os/shared/inc/os-shared-mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@

typedef struct
{
char obj_name[OS_MAX_API_NAME];
char obj_name[OS_MAX_API_NAME];
osal_id_t last_owner;
} OS_mutex_internal_record_t;

/*
Expand Down
28 changes: 28 additions & 0 deletions src/os/shared/src/osapi-mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,24 @@ int32 OS_MutSemGive(osal_id_t sem_id)
OS_common_record_t *record;
uint32 local_id;
int32 return_code;
osal_id_t self_task;

/* Check Parameters */
return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record);
if (return_code == OS_SUCCESS)
{
self_task = OS_TaskGetId();

if (!OS_ObjectIdEqual(OS_mutex_table[local_id].last_owner, self_task))
{
OS_DEBUG("WARNING: Task %lu giving mutex %lu while owned by task %lu\n",
OS_ObjectIdToInteger(self_task),
OS_ObjectIdToInteger(sem_id),
OS_ObjectIdToInteger(OS_mutex_table[local_id].last_owner));
}

OS_mutex_table[local_id].last_owner = OS_OBJECT_ID_UNDEFINED;

return_code = OS_MutSemGive_Impl(local_id);
}

Expand All @@ -187,12 +200,27 @@ int32 OS_MutSemTake(osal_id_t sem_id)
OS_common_record_t *record;
uint32 local_id;
int32 return_code;
osal_id_t self_task;

/* Check Parameters */
return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, sem_id, &local_id, &record);
if (return_code == OS_SUCCESS)
{
return_code = OS_MutSemTake_Impl(local_id);
if (return_code == OS_SUCCESS)
{
self_task = OS_TaskGetId();

if (OS_ObjectIdDefined(OS_mutex_table[local_id].last_owner))
{
OS_DEBUG("WARNING: Task %lu taking mutex %lu while owned by task %lu\n",
OS_ObjectIdToInteger(self_task),
OS_ObjectIdToInteger(sem_id),
OS_ObjectIdToInteger(OS_mutex_table[local_id].last_owner));
}

OS_mutex_table[local_id].last_owner = self_task;
}
}

return return_code;
Expand Down