Esempio n. 1
0
/**
 * Remove a descriptor from the set of descriptors within the
 * polling environment.
 * The state change command may fail because concurrent threads may call
 * dcb_set_state simultaneously and the conflict is prevented in dcb_set_state.
 *
 * @param dcb	The descriptor to remove
 * @return	-1 on error or 0 on success
 */
int
poll_remove_dcb(DCB *dcb)
{
        struct	epoll_event ev;
        int                 rc = -1;
        dcb_state_t         old_state = DCB_STATE_UNDEFINED;
        dcb_state_t         new_state = DCB_STATE_NOPOLLING;

        CHK_DCB(dcb);

        /*< It is possible that dcb has already been removed from the set */
        if (dcb->state != DCB_STATE_POLLING) 
	{
                if (dcb->state == DCB_STATE_NOPOLLING ||
                    dcb->state == DCB_STATE_ZOMBIE)
                {
                        rc = 0;
                }
                goto return_rc;
        }
        /*<
         * Set state to NOPOLLING and remove dcb from poll set.
         */
        if (dcb_set_state(dcb, new_state, &old_state)) 
	{
		/**
		 * Only positive fds can be removed from epoll set.
		 */		 
		if (dcb->fd > 0) 
		{
			rc = epoll_ctl(epoll_fd, EPOLL_CTL_DEL, dcb->fd, &ev);

			if (rc != 0) {
				int eno = errno;
				errno = 0;
				LOGIF(LE, (skygw_log_write_flush(
					LOGFILE_ERROR,
					"Error : epoll_ctl failed due %d, %s.",
					eno,
					strerror(eno))));
			}
			ss_dassert(rc == 0); /*< trap in debug */
		}
        }
        /*<
         * This call was redundant, but the end result is correct.
         */
        else if (old_state == new_state)
        {
                rc = 0;
                goto return_rc;
        }
        
        /*< Set bit for each maxscale thread */
        bitmask_copy(&dcb->memdata.bitmask, poll_bitmask()); 
        rc = 0;
return_rc:
        return rc;
}
Esempio n. 2
0
/**
 * @brief
 *      get_cpubits() and get_membits() initialize memory bitmasks used to
 *      represent the CPUs (resp. memory boards) discovered while parsing
 *      vnode definitions files.
 *
 * @param[in] m - pointer to bitmask structure
 *
 * @return Void
 *
 */
void
get_membits(struct bitmask *m)
{
	assert(m != NULL);
	if (mem_mask != NULL) {
		assert(bitmask_nbits(m) == bitmask_nbits(mem_mask));
		(void) bitmask_copy(m, mem_mask);
	} else {
		bitmask_clearall(m);
		log_err(PBSE_SYSTEM, __func__, "mem_mask not yet initialized");
	}
}