Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion Drv/Ip/SocketComponentHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Os::Task::State::NOT_STARTED); // It is a coding error to start this task multiple times
this->m_reconnectStop = false;
Fw::String reconnectName;
reconnectName.format("%s_reconnect", name.toChar());
reconnectName.format("conn_%s", name.toChar());
Os::Task::Arguments reconnectArguments(reconnectName, SocketComponentHelper::reconnectTask, this, priorityReconnect,
stackReconnect, cpuAffinityReconnect);
Os::Task::Status reconnectStat = m_reconnectTask.start(reconnectArguments);
Expand Down
27 changes: 27 additions & 0 deletions Os/Posix/Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "Fw/Logger/Logger.hpp"
#include "Fw/Types/Assert.hpp"
#include "Fw/Types/StringUtils.hpp"
#include "Os/Posix/Task.hpp"
#include "Os/Posix/error.hpp"
#include "Os/Task.hpp"
Expand Down Expand Up @@ -115,6 +116,29 @@
return status;
}

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) && defined(POSIX_THREADS_ENABLE_NAMES) && \
POSIX_THREADS_ENABLE_NAMES
Comment on lines +132 to +133

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
// Construct a sixteen char long version of the task name. This length is fixed by the posix thread
// specification and is a constant.
char name_sixteen_capped[PosixTask::PTHREAD_NAME_LENGTH];
Fw::StringUtils::string_copy(name_sixteen_capped, arguments.m_name.toChar(), sizeof(name_sixteen_capped));

status = pthread_setname_np(thread, name_sixteen_capped);
#else
// Only warn if the flag is on
#if defined(POSIX_THREADS_ENABLE_NAMES) && POSIX_THREADS_ENABLE_NAMES
Fw::Logger::log("[WARNING] %s setting thread name is only available with GNU pthreads\n",
const_cast<CHAR*>(arguments.m_name.toChar()));
#endif
#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 +164,9 @@
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
1 change: 1 addition & 0 deletions Os/Posix/Task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct PosixTaskHandle : public TaskHandle {
//! Posix task implementation as driven by pthreads implementation
class PosixTask : public TaskInterface {
public:
static constexpr FwSizeType PTHREAD_NAME_LENGTH = 16; //!< Length of pthread name
//! Enumeration of permission expectations
enum PermissionExpectation {
EXPECT_PERMISSION, //!< Expect that you hold necessary permissions
Expand Down
6 changes: 6 additions & 0 deletions default/config/FpConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ extern "C" {
#define FW_AMPCS_COMPATIBLE 0 //!< Whether or not JPL AMPCS ground system support is enabled.
#endif

// Posix thread names are limited to 16 characters, this can lead to collisions. In the event of a
// collision, set this to 0.
#ifndef POSIX_THREADS_ENABLE_NAMES
#define POSIX_THREADS_ENABLE_NAMES 1 //!< Enable/Disable assigning names to threads
#endif

// *** NOTE configuration checks are in Fw/Cfg/ConfigCheck.cpp in order to have
// the type definitions in Fw/Types/BasicTypes available.
#ifdef __cplusplus
Expand Down
Loading