48#include <sys/signal.h>
52#include <sys/signalfd.h>
84#define LOCK_BANNER "[LOCK]"
87#define THD_CLEANUP_PHASE1 TRUE
88#define THD_CLEANUP_PHASE2 FALSE
91#define THD_STRICT_LOOKUP TRUE
92#define THD_SIMPLE_LOOKUP !THD_STRICT_LOOKUP
94#define NULL_PTHREAD (pthread_t)NULL
100#define MAINLINE_SID 0
103#define NULL_SID SES_NULL_SID
107#define THD_CAP_CANCEL_CC bit0
108#define THD_CAP_NEXT_AVAIL bit1
110#define THD_INC_THD_CNT ENTER_FAST_CS; \
114#define THD_DEC_THD_CNT ENTER_FAST_CS; \
119#define THD_SIGNAL SIGVTALRM
121#define THD_SIGNAL SIGTERM
124#define THD_LOGROTATE_SIG SIGUSR2
145typedef boolean (*test_cdx_void_t) (void);
146typedef boolean (*test_cdx_int_t) (int);
149typedef enum thd_tcb_state_t_ {
157#define THD_TCB_STATE_MIN (THD_TCB_STATE_NONE + 1)
158#define THD_TCB_STATE_MAX (THD_TCB_STATE_LIMIT - 1)
161typedef enum thd_type_t_ {
171#define THD_TYPE_MIN (THD_TYPE_NONE + 1)
172#define THD_TYPE_MAX (THD_TYPE_LIMIT - 1)
175typedef struct thd_tcb_t_ {
237 struct agt_not_subscription_t_ *
sub;
249extern boolean thd_init_called;
250extern boolean thd_init_successful;
252extern int thread_count;
253extern boolean thd_cs_mutex_init;
255extern pthread_attr_t pthread_attr;
305 test_cdx_int_t sid_test_func);
status_t
global error return code
Definition: status_enum.h:210
ses_term_reason_t
Session Termination reason.
Definition: ses.h:417
uint32 ses_id_t
Session ID.
Definition: ses.h:335
status_t thd_module_db_wrlock(thd_tcb_t *tcb)
Request write access to the module DB ("object tree").
Definition: thd.c:1399
thd_tcb_t * thd_find_tcb_by_handle(pthread_t handle)
Find a thread by its OS pthread handle.
Definition: thd.c:757
ses_id_t thd_find_sess_id(void)
Find the session ID represented by the current thread.
Definition: thd.c:951
void thd_shutdown(void)
Begin thread ermination by signalling.
Definition: thd.c:1817
thd_tcb_t * thd_get_first_tcb(void)
Get the first thread control block.
Definition: thd.c:2003
int thd_lock_recursive_log_cs_mutex(void)
Request lock on recursive logger CS (critical section) mutex.
Definition: thd.c:1219
void thd_set_main_handle(void)
Record the thread handle of "main" (running initially before any threads are created) for reference.
Definition: thd.c:502
ses_id_t thd_find_sess_id_by_handle(pthread_t handle)
Find the session ID represented by the thread handle.
Definition: thd.c:912
void thd_get_ids(int *tid, ses_id_t *sid)
Return the TID and SID of the current running thread.
Definition: thd.c:1025
int thd_unlock_ses_sync_mutex(void)
Unlock session sync mutex (enforce session synchronization)
Definition: thd.c:1112
void thd_cleanup(boolean phase1)
Terminate threads and deallocate associated resources, including thread control blocks.
Definition: thd.c:1864
void thd_check_shutdown_signal(sigset_t *sigmask, thd_tcb_t *tcb)
The agt_shutdown_requested == TRUE at this point.
Definition: thd.c:1767
thd_tcb_t * thd_new_tcb(thd_type_t type)
Allocate a new thread control block.
Definition: thd.c:548
void thd_set_ready(void)
Netconfd will set thd_ready when initialization is complete, but before creating threads.
Definition: thd.c:528
int thd_unlock_recursive_log_cs_mutex(void)
Unlock recursive logger CS (critical section) mutex.
Definition: thd.c:1252
int thd_unlock_inreadyQ_mutex(ses_id_t sid)
Unlock mutex for access to the inreadyQ (pending input).
Definition: thd.c:1312
boolean thd_rcv_signal_setup(sigset_t *sigmask, thd_tcb_t *tcb)
Init thread to receive omnibus signal.
Definition: thd.c:1710
void thd_mark_tcb_deleted(thd_tcb_t *tcb)
Cleanup (release resources associated with a TCB) and free it.
Definition: thd.c:661
status_t thd_module_db_unlock(thd_tcb_t *tcb)
Unlock (release access) to the module DB ("object tree").
Definition: thd.c:1453
thd_tcb_t * thd_find_tcb_by_sid(ses_id_t sid, boolean strict)
Lookup TCB by session ID.
Definition: thd.c:708
int thd_count_ses_threads(void)
Count the number of session threads.
Definition: thd.c:871
int thd_lock_ses_sync_mutex(void)
Request lock on session sync mutex (enforce session synchronization)
Definition: thd.c:1072
int thd_find_thread_id(void)
Find the thread ID represented by the current thread.
Definition: thd.c:972
thd_tcb_t * thd_get_thread_tcb(void)
Return the TCB of the current thread.
Definition: thd.c:998
boolean thd_yield_for_cdx(int max_yield_count, uint usec, int ival, test_cdx_int_t sid_test_func)
Yield scheduler in loop until specified condition(s) are met or max loop count is exceeded.
Definition: thd.c:1616
void thd_set_main_pthread_attr(void)
Set/display main pthread attributes, to be inherited by all threads, unless otherwise noted.
Definition: thd.c:413
status_t thd_master_init(void)
Initialize all mutexes for use by threads.
Definition: thd.c:1506
thd_tcb_t * thd_find_tcb_by_type(thd_type_t type)
Find a TCB supporting the specified type.
Definition: thd.c:833
status_t thd_module_db_rdlock(thd_tcb_t *tcb)
Request read access to the module DB ("object tree")
Definition: thd.c:1344
thd_type_t
Thread types.
Definition: thd.h:161
void thd_clear_locks(thd_tcb_t *tcb)
Clear mutexes and RWLOCKs prior to termination.
Definition: thd.c:584
thd_tcb_t * thd_find_tcb_by_capability(uint cap)
Find a TCB supporting the specified capability.
Definition: thd.c:795
thd_tcb_state_t
Thread (tcb) states.
Definition: thd.h:149
int thd_lock_inreadyQ_mutex(ses_id_t sid)
Request mutex lock for access to the inreadyQ (pending input).
Definition: thd.c:1281
thd_tcb_t * thd_get_next_tcb(thd_tcb_t *tcb)
Get the next thread control block from the specified entry.
Definition: thd.c:2021
@ THD_TYPE_DUMMY
Dummy session TCB.
Definition: thd.h:167
@ THD_TYPE_NONE
not set
Definition: thd.h:162
@ THD_TYPE_SES
Session (rx_thread)
Definition: thd.h:166
@ THD_TYPE_CONN
Connection.
Definition: thd.h:164
@ THD_TYPE_BKGD
Background.
Definition: thd.h:163
@ THD_TYPE_TMR
Timer.
Definition: thd.h:165
@ THD_TCB_STATE_INACTIVE
Phase 1 cleanup done - ready to reuse.
Definition: thd.h:152
@ THD_TCB_STATE_NONE
not set
Definition: thd.h:150
@ THD_TCB_STATE_ACTIVE
active
Definition: thd.h:151
@ THD_TCB_STATE_DELETED
Phase 2 cleanup done - ready to free
Definition: thd.h:153
ncx_confirm_event_t
type of confirmEvent in the sysConfirmedCommit notification Used in confirmed-commit standard as well
Definition: ncxtypes.h:1515
#define NCX_CFGID_CNT
Should match CFG_NUM_STATIC.
Definition: ncxtypes.h:557
NETCONF Session Common definitions module.
Global error messages for status code enumerations.
Session Control Block.
Definition: ses.h:573
Thread control block (TCB)
Definition: thd.h:175
thd_tcb_state_t state
thread state
Definition: thd.h:178
int sleep
sleep amount
Definition: thd.h:191
ses_id_t sid
Session ID of thread.
Definition: thd.h:184
boolean module_db_locked
module with datastores loads
Definition: thd.h:217
struct agt_not_subscription_t_ * sub
sub is used for RFC 5277 notifications only There will be 0 or 1 of these fields used
Definition: thd.h:237
boolean snmp_notif
1 subscription allowed
Definition: thd.h:238
dlq_hdr_t qhdr
queue header
Definition: thd.h:177
ses_id_t killedby
kill session done
Definition: thd.h:223
int fd
I/O file descriptor.
Definition: thd.h:188
thd_type_t thd_type
thread type
Definition: thd.h:180
fd_set tcb_fd_set
FDs used by thread.
Definition: thd.h:190
boolean cancel_cc
cancel confirmed-commit flag
Definition: thd.h:229
ncx_confirm_event_t cancel_cc_event
confirm-commit event
Definition: thd.h:232
pthread_t handle
Internal thread handle.
Definition: thd.h:179
boolean kill_session
kill session requested
Definition: thd.h:220
int tid
thread ID
Definition: thd.h:186
const char * name
thread name
Definition: thd.h:182
ses_cb_t * dscb
Dummy SCB, if any.
Definition: thd.h:183
uint thd_cap
Capability bits.
Definition: thd.h:181
ses_term_reason_t termreason
termination reason
Definition: thd.h:226
int run
internal run state
Definition: thd.h:187
int sfd
Signal file descriptor.
Definition: thd.h:189