Example #1
0
/**
 * Runs all PiThread tests.
 */
void PICC_test_pithread()
{
    ALLOC_ERROR(error);
    test_create_pithread(&error);

    if (HAS_ERROR(error))
        PRINT_ERROR(&error);
}
Example #2
0
/**
 * Prints the given error stack on the standard error output and quits the
 * program with failure return code.
 *
 * @param error Error stack
 * @param file File where the crash occured (for DEBUG)
 * @param fct Function where the crash occured (for DEBUG)
 */
void PICC_crash(PICC_Error *error, const char *file, const char *fct)
{
    if (HAS_ERROR((*error))) {
        PICC_print_error(error, file, fct);
        printf("Exiting runtime...\n");
        exit(EXIT_FAILURE);
    }
}
Example #3
0
struct lnklst_st* new_lstnmods(struct lnklst_st* fkvs)
{
FUNC_ENTER

	struct sortedll_st* ports = NULL;
	struct lnklst_st* lstnmods = NULL;		// ports がユニークなので lnklst_t でよい

	ports = sll_init(NULL, cmp_as_long_, SLLOPT_DISALLOW_DUPVAL);
	if (! ports)
	{
		FIRE("sll_init");
	}

	syserr = ll_foreach(fkvs, collect_port_, ports);
	if (syserr)
	{
		FIRE("ll_foreach");
	}

	lstnmods = new_lstnmods_(ports, fkvs);
	if (! lstnmods)
	{
		FIRE("new_lstnmods_");
	}

FUNC_CHECKPOINT

	if (HAS_ERROR())
	{
		ll_free(lstnmods);
		lstnmods = NULL;
	}

	sll_free(ports);
	ports = NULL;

FUNC_LEAVE

	return lstnmods;
}
Example #4
0
static struct lnklst_st* new_lstnmods_(struct sortedll_st* ports, struct lnklst_st* fkvs)
{
FUNC_ENTER

	struct lnklst_st* lstnmods = NULL;

	struct cbmod_st* defset = NULL;
	struct cbmod_st* cbmod = NULL;

	defset = new_default_cbmod(fkvs, "/listen-module-default");
	if (! defset)
	{
		FIRE("new_default_cbmod_");
	}

	defset->iconf->cbmt = JBXM_CBMT_LISTEN;

//puts("# defset -->");
//print_cbmod_(defset, NULL);
//puts("# defset --<");

	lstnmods = ll_init(free_cbmod);
	if (! lstnmods)
	{
		FIRE("ll_init");
	}

	char family[32] = "";

	for (struct lnkelm_st* le=sll_first(ports); le->next; le=le->next)
	{
// ポート番号を数値に変換

		intptr_t n_port = (intptr_t)le->val;

// デフォルト値をコピーする (family_, name, port 以外)

		cbmod = new_copy_cbmod_attr(defset);
		if (! cbmod)
		{
			FIRE("new_copy_cbmod");
		}

		snprintf(family, sizeof family, "/listen-modules/%zd", n_port);

// family_ をコピー

		cbmod->family_ = strdup(family);
		if (! cbmod->family_)
		{
			FIRE("strdup");
		}

// family_ の値を元に conf から値を設定する

		syserr = ll_foreach(fkvs, set_cbmod_by_family, cbmod);
		if (syserr)
		{
			FIRE("ll_foreach");
		}

		if (! is_valid_cbmod(cbmod))
		{
			FIRE("is_valid_cbmod port=%ld", n_port);
		}

		cbmod->iconf->port = (u_short)n_port;

		if (cbmod->enable)
		{
print_cbmod(cbmod, NULL);

			void* ok = ll_add_tail(lstnmods, cbmod);
			if (! ok)
			{
				FIRE("ll_add");
			}

			cbmod = NULL;
		}
		else
		{
DBGLOG("port(%u) disable", cbmod->iconf->port);

			free_cbmod(cbmod);
			cbmod = NULL;
		}
	}

FUNC_CHECKPOINT

	if (HAS_ERROR())
	{
		free_cbmod(cbmod);
		cbmod = NULL;

		ll_free(lstnmods);
		lstnmods = NULL;
	}

	free_cbmod(defset);
	defset = NULL;

FUNC_LEAVE

	return lstnmods;
}
Example #5
0
/**
 * Decrements the global reference count of a managed value
 *
 * @pre h != NULL
 *
 * @post h->global_rc = h->global_rc@pre - 1
 *
 * @param Handle to update
 */
void PICC_handle_dec_ref_count(PICC_Handle **h)
{
    /* #ifdef CONTRACT_PRE_INV */
    /*     //inv */
    /*     PICC_Channel_inv(*channel); */
    /* #endif */

    #ifdef CONTRACT_PRE
        //pre
        ASSERT(*h != NULL );
    #endif

    #ifdef CONTRACT_POST
        // capture
        // int global_rc_at_pre = (*h)->global_rc;
    #endif

	// I think there is a problem here: what happens if global_rc is equal to one
	// and another thread was about to increment it but lost the race to acquire the lock ?
	//
	// moreover, for now the lock is alocated in the channel/handle with the previous
	// case in mind we cannot free it in the reclaim
	// I think a solution would be to have a pool of Lock witch contain the lock itself
	// and the value it's suposed to lock
	//
	// kind of:
	// struct{
	//   atomic_int cpt;
	//   void *content;
        // }
	//
	// in the function lock_alloc we would keep track of all the locks and we could
	// reuse the ones that have cpt == 0 && content == NULL
	//

    LOCK_HANDLE(*h);
    (*h)->global_rc--;

    if ((*h)->global_rc == 0) {
	RELEASE_HANDLE(*h);

	ALLOC_ERROR(reclaim_error);
        (*h)->reclaim(*h, &reclaim_error);
	*h = NULL;
        if (HAS_ERROR(reclaim_error))
            CRASH(&reclaim_error);
    }
    else{
	RELEASE_HANDLE(*h);
    }

    /* #ifdef CONTRACT_POST_INV */
    /*     if (*h != NULL) */
    /*         PICC_Channel_inv(*channel); */
    /* #endif */

    /* #ifdef CONTRACT_POST */
    /*     if(global_rc_at_pre > 1) */
    /*         ASSERT((*channel)->global_rc == global_rc_at_pre - 1 ); */
    //cannot be asserted see incr for the same comment
    /* #endif */
}