srsLTE: Fix thread memory leak. Moved test. Fix CLang warnings.

master
Xavier Arteaga 5 years ago committed by Xavier Arteaga
parent a7e92c384e
commit ad46fc006f

@ -58,3 +58,5 @@ add_executable(arch_select arch_select.cc)
target_include_directories(srslte_common PUBLIC ${SEC_INCLUDE_DIRS})
target_link_libraries(srslte_common srslte_phy ${SEC_LIBRARIES})
install(TARGETS srslte_common DESTINATION ${LIBRARY_DIR})
add_subdirectory(test)

@ -0,0 +1,31 @@
#
# Copyright 2013-2019 Software Radio Systems Limited
#
# This file is part of srsLTE
#
# srsLTE is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# srsLTE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# A copy of the GNU Affero General Public License can be found in
# the LICENSE file in the top-level directory of this distribution
# and at http://www.gnu.org/licenses/.
#
add_executable(thread_pool_test thread_pool_test.cc)
target_link_libraries(thread_pool_test
srslte_common)
add_test(thread_pool_test thread_pool_test)
add_executable(thread_test thread_test.cc)
target_link_libraries(thread_test
srsue_phy
srslte_common)
add_test(thread_test thread_test)

@ -18,11 +18,10 @@
* and at http://www.gnu.org/licenses/.
*
*/
#include <srslte/common/log_filter.h>
#include <srslte/common/thread_pool.h>
#include <srslte/common/tti_sempahore.h>
#include <srslte/phy/utils/random.h>
#include <srslte/srslte.h>
#include <srsue/hdr/phy/phy.h>
class dummy_radio
{

@ -0,0 +1,46 @@
/*
* Copyright 2013-2019 Software Radio Systems Limited
*
* This file is part of srsLTE.
*
* srsLTE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* srsLTE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#include <iostream>
#include <srslte/common/threads.h>
class thread_test : public thread
{
public:
thread_test() : thread("Threat Test") {}
protected:
void run_thread() override { std::cout << "Hello world!" << std::endl; }
};
int main(int argc, char** argv)
{
// Declare thread
thread_test mythread;
// Start
mythread.start(0);
// Wait to finish, join
mythread.wait_thread_finish();
return 0;
}

@ -90,7 +90,11 @@ bool threads_new_rt_cpu(pthread_t* thread, void* (*start_routine)(void*), void*
// All threads have normal priority except prio_offset=0,1,2,3,4
if (prio_offset >= 0 && prio_offset < 5) {
param.sched_priority = 50 - prio_offset;
pthread_attr_init(&attr);
if (pthread_attr_init(&attr)) {
perror("pthread_attr_init");
} else {
attr_enable = true;
}
if (pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) {
perror("pthread_attr_setinheritsched");
}
@ -101,12 +105,14 @@ bool threads_new_rt_cpu(pthread_t* thread, void* (*start_routine)(void*), void*
perror("pthread_attr_setschedparam");
fprintf(stderr, "Error not enough privileges to set Scheduling priority\n");
}
attr_enable = true;
} else {
#endif
param.sched_priority = 0;
pthread_attr_init(&attr);
if (pthread_attr_init(&attr)) {
perror("pthread_attr_init");
} else {
attr_enable = true;
}
if (pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) {
perror("pthread_attr_setinheritsched");
}
@ -117,16 +123,15 @@ bool threads_new_rt_cpu(pthread_t* thread, void* (*start_routine)(void*), void*
perror("pthread_attr_setschedparam");
fprintf(stderr, "Error not enough privileges to set Scheduling priority\n");
}
attr_enable = true;
}
if (cpu > 0) {
if (cpu > 50) {
int mask;
uint32_t mask;
mask = cpu / 100;
CPU_ZERO(&cpuset);
for (int i = 0; i < 8; i++) {
if (((mask >> i) & 0x01) == 1) {
for (uint32_t i = 0; i < 8; i++) {
if (((mask >> i) & 0x01U) == 1U) {
CPU_SET((size_t)i, &cpuset);
}
}
@ -143,6 +148,9 @@ bool threads_new_rt_cpu(pthread_t* thread, void* (*start_routine)(void*), void*
int err = pthread_create(thread, attr_enable ? &attr : NULL, start_routine, arg);
if (err) {
if (EPERM == err) {
// Join failed thread for avoiding memory leak from previous trial
pthread_join(*thread, NULL);
perror("Warning: Failed to create thread with real-time priority. Creating it with normal priority");
err = pthread_create(thread, NULL, start_routine, arg);
if (err) {

@ -29,8 +29,8 @@ link_directories(
${SEC_LIBRARY_DIRS}
)
add_executable(phy_worker_test phy_worker_test.cc)
target_link_libraries(phy_worker_test
add_executable(ue_phy_test ue_phy_test.cc)
target_link_libraries(ue_phy_test
srsue_phy
srsue_stack
srsue_upper
@ -43,14 +43,7 @@ target_link_libraries(phy_worker_test
rrc_asn1
${CMAKE_THREAD_LIBS_INIT}
${Boost_LIBRARIES})
add_test(phy_worker_test phy_worker_test)
add_executable(phy_concurrency_test phy_concurrency_test.cc)
target_link_libraries(phy_concurrency_test
srsue_phy
srslte_common)
add_test(phy_concurrency_test phy_concurrency_test)
add_test(ue_phy_test ue_phy_test)
add_executable(scell_search_test scell_search_test.cc)
target_link_libraries(scell_search_test

Loading…
Cancel
Save