zabbix-agent2/src/libs/zbxdbcache/dbconfig.c
/******************************************************************************
 *                                                                            *
 * Function: zbx_dc_get_or_create_data_session                                *
 *                                                                            *
 * Purpose: returns data session, creates a new session if none found         *
 *                                                                            *
 * Parameter: hostid - [IN] the host (proxy) identifier                       *
 *            token  - [IN] the session token (not NULL)                      *
 *                                                                            *
 * Return value: pointer to data session.                                     *
 *                                                                            *
 * Comments: The last_valueid property of the returned session object can be  *
 *           updated directly without locking cache because only one data     *
 *           session is updated at the same time and after retrieving the     *
 *           session object will not be deleted for 24 hours.                 *
 *                                                                            *
 ******************************************************************************/
zbx_dc_get_or_create_data_session

Purpose: returns data session, creates a new session if none found

Parameter: hostid - [IN] the host (proxy) identifier
token  - [IN] the session token (not NULL)

Return value: pointer to data session.

Comments: The last_valueid property of the returned session object can be
updated directly without locking cache because only one data
session is updated at the same time and after retrieving the
session object will not be deleted for 24 hours.
zbx_dc_get_or_create_data_session Purpose : returns data session creates a new session if none found Parameter : hostid - [ IN ] the host ( proxy ) identifier token - [ IN ] the session token ( not NULL ) Return value : pointer to data session . Comments : The last_valueid property of the returned session object can be updated directly without locking cache because only one data session is updated at the same time and after retrieving the session object will not be deleted for 24 hours .
zbx_data_session_t	*zbx_dc_get_or_create_data_session(zbx_uint64_t hostid, const char *token)
{
	zbx_data_session_t	*session, session_local;
	time_t			now;
	now = time(NULL);
	session_local.hostid = hostid;
	session_local.token = token;
	RDLOCK_CACHE;
	session = (zbx_data_session_t *)zbx_hashset_search(&config->data_sessions, &session_local);
	UNLOCK_CACHE;
	if (NULL == session)
	{
		WRLOCK_CACHE;
		session = (zbx_data_session_t *)zbx_hashset_insert(&config->data_sessions, &session_local,
				sizeof(session_local));
		session->token = dc_strdup(token);
		UNLOCK_CACHE;
		session->last_valueid = 0;
	}
	session->lastaccess = now;
	return session;
}
zbx_data_session_t * zbx_dc_get_or_create_data_session ( zbx_uint64_t hostid , const char * token ) { zbx_data_session_t * session , session_local ; time_t now ; now = time ( NULL ) ; session_local . hostid = hostid ; session_local . token = token ; RDLOCK_CACHE ; session = ( zbx_data_session_t * ) zbx_hashset_search ( & config -> data_sessions , & session_local ) ; UNLOCK_CACHE ; if ( NULL == session ) { WRLOCK_CACHE ; session = ( zbx_data_session_t * ) zbx_hashset_insert ( & config -> data_sessions , & session_local , sizeof ( session_local ) ) ; session -> token = dc_strdup ( token ) ; UNLOCK_CACHE ; session -> last_valueid = 0 ; } session -> lastaccess = now ; return session ; }
Function: zbx_dc_get_or_create_data_session                                
                                                                            
 Purpose: returns data session, creates a new session if none found         
                                                                            
 Parameter: hostid - [IN] the host (proxy) identifier                       
            token  - [IN] the session token (not NULL)                      
                                                                            
 Return value: pointer to data session.
Function : zbx_dc_get_or_create_data_session Purpose : returns data session creates a new session if none found Parameter : hostid - [ IN ] the host ( proxy ) identifier token - [ IN ] the session token ( not NULL ) Return value : pointer to data session .