Add PTHREAD_PRIO_PROTECT to sm mutexes
- rename mutexes from generic name '_mutex' - create common util functions for initializing and destroying mutexes - add mutex initialize/finalize functions and run them in sm_main_process_initialize - update copyright info to 2023 Test plan: PASS - AIO-DX: iso install PASS - AIO-DX: verify ha swact PASS - AIO-DX: failover swact test PASS - AIO-DX: run pi_stress (rt-tests) to confirm priority inheritance POSIX attribute is working ------------------------------------------------------------------- sysadmin@localhost:~$ sudo pi_stress --uniprocessor --duration=10s Starting PI Stress Test Number of thread groups: 3 Duration of test run: 10 seconds Number of inversions per group: unlimited Admin thread SCHED_FIFO priority 4 3 groups of 3 threads will be created High thread SCHED_FIFO priority 3 Med thread SCHED_FIFO priority 2 Low thread SCHED_FIFO priority 1 Current Inversions: 992034 Stopping test Total inversion performed: 992038 Test Duration: 0 days, 0 hours, 0 minutes, 11 seconds ------------------------------------------------------------------- PASS - AIO-DX: valgrind helgrind * test for inconsistence lock ordering * test race conditions [ detected outside scope of jira ] * test for deadlocks Task: 47503 Story: 2010609 Signed-off-by: Kyale, Eliud <Eliud.Kyale@windriver.com> Change-Id: Ic77f08ca7c3a687b1cc219ac9cba5711979206e8
This commit is contained in:
parent
48ec1759ed
commit
b65eb7b2f6
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -25,6 +25,7 @@
|
|||
#include "sm_debug.h"
|
||||
#include "sm_selobj.h"
|
||||
#include "sm_netlink.h"
|
||||
#include "sm_util_types.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -36,9 +37,19 @@ typedef struct
|
|||
SmHwCallbacksT callbacks;
|
||||
} SmHwThreadInfoT;
|
||||
|
||||
static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t hw_mutex;
|
||||
static SmHwThreadInfoT _threads[SM_THREADS_MAX];
|
||||
|
||||
SmErrorT sm_hw_mutex_initialize ( void )
|
||||
{
|
||||
return sm_mutex_initialize(&hw_mutex, false);
|
||||
}
|
||||
|
||||
SmErrorT sm_hw_mutex_finalize ( void )
|
||||
{
|
||||
return sm_mutex_finalize(&hw_mutex);
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
// Hardware - Find Thread Info
|
||||
// ===========================
|
||||
|
@ -673,7 +684,7 @@ SmErrorT sm_hw_initialize( SmHwCallbacksT* callbacks )
|
|||
SmHwThreadInfoT* thread_info = NULL;
|
||||
SmErrorT error;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &hw_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -757,7 +768,7 @@ SmErrorT sm_hw_initialize( SmHwCallbacksT* callbacks )
|
|||
thread_info->thread_id = pthread_self();
|
||||
thread_info->inuse = true;
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &hw_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -766,7 +777,7 @@ SmErrorT sm_hw_initialize( SmHwCallbacksT* callbacks )
|
|||
return( SM_OKAY );
|
||||
|
||||
ERROR:
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &hw_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -784,7 +795,7 @@ SmErrorT sm_hw_finalize( void )
|
|||
SmHwThreadInfoT* thread_info;
|
||||
SmErrorT error;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &hw_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -817,7 +828,7 @@ SmErrorT sm_hw_finalize( void )
|
|||
}
|
||||
|
||||
DONE:
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &hw_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -126,6 +126,18 @@ extern SmErrorT sm_hw_initialize( SmHwCallbacksT* callbacks );
|
|||
extern SmErrorT sm_hw_finalize( void );
|
||||
// ***************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// initialize mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_hw_mutex_initialize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// destroy mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_hw_mutex_finalize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -20,6 +20,7 @@
|
|||
#include "sm_types.h"
|
||||
#include "sm_debug.h"
|
||||
#include "sm_list.h"
|
||||
#include "sm_util_types.h"
|
||||
|
||||
#define SM_SEL_OBJ_ENTRY_VALID 0xFDFDFDFD
|
||||
|
||||
|
@ -40,9 +41,19 @@ typedef struct
|
|||
SmSelObjSelectEntryT selobjs[SM_THREAD_SELECT_OBJS_MAX];
|
||||
} SmSelObjThreadInfoT;
|
||||
|
||||
static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t selobj_mutex;
|
||||
static SmSelObjThreadInfoT _threads[SM_THREADS_MAX];
|
||||
|
||||
SmErrorT sm_selobj_mutex_initialize ( void )
|
||||
{
|
||||
return sm_mutex_initialize(&selobj_mutex, false);
|
||||
}
|
||||
|
||||
SmErrorT sm_selobj_mutex_finalize ( void )
|
||||
{
|
||||
return sm_mutex_finalize(&selobj_mutex);
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
// Selection Object - Find Thread Info
|
||||
// ===================================
|
||||
|
@ -246,7 +257,7 @@ SmErrorT sm_selobj_initialize( void )
|
|||
{
|
||||
SmSelObjThreadInfoT* thread_info = NULL;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &selobj_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -274,7 +285,7 @@ SmErrorT sm_selobj_initialize( void )
|
|||
thread_info->thread_id = pthread_self();
|
||||
FD_ZERO( &(thread_info->selobjs_set) );
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &selobj_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
@ -282,7 +293,7 @@ SmErrorT sm_selobj_initialize( void )
|
|||
return( SM_OKAY );
|
||||
|
||||
ERROR:
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &selobj_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -299,7 +310,7 @@ SmErrorT sm_selobj_finalize( void )
|
|||
{
|
||||
SmSelObjThreadInfoT* thread_info;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &selobj_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -315,7 +326,7 @@ SmErrorT sm_selobj_finalize( void )
|
|||
memset( thread_info, 0, sizeof(SmSelObjThreadInfoT) );
|
||||
FD_ZERO( &(thread_info->selobjs_set) );
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &selobj_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -18,6 +18,18 @@ extern "C" {
|
|||
|
||||
typedef void (*SmSelObjCallbackT) (int selobj, int64_t user_data);
|
||||
|
||||
// ****************************************************************************
|
||||
// initialize mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_selobj_mutex_initialize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// destroy mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_selobj_mutex_finalize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// Selection Object - Register
|
||||
// ===========================
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -14,6 +14,7 @@
|
|||
#include "sm_types.h"
|
||||
#include "sm_debug.h"
|
||||
#include "sm_time.h"
|
||||
#include "sm_util_types.h"
|
||||
|
||||
#define SM_THREAD_HEALTH_CHECK_INTERVAL_IN_MS 1000
|
||||
|
||||
|
@ -27,7 +28,17 @@ typedef struct
|
|||
} SmThreadHealthT;
|
||||
|
||||
static SmThreadHealthT _threads[SM_THREADS_MAX];
|
||||
static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t thread_health_mutex;
|
||||
|
||||
SmErrorT sm_thread_health_mutex_initialize ( void )
|
||||
{
|
||||
return sm_mutex_initialize(&thread_health_mutex, false);
|
||||
}
|
||||
|
||||
SmErrorT sm_thread_health_mutex_finalize ( void)
|
||||
{
|
||||
return sm_mutex_finalize(&thread_health_mutex);
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
// Thread Health - Register
|
||||
|
@ -35,7 +46,7 @@ static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
|
|||
SmErrorT sm_thread_health_register( const char thread_name[],
|
||||
long warn_after_elapsed_ms, long fail_after_elapsed_ms )
|
||||
{
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &thread_health_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -60,7 +71,7 @@ SmErrorT sm_thread_health_register( const char thread_name[],
|
|||
}
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &thread_health_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -75,7 +86,7 @@ SmErrorT sm_thread_health_register( const char thread_name[],
|
|||
// ==========================
|
||||
SmErrorT sm_thread_health_deregister( const char thread_name[] )
|
||||
{
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &thread_health_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -98,7 +109,7 @@ SmErrorT sm_thread_health_deregister( const char thread_name[] )
|
|||
}
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &thread_health_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -113,7 +124,7 @@ SmErrorT sm_thread_health_deregister( const char thread_name[] )
|
|||
// ======================
|
||||
SmErrorT sm_thread_health_update( const char thread_name[] )
|
||||
{
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &thread_health_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -136,7 +147,7 @@ SmErrorT sm_thread_health_update( const char thread_name[] )
|
|||
}
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &thread_health_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -168,7 +179,7 @@ SmErrorT sm_thread_health_check( bool* healthy )
|
|||
|
||||
sm_time_get( &last_check );
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &thread_health_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -199,7 +210,7 @@ SmErrorT sm_thread_health_check( bool* healthy )
|
|||
}
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &thread_health_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( SM_FAILED );
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -14,6 +14,18 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ****************************************************************************
|
||||
// initialize mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_thread_health_mutex_initialize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// destroy mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_thread_health_mutex_finalize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// Thread Health - Register
|
||||
// ========================
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -23,6 +23,7 @@
|
|||
#include "sm_time.h"
|
||||
#include "sm_debug.h"
|
||||
#include "sm_selobj.h"
|
||||
#include "sm_util_types.h"
|
||||
|
||||
#define SM_TIMER_ENTRY_INUSE 0xFDFDFDFD
|
||||
#define SM_MAX_TIMERS 512
|
||||
|
@ -70,9 +71,19 @@ typedef struct
|
|||
|
||||
static SmTimerIdT _next_timer_id = 1;
|
||||
|
||||
static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t timer_mutex;
|
||||
static SmTimerThreadInfoT _threads[SM_THREADS_MAX];
|
||||
|
||||
SmErrorT sm_timer_mutex_initialize ( void )
|
||||
{
|
||||
return sm_mutex_initialize(&timer_mutex, false);
|
||||
}
|
||||
|
||||
SmErrorT sm_timer_mutex_finalize ( void )
|
||||
{
|
||||
return sm_mutex_finalize(&timer_mutex);
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
// Timer - Find Thread Info
|
||||
// ========================
|
||||
|
@ -542,7 +553,7 @@ SmErrorT sm_timer_initialize( unsigned int tick_interval_in_ms )
|
|||
SmTimerThreadInfoT* thread_info = NULL;
|
||||
SmErrorT error;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &timer_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -610,7 +621,7 @@ SmErrorT sm_timer_initialize( unsigned int tick_interval_in_ms )
|
|||
goto ERROR;
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &timer_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -619,7 +630,7 @@ SmErrorT sm_timer_initialize( unsigned int tick_interval_in_ms )
|
|||
return( SM_OKAY );
|
||||
|
||||
ERROR:
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &timer_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -637,7 +648,7 @@ SmErrorT sm_timer_finalize( void )
|
|||
SmTimerThreadInfoT* thread_info;
|
||||
SmErrorT error;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &timer_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -665,7 +676,7 @@ SmErrorT sm_timer_finalize( void )
|
|||
}
|
||||
|
||||
DONE:
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &timer_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -24,6 +24,18 @@ typedef int64_t SmTimerIdT;
|
|||
|
||||
typedef bool (*SmTimerCallbackT) (SmTimerIdT timer_id, int64_t user_data );
|
||||
|
||||
// ****************************************************************************
|
||||
// initialize mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_timer_mutex_initialize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// destroy mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_timer_mutex_finalize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// Timer - Register
|
||||
// ================
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -25,6 +25,7 @@
|
|||
#include "sm_types.h"
|
||||
#include "sm_debug.h"
|
||||
#include "sm_trap_thread.h"
|
||||
#include "sm_util_types.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -37,7 +38,7 @@ static int _trap_fd = -1;
|
|||
static int _process_id;
|
||||
static char _process_name[SM_PROCESS_NAME_MAX_CHAR];
|
||||
static SmTrapThreadInfoT _threads[SM_THREADS_MAX];
|
||||
static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t trap_mutex;
|
||||
static pthread_spinlock_t _thread_spinlock;
|
||||
|
||||
// ***************************************************************************
|
||||
|
@ -158,7 +159,7 @@ void sm_trap_set_thread_info( void )
|
|||
int thread_id;
|
||||
SmTrapThreadInfoT* info;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &trap_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return;
|
||||
|
@ -185,7 +186,7 @@ void sm_trap_set_thread_info( void )
|
|||
}
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &trap_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return;
|
||||
|
@ -207,6 +208,8 @@ SmErrorT sm_trap_initialize( const char process_name[] )
|
|||
int dummy_trace_count;
|
||||
SmErrorT error = SM_FAILED;
|
||||
|
||||
sm_mutex_initialize(&trap_mutex, false);
|
||||
|
||||
_process_id = (int) getpid();
|
||||
snprintf( _process_name, sizeof(_process_name), "%s", process_name );
|
||||
|
||||
|
@ -312,9 +315,7 @@ ERROR:
|
|||
// ===============
|
||||
SmErrorT sm_trap_finalize( void )
|
||||
{
|
||||
SmErrorT error;
|
||||
|
||||
error = sm_trap_thread_stop();
|
||||
SmErrorT error = sm_trap_thread_stop();
|
||||
if( SM_OKAY != error )
|
||||
{
|
||||
printf( "Failed to stop trap thread, error=%s.\n",
|
||||
|
@ -327,6 +328,8 @@ SmErrorT sm_trap_finalize( void )
|
|||
_trap_fd = -1;
|
||||
}
|
||||
|
||||
sm_mutex_finalize(&trap_mutex);
|
||||
|
||||
return( SM_OKAY );
|
||||
}
|
||||
// ***************************************************************************
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Wind River Systems, Inc.
|
||||
// Copyright (c) 2018,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -8,10 +8,57 @@
|
|||
#include "sm_util_types.h"
|
||||
#include "sm_debug.h"
|
||||
|
||||
SmErrorT sm_mutex_initialize ( pthread_mutex_t* mutex, bool mutex_recursive )
|
||||
{
|
||||
SmErrorT error = SM_OKAY;
|
||||
pthread_mutexattr_t attr;
|
||||
if(mutex)
|
||||
{
|
||||
pthread_mutexattr_init(&attr);
|
||||
if(mutex_recursive)
|
||||
{
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
}
|
||||
pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_INHERIT);
|
||||
int res = pthread_mutex_init(mutex, &attr);
|
||||
if( res != 0 )
|
||||
{
|
||||
DPRINTFE("Failed to initialize mutex, error %d", res);
|
||||
error = SM_FAILED;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DPRINTFE("Failed to initialize mutex, NULL ptr");
|
||||
error = SM_FAILED;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
SmErrorT sm_mutex_finalize ( pthread_mutex_t* mutex )
|
||||
{
|
||||
SmErrorT error = SM_OKAY;
|
||||
if(mutex)
|
||||
{
|
||||
int res = pthread_mutex_destroy(mutex);
|
||||
if( res != 0 )
|
||||
{
|
||||
DPRINTFE("Failed to destroy mutex, error %d", res);
|
||||
error = SM_FAILED;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DPRINTFE("Failed to destroy mutex, NULL ptr");
|
||||
error = SM_FAILED;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
mutex_holder::mutex_holder(pthread_mutex_t* mutex)
|
||||
{
|
||||
this->_mutex = mutex;
|
||||
if( 0 != pthread_mutex_lock( this->_mutex ) )
|
||||
this->m_mutex = mutex;
|
||||
if( 0 != pthread_mutex_lock( this->m_mutex ) )
|
||||
{
|
||||
DPRINTFE("Critical error, failed to obtain the mutex. Quit...");
|
||||
abort();
|
||||
|
@ -20,7 +67,7 @@ mutex_holder::mutex_holder(pthread_mutex_t* mutex)
|
|||
|
||||
mutex_holder::~mutex_holder()
|
||||
{
|
||||
if( 0 != pthread_mutex_unlock( this->_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( this->m_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
|
|
@ -1,20 +1,34 @@
|
|||
//
|
||||
// Copyright (c) 2018 Wind River Systems, Inc.
|
||||
// Copyright (c) 2018,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
#ifndef __SM_UTIL_TYPES_H__
|
||||
#define __SM_UTIL_TYPES_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <pthread.h>
|
||||
#include "sm_types.h"
|
||||
|
||||
class mutex_holder
|
||||
{
|
||||
private:
|
||||
pthread_mutex_t* _mutex;
|
||||
pthread_mutex_t* m_mutex;
|
||||
public:
|
||||
mutex_holder(pthread_mutex_t* mutex);
|
||||
virtual ~mutex_holder();
|
||||
};
|
||||
|
||||
// ****************************************************************************
|
||||
// initialize mutex
|
||||
// ==============
|
||||
SmErrorT sm_mutex_initialize ( pthread_mutex_t* mutex, bool mutex_recursive );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// destroy mutex
|
||||
// ==============
|
||||
SmErrorT sm_mutex_finalize ( pthread_mutex_t* mutex );
|
||||
// ****************************************************************************
|
||||
|
||||
#endif //__SM_UTIL_TYPES_H__
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -8,8 +8,19 @@
|
|||
#include <pthread.h>
|
||||
|
||||
#include "sm_debug.h"
|
||||
#include "sm_util_types.h"
|
||||
|
||||
static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t fm_api_mutex;
|
||||
|
||||
SmErrorT fm_mutex_initialize ( void )
|
||||
{
|
||||
return sm_mutex_initialize(&fm_api_mutex, false);
|
||||
}
|
||||
|
||||
SmErrorT fm_mutex_finalize ( void )
|
||||
{
|
||||
return sm_mutex_finalize(&fm_api_mutex);
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
// FM Wrapper - FM Set Fault
|
||||
|
@ -18,7 +29,7 @@ EFmErrorT fm_set_fault_wrapper( const SFmAlarmDataT* alarm, fm_uuid_t* uuid )
|
|||
{
|
||||
EFmErrorT fm_error;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &fm_api_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( FM_ERR_NOCONNECT );
|
||||
|
@ -26,7 +37,7 @@ EFmErrorT fm_set_fault_wrapper( const SFmAlarmDataT* alarm, fm_uuid_t* uuid )
|
|||
|
||||
fm_error = fm_set_fault( alarm, uuid );
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &fm_api_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
@ -42,7 +53,7 @@ EFmErrorT fm_clear_fault_wrapper( AlarmFilter* filter )
|
|||
{
|
||||
EFmErrorT fm_error;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &fm_api_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( FM_ERR_NOCONNECT );
|
||||
|
@ -50,7 +61,7 @@ EFmErrorT fm_clear_fault_wrapper( AlarmFilter* filter )
|
|||
|
||||
fm_error = fm_clear_fault( filter );
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &fm_api_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
@ -66,7 +77,7 @@ EFmErrorT fm_clear_all_wrapper( fm_ent_inst_t* inst_id )
|
|||
{
|
||||
EFmErrorT fm_error;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &fm_api_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( FM_ERR_NOCONNECT );
|
||||
|
@ -74,7 +85,7 @@ EFmErrorT fm_clear_all_wrapper( fm_ent_inst_t* inst_id )
|
|||
|
||||
fm_error = fm_clear_all( inst_id );
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &fm_api_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
@ -90,7 +101,7 @@ EFmErrorT fm_get_fault_wrapper( AlarmFilter* filter, SFmAlarmDataT* alarm )
|
|||
{
|
||||
EFmErrorT fm_error;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &fm_api_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( FM_ERR_NOCONNECT );
|
||||
|
@ -98,7 +109,7 @@ EFmErrorT fm_get_fault_wrapper( AlarmFilter* filter, SFmAlarmDataT* alarm )
|
|||
|
||||
fm_error = fm_get_fault( filter, alarm );
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &fm_api_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
@ -115,7 +126,7 @@ EFmErrorT fm_get_faults_wrapper( fm_ent_inst_t* inst_id, SFmAlarmDataT* alarm,
|
|||
{
|
||||
EFmErrorT fm_error;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &fm_api_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( FM_ERR_NOCONNECT );
|
||||
|
@ -123,7 +134,7 @@ EFmErrorT fm_get_faults_wrapper( fm_ent_inst_t* inst_id, SFmAlarmDataT* alarm,
|
|||
|
||||
fm_error = fm_get_faults( inst_id, alarm, max_alarms_to_get );
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &fm_api_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
@ -140,7 +151,7 @@ EFmErrorT fm_get_faults_by_id_wrapper( fm_alarm_id* alarm_id,
|
|||
{
|
||||
EFmErrorT fm_error;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &fm_api_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( FM_ERR_NOCONNECT );
|
||||
|
@ -148,7 +159,7 @@ EFmErrorT fm_get_faults_by_id_wrapper( fm_alarm_id* alarm_id,
|
|||
|
||||
fm_error = fm_get_faults_by_id( alarm_id, alarm, max_alarms_to_get );
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &fm_api_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -8,6 +8,7 @@
|
|||
|
||||
|
||||
#include <fmAPI.h>
|
||||
#include "sm_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -27,6 +28,10 @@ extern EFmErrorT fm_clear_all_wrapper( fm_ent_inst_t *inst_id );
|
|||
extern EFmErrorT fm_get_fault_wrapper( AlarmFilter *filter,
|
||||
SFmAlarmDataT* alarm );
|
||||
|
||||
extern SmErrorT fm_mutex_initialize ( void );
|
||||
|
||||
extern SmErrorT fm_mutex_finalize ( void );
|
||||
|
||||
EFmErrorT fm_get_faults_wrapper( fm_ent_inst_t *inst_id,
|
||||
SFmAlarmDataT *alarm, unsigned int* max_alarms_to_get );
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -26,6 +26,7 @@
|
|||
#include "sm_time.h"
|
||||
#include "sm_node_utils.h"
|
||||
#include "sm_alarm_thread.h"
|
||||
#include "sm_util_types.h"
|
||||
|
||||
#define SM_ALARM_ENTRY_INUSE 0xA5A5A5A5
|
||||
|
||||
|
@ -51,7 +52,7 @@ typedef struct
|
|||
|
||||
static int _server_fd = -1;
|
||||
static int _client_fd = -1;
|
||||
static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t alarm_mutex;
|
||||
static SmAlarmEntryT _alarms[SM_ALARMS_MAX];
|
||||
|
||||
// ****************************************************************************
|
||||
|
@ -112,7 +113,7 @@ static bool sm_alarm_throttle( const SmAlarmT alarm, SmAlarmStateT alarm_state,
|
|||
bool throttle = false;
|
||||
SmAlarmEntryT* entry;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &alarm_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
abort();
|
||||
|
@ -167,7 +168,7 @@ static bool sm_alarm_throttle( const SmAlarmT alarm, SmAlarmStateT alarm_state,
|
|||
}
|
||||
|
||||
RELEASE_MUTEX:
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &alarm_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
abort();
|
||||
|
@ -569,7 +570,7 @@ void sm_alarm_clear_all( const SmAlarmDomainNameT domain_name )
|
|||
SmAlarmThreadMsgClearAllAlarmsT* clear_all_alarms = &(msg.u.clear_all_alarms);
|
||||
int result;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &alarm_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
abort();
|
||||
|
@ -577,7 +578,7 @@ void sm_alarm_clear_all( const SmAlarmDomainNameT domain_name )
|
|||
|
||||
memset( _alarms, 0, sizeof(_alarms) );
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &alarm_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
abort();
|
||||
|
@ -647,7 +648,9 @@ SmErrorT sm_alarm_initialize( void )
|
|||
DPRINTFD( "Alarm message size is %i bytes.",
|
||||
(int) sizeof(SmAlarmThreadMsgT) );
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
sm_mutex_initialize(&alarm_mutex, false);
|
||||
|
||||
if( 0 != pthread_mutex_lock( &alarm_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
abort();
|
||||
|
@ -655,7 +658,7 @@ SmErrorT sm_alarm_initialize( void )
|
|||
|
||||
memset( _alarms, 0, sizeof(_alarms) );
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &alarm_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
abort();
|
||||
|
@ -751,7 +754,7 @@ SmErrorT sm_alarm_finalize( void )
|
|||
_client_fd = -1;
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &alarm_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
abort();
|
||||
|
@ -759,12 +762,14 @@ SmErrorT sm_alarm_finalize( void )
|
|||
|
||||
memset( _alarms, 0, sizeof(_alarms) );
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &alarm_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
abort();
|
||||
}
|
||||
|
||||
sm_mutex_finalize(&alarm_mutex);
|
||||
|
||||
return( SM_OKAY );
|
||||
}
|
||||
// ****************************************************************************
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Wind River Systems, Inc.
|
||||
// Copyright (c) 2018,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -23,6 +23,7 @@
|
|||
#include "sm_selobj.h"
|
||||
#include "sm_worker_thread.h"
|
||||
#include "sm_node_utils.h"
|
||||
#include "sm_util_types.h"
|
||||
|
||||
// uncomment when debugging this module to enabled DPRINTFD output to log file
|
||||
// #define __DEBUG__MSG__
|
||||
|
@ -117,7 +118,7 @@ void log_cluster_hbs_state(const SmClusterHbsStateT& state)
|
|||
}
|
||||
}
|
||||
|
||||
pthread_mutex_t SmClusterHbsInfoMsg::_mutex;
|
||||
pthread_mutex_t SmClusterHbsInfoMsg::sm_cluster_hbs_mutex;
|
||||
const unsigned short Invalid_Req_Id = 0;
|
||||
int SmClusterHbsInfoMsg::_sock = -1;
|
||||
SmClusterHbsStateT SmClusterHbsInfoMsg::_cluster_hbs_state_current;
|
||||
|
@ -228,7 +229,7 @@ bool SmClusterHbsInfoMsg::_process_cluster_hbs_history(mtce_hbs_cluster_history_
|
|||
void SmClusterHbsInfoMsg::_cluster_hbs_info_msg_received( int selobj, int64_t user_data )
|
||||
{
|
||||
mtce_hbs_cluster_type msg = {0};
|
||||
mutex_holder holder(&_mutex);
|
||||
mutex_holder holder(&sm_cluster_hbs_mutex);
|
||||
while(true)
|
||||
{
|
||||
int bytes_read = recv( selobj, &msg, sizeof(msg), MSG_NOSIGNAL | MSG_DONTWAIT );
|
||||
|
@ -349,7 +350,7 @@ bool SmClusterHbsInfoMsg::cluster_hbs_info_query(cluster_hbs_query_ready_callbac
|
|||
unsigned short reqid;
|
||||
struct timespec ts;
|
||||
{
|
||||
mutex_holder holder(&_mutex);
|
||||
mutex_holder holder(&sm_cluster_hbs_mutex);
|
||||
if(alive_pulse)
|
||||
{
|
||||
reqid = 0;
|
||||
|
@ -473,14 +474,10 @@ SmErrorT SmClusterHbsInfoMsg::open_socket()
|
|||
SmErrorT SmClusterHbsInfoMsg::initialize()
|
||||
{
|
||||
SmErrorT error;
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
int res = pthread_mutex_init(&_mutex, &attr);
|
||||
if( 0 != res )
|
||||
error = sm_mutex_initialize(&sm_cluster_hbs_mutex, true);
|
||||
if( error != SM_OKAY )
|
||||
{
|
||||
DPRINTFE("Failed to initialize mutex, error %d", res);
|
||||
return SM_FAILED;
|
||||
}
|
||||
|
||||
|
@ -530,13 +527,15 @@ SmErrorT SmClusterHbsInfoMsg::initialize()
|
|||
|
||||
SmErrorT SmClusterHbsInfoMsg::finalize()
|
||||
{
|
||||
mutex_holder holder(&_mutex);
|
||||
{
|
||||
mutex_holder holder(&sm_cluster_hbs_mutex);
|
||||
if(_sock > 0)
|
||||
{
|
||||
close(_sock);
|
||||
_sock = -1;
|
||||
}
|
||||
pthread_mutex_destroy(&_mutex);
|
||||
}
|
||||
pthread_mutex_destroy(&sm_cluster_hbs_mutex);
|
||||
return SM_OKAY;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Wind River Systems, Inc.
|
||||
// Copyright (c) 2018,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -86,7 +86,7 @@ class SmClusterHbsInfoMsg
|
|||
private:
|
||||
static int _sock;
|
||||
static unsigned short _last_reqid;
|
||||
static pthread_mutex_t _mutex;
|
||||
static pthread_mutex_t sm_cluster_hbs_mutex;
|
||||
static SmClusterHbsStateT _cluster_hbs_state_current;
|
||||
static SmClusterHbsStateT _cluster_hbs_state_previous;
|
||||
static hbs_query_respond_callback _callbacks;
|
||||
|
|
|
@ -139,7 +139,7 @@ static SmFailoverInterfaceInfo* _mgmt_interface_info = NULL;
|
|||
static SmFailoverInterfaceInfo* _cluster_host_interface_info = NULL;
|
||||
static SmFailoverInterfaceInfo* _admin_interface_info = NULL;
|
||||
static SmFailoverInterfaceInfo _peer_if_list[SM_INTERFACE_MAX];
|
||||
static pthread_mutex_t _mutex;
|
||||
static pthread_mutex_t sm_failover_mutex;
|
||||
static SmDbHandleT* _sm_db_handle = NULL;
|
||||
|
||||
static SmNodeScheduleStateT _host_state;
|
||||
|
@ -160,6 +160,16 @@ SmErrorT sm_exec_json_command(const char* cmd, char result_buf[], int result_len
|
|||
SmErrorT sm_failover_get_node_oper_state(char* node_name, SmNodeOperationalStateT *state);
|
||||
void _log_nodes_state();
|
||||
|
||||
SmErrorT sm_failover_mutex_initialize ( void )
|
||||
{
|
||||
return sm_mutex_initialize(&sm_failover_mutex, true);
|
||||
}
|
||||
|
||||
SmErrorT sm_failover_mutex_finalize ( void )
|
||||
{
|
||||
return sm_mutex_finalize(&sm_failover_mutex);
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
// Failover - interface check
|
||||
// ==================
|
||||
|
@ -254,7 +264,7 @@ static SmFailoverInterfaceInfo* find_interface_info( SmFailoverInterfaceT* inter
|
|||
// ==================
|
||||
void sm_failover_lost_hello_msg()
|
||||
{
|
||||
mutex_holder holder(&_mutex);
|
||||
mutex_holder holder(&sm_failover_mutex);
|
||||
|
||||
if(_hello_msg_alive)
|
||||
{
|
||||
|
@ -268,7 +278,7 @@ void sm_failover_lost_hello_msg()
|
|||
// ==================
|
||||
void sm_failover_hello_msg_restore()
|
||||
{
|
||||
mutex_holder holder(&_mutex);
|
||||
mutex_holder holder(&sm_failover_mutex);
|
||||
|
||||
SmFailoverInterfaceInfo* iter;
|
||||
for(iter = _my_if_list; iter < _end_of_list; iter ++)
|
||||
|
@ -287,7 +297,7 @@ void sm_failover_hello_msg_restore()
|
|||
// ==================
|
||||
void sm_failover_lost_heartbeat( SmFailoverInterfaceT* interface )
|
||||
{
|
||||
mutex_holder holder(&_mutex);
|
||||
mutex_holder holder(&sm_failover_mutex);
|
||||
|
||||
SmFailoverInterfaceInfo* if_info = find_interface_info( interface );
|
||||
if ( NULL == if_info )
|
||||
|
@ -319,7 +329,7 @@ void sm_failover_lost_heartbeat( SmFailoverInterfaceT* interface )
|
|||
// ==================
|
||||
void sm_failover_heartbeat_restore( SmFailoverInterfaceT* interface )
|
||||
{
|
||||
mutex_holder holder(&_mutex);
|
||||
mutex_holder holder(&sm_failover_mutex);
|
||||
|
||||
SmFailoverInterfaceInfo* if_info = find_interface_info( interface );
|
||||
if ( NULL == if_info )
|
||||
|
@ -364,7 +374,7 @@ void sm_failover_heartbeat_restore( SmFailoverInterfaceT* interface )
|
|||
// ==================
|
||||
void sm_failover_interface_down( const char* const interface_name )
|
||||
{
|
||||
mutex_holder holder(&_mutex);
|
||||
mutex_holder holder(&sm_failover_mutex);
|
||||
|
||||
SmFailoverInterfaceInfo* iter;
|
||||
int impacted = 0;
|
||||
|
@ -398,7 +408,7 @@ void sm_failover_interface_down( const char* const interface_name )
|
|||
// ==================
|
||||
void sm_failover_interface_up( const char* const interface_name )
|
||||
{
|
||||
mutex_holder holder(&_mutex);
|
||||
mutex_holder holder(&sm_failover_mutex);
|
||||
|
||||
SmFailoverInterfaceInfo* iter;
|
||||
int impacted = 0;
|
||||
|
@ -468,7 +478,7 @@ void sm_failover_if_state_update(const char node_name[], SmHeartbeatMsgIfStateT
|
|||
{
|
||||
if( 0 == strcmp(node_name, _peer_name) )
|
||||
{
|
||||
mutex_holder holder(&_mutex);
|
||||
mutex_holder holder(&sm_failover_mutex);
|
||||
|
||||
if( _peer_if_state != if_state )
|
||||
{
|
||||
|
@ -575,7 +585,7 @@ int sm_failover_get_if_state()
|
|||
// ==================
|
||||
SmHeartbeatMsgIfStateT sm_failover_if_state_get()
|
||||
{
|
||||
mutex_holder holder(&_mutex);
|
||||
mutex_holder holder(&sm_failover_mutex);
|
||||
int if_state_flag = sm_failover_get_if_state();
|
||||
return (if_state_flag & 0b0111); //the lower 3 bits i/f state flag
|
||||
}
|
||||
|
@ -586,7 +596,7 @@ SmHeartbeatMsgIfStateT sm_failover_if_state_get()
|
|||
// ==================
|
||||
SmHeartbeatMsgIfStateT sm_failover_get_peer_if_state()
|
||||
{
|
||||
mutex_holder holder(&_mutex);
|
||||
mutex_holder holder(&sm_failover_mutex);
|
||||
|
||||
return (_peer_if_state & 0b0111); //the lower 3 bits i/f state flag
|
||||
}
|
||||
|
@ -993,7 +1003,7 @@ SmErrorT sm_failover_set_system(const SmSystemFailoverStatus& failover_status)
|
|||
// =======================
|
||||
void sm_failover_audit()
|
||||
{
|
||||
mutex_holder holder(&_mutex);
|
||||
mutex_holder holder(&sm_failover_mutex);
|
||||
|
||||
timespec now;
|
||||
time_t now_ms;
|
||||
|
@ -1291,17 +1301,6 @@ SmErrorT sm_failover_initialize( void )
|
|||
bool enabled;
|
||||
SmErrorT error;
|
||||
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
int res = pthread_mutex_init(&_mutex, &attr);
|
||||
if( 0 != res )
|
||||
{
|
||||
DPRINTFE("Failed to initialize mutex, error %d", res);
|
||||
return SM_FAILED;
|
||||
}
|
||||
|
||||
error = SmFailoverFSM::initialize();
|
||||
if( SM_OKAY != error )
|
||||
{
|
||||
|
@ -1460,7 +1459,6 @@ SmErrorT sm_failover_finalize( void )
|
|||
DPRINTFE( "Failed to finalize failover FSM, error %s.", sm_error_str( error ) );
|
||||
}
|
||||
|
||||
pthread_mutex_destroy(&_mutex);
|
||||
return SM_OKAY;
|
||||
}
|
||||
// ****************************************************************************
|
||||
|
|
|
@ -40,6 +40,18 @@ typedef enum
|
|||
SM_FAILOVER_PEER_DISABLED = 0x4000,
|
||||
}SmFailoverCommFaultBitFlagT;
|
||||
|
||||
// ****************************************************************************
|
||||
// initialize mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_failover_mutex_initialize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// destroy mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_failover_mutex_finalize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// Failover - check
|
||||
// ==================
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "sm_log.h"
|
||||
#include "sm_failover.h"
|
||||
#include "sm_cluster_hbs_info_msg.h"
|
||||
#include "sm_util_types.h"
|
||||
|
||||
#define SM_HEARTBEAT_THREAD_NAME "sm_heartbeat"
|
||||
#define SM_HEARTBEAT_THREAD_TICK_INTERVAL_IN_MS 100
|
||||
|
@ -96,7 +97,7 @@ typedef struct
|
|||
|
||||
static sig_atomic_t _stay_on;
|
||||
static bool _thread_created = false;
|
||||
static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t heartbeat_mutex;
|
||||
static pthread_t _heartbeat_thread;
|
||||
static sig_atomic_t _messaging_enabled = 0;
|
||||
static sig_atomic_t _heartbeat_required = 1;
|
||||
|
@ -129,6 +130,17 @@ static bool operator != ( const SmNetworkAddressT& src, const SmNetworkAddressT&
|
|||
}
|
||||
// ****************************************************************************
|
||||
|
||||
SmErrorT sm_heartbeat_thread_mutex_initialize ( void )
|
||||
{
|
||||
return sm_mutex_initialize(&heartbeat_mutex, false);
|
||||
}
|
||||
|
||||
SmErrorT sm_heartbeat_thread_mutex_finalize ( void )
|
||||
{
|
||||
return sm_mutex_finalize(&heartbeat_mutex);
|
||||
}
|
||||
|
||||
|
||||
// ****************************************************************************
|
||||
// Heartbeat Thread - Disable heartbeat
|
||||
// =========================
|
||||
|
@ -200,7 +212,7 @@ SmErrorT sm_heartbeat_thread_add_interface( const SmServiceDomainInterfaceT& dom
|
|||
SmHeartbeatThreadInterfaceT* interface;
|
||||
SmErrorT error;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -307,7 +319,7 @@ SmErrorT sm_heartbeat_thread_add_interface( const SmServiceDomainInterfaceT& dom
|
|||
interface->interface_name );
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -316,7 +328,7 @@ SmErrorT sm_heartbeat_thread_add_interface( const SmServiceDomainInterfaceT& dom
|
|||
return( SM_OKAY );
|
||||
|
||||
ERROR:
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -333,7 +345,7 @@ SmErrorT sm_heartbeat_thread_delete_interface( int64_t id )
|
|||
{
|
||||
SmHeartbeatThreadInterfaceT* interface;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -347,7 +359,7 @@ SmErrorT sm_heartbeat_thread_delete_interface( int64_t id )
|
|||
free( interface );
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -442,7 +454,7 @@ static bool sm_heartbeat_peer_alarm_on_interface( SmTimerIdT timer_id,
|
|||
return( true );
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( true );
|
||||
|
@ -579,7 +591,7 @@ static bool sm_heartbeat_peer_alarm_on_interface( SmTimerIdT timer_id,
|
|||
sm_log_communication_state_change( network_type, peer_interface->log_text );
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
@ -587,7 +599,7 @@ static bool sm_heartbeat_peer_alarm_on_interface( SmTimerIdT timer_id,
|
|||
return( true );
|
||||
|
||||
ERROR:
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
@ -613,7 +625,7 @@ SmErrorT sm_heartbeat_thread_add_peer_interface( int64_t id,
|
|||
return( SM_OKAY );
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -664,7 +676,7 @@ SmErrorT sm_heartbeat_thread_add_peer_interface( int64_t id,
|
|||
(SmListEntryDataPtrT) peer_interface );
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -673,7 +685,7 @@ SmErrorT sm_heartbeat_thread_add_peer_interface( int64_t id,
|
|||
return( SM_OKAY );
|
||||
|
||||
ERROR:
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -692,7 +704,7 @@ SmErrorT sm_heartbeat_thread_delete_peer_interface( char interface_name[],
|
|||
SmHeartbeatThreadPeerInterfaceT* peer_interface;
|
||||
SmErrorT error;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -722,7 +734,7 @@ SmErrorT sm_heartbeat_thread_delete_peer_interface( char interface_name[],
|
|||
free( peer_interface );
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -765,7 +777,7 @@ bool sm_heartbeat_thread_peer_alive_in_period( char node_name[],
|
|||
bool peer_alive = false;
|
||||
SmHeartbeatThreadPeerNodeT* peer_node;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( true );
|
||||
|
@ -781,7 +793,7 @@ bool sm_heartbeat_thread_peer_alive_in_period( char node_name[],
|
|||
peer_alive = ( period_in_ms >= ms_expired );
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
@ -800,7 +812,7 @@ static bool sm_heartbeat_alive_timer( SmTimerIdT timer_id, int64_t user_data )
|
|||
SmHeartbeatThreadInterfaceT* interface;
|
||||
SmErrorT error;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( true );
|
||||
|
@ -965,7 +977,7 @@ static bool sm_heartbeat_alive_timer( SmTimerIdT timer_id, int64_t user_data )
|
|||
}
|
||||
|
||||
DONE:
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( true );
|
||||
|
@ -987,7 +999,7 @@ static bool sm_heartbeat_thread_auth_message( char interface_name[],
|
|||
SmHeartbeatThreadInterfaceT* interface;
|
||||
SmSha512HashT hash;
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( true );
|
||||
|
@ -1020,7 +1032,7 @@ static bool sm_heartbeat_thread_auth_message( char interface_name[],
|
|||
|
||||
|
||||
DONE:
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return( true );
|
||||
|
@ -1041,7 +1053,7 @@ static void sm_heartbeat_thread_receive_alive_message( char node_name[],
|
|||
|
||||
DPRINTFD( "Received alive message from node (%s).", node_name );
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return;
|
||||
|
@ -1095,7 +1107,7 @@ static void sm_heartbeat_thread_receive_alive_message( char node_name[],
|
|||
}
|
||||
|
||||
DONE:
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &heartbeat_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
return;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014-2017 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014-2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -16,6 +16,18 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ****************************************************************************
|
||||
// initialize mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_heartbeat_thread_mutex_initialize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// destroy mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_heartbeat_thread_mutex_finalize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// Heartbeat Thread - Disable heartbeat
|
||||
// =========================
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -43,6 +43,7 @@
|
|||
#include "sm_service_group_api.h"
|
||||
#include "sm_service_api.h"
|
||||
#include "sm_service_action.h"
|
||||
#include "sm_service_enable.h"
|
||||
#include "sm_service_heartbeat_api.h"
|
||||
#include "sm_service_heartbeat_thread.h"
|
||||
#include "sm_service_domain_scheduler.h"
|
||||
|
@ -55,6 +56,8 @@
|
|||
#include "sm_worker_thread.h"
|
||||
#include "sm_configuration_table.h"
|
||||
#include "sm_cluster_hbs_info_msg.h"
|
||||
#include "fm_api_wrapper.h"
|
||||
#include "sm_swact_state.h"
|
||||
|
||||
#define SM_PROCESS_DB_CHECKPOINT_INTERVAL_IN_MS 30000
|
||||
#define SM_PROCESS_TICK_INTERVAL_IN_MS 200
|
||||
|
@ -170,6 +173,18 @@ static SmErrorT sm_process_initialize( void )
|
|||
{
|
||||
SmErrorT error;
|
||||
|
||||
// mutexes
|
||||
fm_mutex_initialize();
|
||||
sm_failover_mutex_initialize();
|
||||
sm_service_enable_mutex_initialize();
|
||||
sm_swact_state_mutex_initialize();
|
||||
sm_service_heartbeat_api_mutex_initialize();
|
||||
sm_heartbeat_thread_mutex_initialize();
|
||||
sm_thread_health_mutex_initialize();
|
||||
sm_selobj_mutex_initialize();
|
||||
sm_timer_mutex_initialize();
|
||||
sm_hw_mutex_initialize();
|
||||
|
||||
error = sm_selobj_initialize();
|
||||
if( SM_OKAY != error )
|
||||
{
|
||||
|
@ -538,6 +553,18 @@ static SmErrorT sm_process_finalize( void )
|
|||
sm_error_str( error ) );
|
||||
}
|
||||
|
||||
// mutexes
|
||||
fm_mutex_finalize();
|
||||
sm_failover_mutex_finalize();
|
||||
sm_service_enable_mutex_finalize();
|
||||
sm_swact_state_mutex_finalize();
|
||||
sm_service_heartbeat_api_mutex_finalize();
|
||||
sm_heartbeat_thread_mutex_finalize();
|
||||
sm_thread_health_mutex_finalize();
|
||||
sm_selobj_mutex_finalize();
|
||||
sm_timer_mutex_finalize();
|
||||
sm_hw_mutex_finalize();
|
||||
|
||||
return( SM_OKAY );
|
||||
}
|
||||
// ****************************************************************************
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -29,7 +29,7 @@
|
|||
#define EXTRA_CORES_STORAGE "/etc/platform/.task_affining_incomplete"
|
||||
#define PLATFORM_CORES_FILE "/var/run/sm/.platform_cores"
|
||||
|
||||
static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t sm_service_enable_mutex;
|
||||
static sem_t sem;
|
||||
static int num_initial_cores = 0;
|
||||
static sem_t sem_more_cores;
|
||||
|
@ -37,13 +37,22 @@ static bool check_more_cores_available = false;
|
|||
static bool more_cores_available = false;
|
||||
static int num_extra_cores = 0;
|
||||
|
||||
SmErrorT sm_service_enable_mutex_initialize ( void )
|
||||
{
|
||||
return sm_mutex_initialize(&sm_service_enable_mutex, false);
|
||||
}
|
||||
|
||||
SmErrorT sm_service_enable_mutex_finalize ( void )
|
||||
{
|
||||
return sm_mutex_finalize(&sm_service_enable_mutex);
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
// add more cores for enabling service
|
||||
// ==============
|
||||
void sm_service_enable_throttle_add_cores( bool additional_cores )
|
||||
{
|
||||
mutex_holder holder(&_mutex);
|
||||
mutex_holder holder(&sm_service_enable_mutex);
|
||||
|
||||
check_more_cores_available = additional_cores;
|
||||
if (!additional_cores)
|
||||
|
@ -661,7 +670,7 @@ bool sm_service_enable_throttle_check( void )
|
|||
return true;
|
||||
} else if( EAGAIN == errno )
|
||||
{
|
||||
mutex_holder holder(&_mutex);
|
||||
mutex_holder holder(&sm_service_enable_mutex);
|
||||
if(check_more_cores_available)
|
||||
{
|
||||
int new_num_platform_cores = get_extra_cores();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -13,6 +13,18 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ****************************************************************************
|
||||
// initialize mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_service_enable_mutex_initialize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// destroy mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_service_enable_mutex_finalize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// add more cores for enabling service
|
||||
// ==============
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -19,6 +19,7 @@
|
|||
#include "sm_list.h"
|
||||
#include "sm_selobj.h"
|
||||
#include "sm_timer.h"
|
||||
#include "sm_util_types.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -79,7 +80,17 @@ typedef struct
|
|||
static int _sm_heartbeat_api_server_fd = -1;
|
||||
static int _sm_heartbeat_api_client_fd = -1;
|
||||
static SmListT* _callbacks = NULL;
|
||||
static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t heartbeat_callback_mutex;
|
||||
|
||||
SmErrorT sm_service_heartbeat_api_mutex_initialize ( void )
|
||||
{
|
||||
return sm_mutex_initialize(&heartbeat_callback_mutex, true); // PTHREAD_MUTEX_RECURSIVE
|
||||
}
|
||||
|
||||
SmErrorT sm_service_heartbeat_api_mutex_finalize ( void )
|
||||
{
|
||||
return sm_mutex_finalize(&heartbeat_callback_mutex);
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
// Service Heartbeat API - Register Callbacks
|
||||
|
@ -87,7 +98,7 @@ static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
|
|||
SmErrorT sm_service_heartbeat_api_register_callbacks(
|
||||
SmServiceHeartbeatCallbacksT* callbacks )
|
||||
{
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &heartbeat_callback_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -95,7 +106,7 @@ SmErrorT sm_service_heartbeat_api_register_callbacks(
|
|||
|
||||
SM_LIST_PREPEND( _callbacks, (SmListEntryDataPtrT) callbacks );
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &heartbeat_callback_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
@ -110,7 +121,7 @@ SmErrorT sm_service_heartbeat_api_register_callbacks(
|
|||
SmErrorT sm_service_heartbeat_api_deregister_callbacks(
|
||||
SmServiceHeartbeatCallbacksT* callbacks )
|
||||
{
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &heartbeat_callback_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return( SM_FAILED );
|
||||
|
@ -118,7 +129,7 @@ SmErrorT sm_service_heartbeat_api_deregister_callbacks(
|
|||
|
||||
SM_LIST_REMOVE( _callbacks, (SmListEntryDataPtrT) callbacks );
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &heartbeat_callback_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
@ -317,7 +328,7 @@ static void sm_service_heartbeat_api_dispatch( int selobj, int64_t user_data )
|
|||
return;
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_lock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_lock( &heartbeat_callback_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to capture mutex." );
|
||||
return;
|
||||
|
@ -378,7 +389,7 @@ static void sm_service_heartbeat_api_dispatch( int selobj, int64_t user_data )
|
|||
}
|
||||
}
|
||||
|
||||
if( 0 != pthread_mutex_unlock( &_mutex ) )
|
||||
if( 0 != pthread_mutex_unlock( &heartbeat_callback_mutex ) )
|
||||
{
|
||||
DPRINTFE( "Failed to release mutex." );
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -31,6 +31,18 @@ typedef struct
|
|||
SmServiceHeartbeatFailCallbackT fail_callback;
|
||||
} SmServiceHeartbeatCallbacksT;
|
||||
|
||||
// ****************************************************************************
|
||||
// initialize mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_service_heartbeat_api_mutex_initialize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// destroy mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_service_heartbeat_api_mutex_finalize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// Service Heartbeat API - Register Callbacks
|
||||
// ==========================================
|
||||
|
|
|
@ -1,12 +1,24 @@
|
|||
// Copyright (c) 2017 Wind River Systems, Inc.
|
||||
// Copyright (c) 2017,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
#include "sm_swact_state.h"
|
||||
#include "pthread.h"
|
||||
#include "sm_debug.h"
|
||||
#include "sm_util_types.h"
|
||||
|
||||
volatile SmSwactStateT _swact_state = SM_SWACT_STATE_NONE;
|
||||
static pthread_mutex_t _state_mutex;
|
||||
static pthread_mutex_t swact_state_mutex;
|
||||
|
||||
SmErrorT sm_swact_state_mutex_initialize ( void )
|
||||
{
|
||||
return sm_mutex_initialize(&swact_state_mutex, false);
|
||||
}
|
||||
|
||||
SmErrorT sm_swact_state_mutex_finalize ( void )
|
||||
{
|
||||
return sm_mutex_finalize(&swact_state_mutex);
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
// Swact State - Swact State Setter
|
||||
|
@ -14,9 +26,9 @@ static pthread_mutex_t _state_mutex;
|
|||
void sm_set_swact_state(SmSwactStateT state)
|
||||
{
|
||||
// The state is set by sm main thread and task affining thread.
|
||||
pthread_mutex_lock(&_state_mutex);
|
||||
pthread_mutex_lock(&swact_state_mutex);
|
||||
_swact_state = state;
|
||||
pthread_mutex_unlock(&_state_mutex);
|
||||
pthread_mutex_unlock(&swact_state_mutex);
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
//
|
||||
// Copyright (c) 2017 Wind River Systems, Inc.
|
||||
// Copyright (c) 2017,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
#ifndef __SM_SWACT_STATE_H__
|
||||
#define __SM_SWACT_STATE_H__
|
||||
|
||||
#include "sm_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -17,6 +19,18 @@ typedef enum
|
|||
SM_SWACT_STATE_END,
|
||||
} SmSwactStateT;
|
||||
|
||||
// ****************************************************************************
|
||||
// initialize mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_swact_state_mutex_initialize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// destroy mutex
|
||||
// ==============
|
||||
extern SmErrorT sm_swact_state_mutex_finalize ( void );
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
// Swact State - Setter
|
||||
// ==========================================
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Wind River Systems, Inc.
|
||||
// Copyright (c) 2018,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -73,7 +73,7 @@ SmErrorT SmWorkerThread::finalize()
|
|||
// ****************************************************************************
|
||||
SmWorkerThread::SmWorkerThread() : _priority_queue(), _regular_queue()
|
||||
{
|
||||
this->_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
sm_mutex_initialize(&this->sm_action_mutex, false);
|
||||
this->_goon = true;
|
||||
this->_thread_created = false;
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ SmWorkerThread::SmWorkerThread() : _priority_queue(), _regular_queue()
|
|||
SmWorkerThread::~SmWorkerThread()
|
||||
{
|
||||
sem_destroy(&this->_sem);
|
||||
sm_mutex_finalize(&this->sm_action_mutex);
|
||||
}
|
||||
// ****************************************************************************
|
||||
|
||||
|
@ -157,7 +158,7 @@ SmErrorT SmWorkerThread::stop()
|
|||
// ****************************************************************************
|
||||
void SmWorkerThread::add_action(SmAction* action)
|
||||
{
|
||||
mutex_holder(&this->_mutex);
|
||||
mutex_holder(&this->sm_action_mutex);
|
||||
this->_regular_queue.push(action);
|
||||
int res = sem_post(&_sem);
|
||||
if(0 != res)
|
||||
|
@ -174,7 +175,7 @@ void SmWorkerThread::add_action(SmAction* action)
|
|||
// ****************************************************************************
|
||||
void SmWorkerThread::add_priority_action(SmAction* action)
|
||||
{
|
||||
mutex_holder(&this->_mutex);
|
||||
mutex_holder(&this->sm_action_mutex);
|
||||
this->_priority_queue.push(action);
|
||||
int res = sem_post(&_sem);
|
||||
if(0 != res)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Wind River Systems, Inc.
|
||||
// Copyright (c) 2018,2023 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
@ -66,7 +66,7 @@ class SmWorkerThread
|
|||
static SmErrorT finalize();
|
||||
|
||||
private:
|
||||
pthread_mutex_t _mutex;
|
||||
pthread_mutex_t sm_action_mutex;
|
||||
SmActionQueueT _priority_queue;
|
||||
SmActionQueueT _regular_queue;
|
||||
sem_t _sem;
|
||||
|
|
Loading…
Reference in New Issue