From 0052742836f91a99ff3817536ca35687e4959d17 Mon Sep 17 00:00:00 2001 From: minas anderiasian Date: Thu, 15 Dec 2016 14:53:36 -0800 Subject: [PATCH] Adding a generic routine to start threads. White space change in connection.c --- src/CMakeLists.txt | 2 +- src/connection.c | 25 +++++++++++++------------ src/spin_thread.c | 26 ++++++++++++++++++++++++++ src/spin_thread.h | 17 +++++++++++++++++ tests/CMakeLists.txt | 3 ++- 5 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 src/spin_thread.c create mode 100644 src/spin_thread.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f250359..b54cb24 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. set(SOURCES main.c wss_mgr.c mutex.c networking.c nopoll_helpers.c - string_helpers.c time.c config.c connection.c) + string_helpers.c time.c config.c connection.c spin_thread.c) add_executable(parodus ${SOURCES}) diff --git a/src/connection.c b/src/connection.c index 1b858ea..8eceb7d 100644 --- a/src/connection.c +++ b/src/connection.c @@ -345,18 +345,19 @@ char createNopollConnection(noPollCtx *ctx) } ParodusPrint("webpaProtocol is %s\n", webpaProtocol); - struct data meta_pack[METADATA_COUNT] = {{"hw-model", modelName}, - {"hw-serial-number", get_parodus_cfg()->hw_serial_number}, - {"hw-manufacturer", manufacturer}, - {"hw-mac", get_parodus_cfg()->hw_mac}, - {"hw_last_reboot_reason", reboot_reason}, - {"fw-name", firmwareVersion}, - {"boot_time", boot_time}, - {"webpa-last-reconnect-reason",reconnect_reason}, - {"webpa_protocol",webpaProtocol}, - {"webpa_uuid",get_parodus_cfg()->webpa_uuid}, - {"webpa_interface_used", get_parodus_cfg()->webpa_interface_used} - }; + struct data meta_pack[METADATA_COUNT] = { + {"hw-model", modelName}, + {"hw-serial-number", get_parodus_cfg()->hw_serial_number}, + {"hw-manufacturer", manufacturer}, + {"hw-mac", get_parodus_cfg()->hw_mac}, + {"hw_last_reboot_reason", reboot_reason}, + {"fw-name", firmwareVersion}, + {"boot_time", boot_time}, + {"webpa-last-reconnect-reason", reconnect_reason}, + {"webpa_protocol",webpaProtocol}, + {"webpa_uuid",get_parodus_cfg()->webpa_uuid}, + {"webpa_interface_used", get_parodus_cfg()->webpa_interface_used} + }; const data_t metapack = {METADATA_COUNT, meta_pack}; diff --git a/src/spin_thread.c b/src/spin_thread.c new file mode 100644 index 0000000..cf4bbe8 --- /dev/null +++ b/src/spin_thread.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include +#include +#include +#include "spin_thread.h" +#include "parodus_log.h" + +void StartThread(void *(*start_routine) (void *)) +{ + int err = 0; + pthread_t threadId; + + err = pthread_create(&threadId, NULL, start_routine, NULL); + if (err != 0) + { + ParodusError("Error creating thread :[%s]\n", strerror(err)); + exit(1); + } + else + { + ParodusPrint("Thread created Successfully %d\n", (int ) threadId); + } +} + \ No newline at end of file diff --git a/src/spin_thread.h b/src/spin_thread.h new file mode 100644 index 0000000..a35b06a --- /dev/null +++ b/src/spin_thread.h @@ -0,0 +1,17 @@ +#ifndef _SPIN_THREAD_H_ +#define _SPIN_THREAD_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +void StartThread(void *(*start_routine) (void *)); + + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a2ae9ed..e532253 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -54,7 +54,8 @@ add_executable(simple simple.c ../src/mutex.c ../src/time.c ../src/config.c - ../src/connection.c) + ../src/connection.c + ../src/spin_thread.c) target_link_libraries (simple ${PARODUS_COMMON_LIBS} gcov -lnopoll -lnanomsg -lrt ) endif (NOT EXCLUDE_SIMPLE)