42 #include <xmlstring.h> 49 #include <sys/signal.h> 53 #include <sys/signalfd.h> 82 #define DEBUG_THD // DEBUG compile only thread-related debugs 85 #define LOCK_BANNER "[LOCK]" 88 #define THD_CLEANUP_PHASE1 TRUE 89 #define THD_CLEANUP_PHASE2 FALSE 92 #define THD_STRICT_LOOKUP TRUE 93 #define THD_SIMPLE_LOOKUP !THD_STRICT_LOOKUP 95 #define NULL_PTHREAD (pthread_t)NULL 100 #define MAINLINE_TID 0 101 #define MAINLINE_SID 0 104 #define NULL_SID SES_NULL_SID 108 #define THD_CAP_CANCEL_CC bit0 109 #define THD_CAP_NEXT_AVAIL bit1 111 #define THD_INC_THD_CNT ENTER_FAST_CS; \ 115 #define THD_DEC_THD_CNT ENTER_FAST_CS; \ 120 #define THD_SIGNAL SIGVTALRM 122 #define THD_SIGNAL SIGTERM 125 #define THD_LOGROTATE_SIG SIGUSR2 146 typedef boolean (*test_cdx_void_t) (void);
147 typedef boolean (*test_cdx_int_t) (int);
150 typedef enum thd_tcb_state_t_ {
158 #define THD_TCB_STATE_MIN (THD_TCB_STATE_NONE + 1) 159 #define THD_TCB_STATE_MAX (THD_TCB_STATE_LIMIT - 1) 162 typedef enum thd_type_t_ {
172 #define THD_TYPE_MIN (THD_TYPE_NONE + 1) 173 #define THD_TYPE_MAX (THD_TYPE_LIMIT - 1) 176 typedef struct thd_tcb_t_ {
238 struct agt_not_subscription_t_ *
sub;
250 extern boolean thd_init_called;
251 extern boolean thd_init_successful;
253 extern int thread_count;
254 extern boolean thd_cs_mutex_init;
256 extern pthread_attr_t pthread_attr;
306 test_cdx_int_t sid_test_func);
int thd_unlock_ses_sync_mutex(void)
Unlock session sync mutex (enforce session synchronization)
Definition: thd.c:1115
Connection.
Definition: thd.h:165
void thd_mark_tcb_deleted(thd_tcb_t *tcb)
Cleanup (release resources associated with a TCB) and free it.
Definition: thd.c:661
ses_id_t thd_find_sess_id(void)
Find the session ID represented by the current thread.
Definition: thd.c:954
Phase 2 cleanup done - ready to free.
Definition: thd.h:154
ses_id_t thd_find_sess_id_by_handle(pthread_t handle)
Find the session ID represented by the thread handle.
Definition: thd.c:915
boolean module_db_locked
module with datastores loads
Definition: thd.h:218
thd_tcb_t * thd_find_tcb_by_capability(uint cap)
Find a TCB supporting the specified capability.
Definition: thd.c:798
status_t thd_module_db_wrlock(thd_tcb_t *tcb)
Request write access to the module DB ("object tree").
Definition: thd.c:1404
void thd_get_ids(int *tid, ses_id_t *sid)
Return the TID and SID of the current running thread.
Definition: thd.c:1028
NETCONF Session Common definitions module.
status_t thd_module_db_rdlock(thd_tcb_t *tcb)
Request read access to the module DB ("object tree")
Definition: thd.c:1347
status_t thd_module_db_unlock(thd_tcb_t *tcb)
Unlock (release access) to the module DB ("object tree").
Definition: thd.c:1460
thd_tcb_t * thd_get_first_tcb(void)
Get the first thread control block.
Definition: thd.c:2012
thd_tcb_t * thd_find_tcb_by_handle(pthread_t handle)
Find a thread by its OS pthread handle.
Definition: thd.c:760
Session (rx_thread)
Definition: thd.h:167
not set
Definition: thd.h:163
const char * name
thread name
Definition: thd.h:183
thd_tcb_t * thd_get_thread_tcb(void)
Return the TCB of the current thread.
Definition: thd.c:1001
uint32 ses_id_t
Session ID.
Definition: ses.h:306
boolean thd_rcv_signal_setup(sigset_t *sigmask, thd_tcb_t *tcb)
Init thread to receive omnibus signal.
Definition: thd.c:1719
Phase 1 cleanup done - ready to reuse.
Definition: thd.h:153
ses_term_reason_t
Session Termination reason.
Definition: ses.h:387
boolean cancel_cc
cancel confirmed-commit flag
Definition: thd.h:230
int thd_unlock_recursive_log_cs_mutex(void)
Unlock recursive logger CS (critical section) mutex.
Definition: thd.c:1255
Thread control block (TCB)
Definition: thd.h:176
thd_type_t thd_type
thread type
Definition: thd.h:181
ses_term_reason_t termreason
termination reason
Definition: thd.h:227
void thd_set_main_handle(void)
Record the thread handle of "main" (running initially before any threads are created) for reference...
Definition: thd.c:505
void thd_check_shutdown_signal(sigset_t *sigmask, thd_tcb_t *tcb)
The agt_shutdown_requested == TRUE at this point.
Definition: thd.c:1776
ses_cb_t * dscb
Dummy SCB, if any.
Definition: thd.h:184
Timer.
Definition: thd.h:166
active
Definition: thd.h:152
void thd_clear_locks(thd_tcb_t *tcb)
Clear mutexes and RWLOCKs prior to termination.
Definition: thd.c:587
thd_tcb_state_t state
thread state
Definition: thd.h:179
uint thd_cap
Capability bits.
Definition: thd.h:182
thd_tcb_state_t
Thread (tcb) states.
Definition: thd.h:150
not set
Definition: thd.h:151
int run
internal run state
Definition: thd.h:188
void thd_set_main_pthread_attr(void)
Set/display main pthread attributes, to be inherited by all threads, unless otherwise noted...
Definition: thd.c:416
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:1625
int tid
thread ID
Definition: thd.h:187
void thd_shutdown(void)
Begin thread ermination by signalling.
Definition: thd.c:1826
Dummy session TCB.
Definition: thd.h:168
Session Control Block.
Definition: ses.h:542
thd_type_t
Thread types.
Definition: thd.h:162
status_t
global error return code
Definition: status_enum.h:186
Background.
Definition: thd.h:164
#define NCX_CFGID_CNT
Should match CFG_NUM_STATIC.
Definition: ncxtypes.h:544
thd_tcb_t * thd_find_tcb_by_type(thd_type_t type)
Find a TCB supporting the specified type.
Definition: thd.c:836
thd_tcb_t * thd_find_tcb_by_sid(ses_id_t sid, boolean strict)
Lookup TCB by session ID.
Definition: thd.c:711
thd_tcb_t * thd_get_next_tcb(thd_tcb_t *tcb)
Get the next thread control block from the specified entry.
Definition: thd.c:2030
int thd_lock_recursive_log_cs_mutex(void)
Request lock on recursive logger CS (critical section) mutex.
Definition: thd.c:1222
int thd_lock_ses_sync_mutex(void)
Request lock on session sync mutex (enforce session synchronization)
Definition: thd.c:1075
ncx_confirm_event_t
type of confirmEvent in the sysConfirmedCommit notification Used in confirmed-commit standard as well...
Definition: ncxtypes.h:1377
int thd_lock_inreadyQ_mutex(ses_id_t sid)
Request mutex lock for access to the inreadyQ (pending input).
Definition: thd.c:1284
Global error messages for status code enumerations.
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:238
int thd_unlock_inreadyQ_mutex(ses_id_t sid)
Unlock mutex for access to the inreadyQ (pending input).
Definition: thd.c:1315
int fd
I/O file descriptor.
Definition: thd.h:189
int sfd
Signal file descriptor.
Definition: thd.h:190
ses_id_t killedby
kill session done
Definition: thd.h:224
int thd_count_ses_threads(void)
Count the number of session threads.
Definition: thd.c:874
boolean kill_session
kill session requested
Definition: thd.h:221
ncx_confirm_event_t cancel_cc_event
confirm-commit event
Definition: thd.h:233
void thd_cleanup(boolean phase1)
Terminate threads and deallocate associated resources, including thread control blocks.
Definition: thd.c:1873
thd_tcb_t * thd_new_tcb(thd_type_t type)
Allocate a new thread control block.
Definition: thd.c:551
status_t thd_master_init(void)
Initialize all mutexes for use by threads.
Definition: thd.c:1515
fd_set tcb_fd_set
FDs used by thread.
Definition: thd.h:191
boolean snmp_notif
1 subscription allowed
Definition: thd.h:239
pthread_t handle
Internal thread handle.
Definition: thd.h:180
void thd_set_ready(void)
Netconfd will set thd_ready when initialization is complete, but before creating threads.
Definition: thd.c:531
int thd_find_thread_id(void)
Find the thread ID represented by the current thread.
Definition: thd.c:975
int sleep
sleep amount
Definition: thd.h:192
ses_id_t sid
Session ID of thread.
Definition: thd.h:185