Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ serializables
setaffinity
setinheritsched
SETLOGGING
setname
setprotocol
setschedparam
setschedpolicy
Expand Down
25 changes: 25 additions & 0 deletions Os/Posix/Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cstring>

#include "Fw/Logger/Logger.hpp"
#include "Fw/Types/StringUtils.hpp"
#include "Fw/Types/Assert.hpp"
#include "Os/Posix/Task.hpp"
#include "Os/Posix/error.hpp"
Expand Down Expand Up @@ -114,7 +115,27 @@
#endif
return status;
}

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
int set_task_name(pthread_t thread, const Os::Task::Arguments& arguments) {
int status = 0;

Check notice

Code scanning / CodeQL

Use of basic integral type Note

status uses the basic integral type int rather than a typedef with size and signedness.
// pthread_setname_np is a non-POSIX function.
// Limit its use to builds that involve glibc, on Linux, with _GNU_SOURCE defined.
// That's the circumstance in which we expect this feature to work.
#if defined(TGT_OS_TYPE_LINUX) && defined(__GLIBC__) && defined(_GNU_SOURCE)

// Construct a sixteen char long version of the task name
const FwSizeType PTHREAD_NAME_LENGTH = 16;
char name_sixteen_capped[PTHREAD_NAME_LENGTH];
Fw::StringUtils::string_copy(name_sixteen_capped, arguments.m_name.toChar(), PTHREAD_NAME_LENGTH);

status = pthread_setname_np(thread, name_sixteen_capped);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter thread has not been checked.
#else
Fw::Logger::log("[WARNING] %s setting thread name is only available with GNU pthreads\n",
const_cast<CHAR*>(arguments.m_name.toChar()));
#endif
return status;
}

Os::Task::Status PosixTask::create(const Os::Task::Arguments& arguments,
const PosixTask::PermissionExpectation permissions) {
int pthread_status = PosixTaskHandle::SUCCESS;
Expand All @@ -140,6 +161,10 @@
pthread_status =
pthread_create(&handle.m_task_descriptor, &attributes, pthread_entry_wrapper, arguments.m_routine_argument);
}
if ((expect_permission) &&
(pthread_status == PosixTaskHandle::SUCCESS)) {
pthread_status = set_task_name(handle.m_task_descriptor, arguments);
}
// Successful execution of all precious steps will result in a valid task handle
if (pthread_status == PosixTaskHandle::SUCCESS) {
handle.m_is_valid = true;
Expand Down
Loading