Beispiel #1
0
kcontext_t *new_ThreadContext(CTX)
{
	KNH_SYSLOCK(_ctx);
	kcontext_t *newCtx = new_hcontext(_ctx);
	newCtx->share = ctx->share;
	newCtx->stat = ctx->stat;
	newCtx->spi = ctx->spi;
	newCtx->script = ctx->script;
	newCtx->parent = WCTX(_ctx);
//	newCtx->freeObjectList = NULL;
//	newCtx->freeObjectTail = NULL;
	KINITv(newCtx->gma, new_(GammaBuilder));
	knh_GammaBuilder_init(newCtx);
	CommonContext_init(_ctx, newCtx);
	knh_stack_initexpand(newCtx, NULL, K_STACKSIZE);

	ctx->wshare->contextCounter++;
	ctx->wshare->threadCounter++;
	if(newCtx->ctxobjNC == NULL) {
		newCtx->ctxobjNC = knh_toContext(newCtx);
	}
	kArray_add(ctx->share->contextListNULL, newCtx->ctxobjNC);
	newCtx->safepoint = ctx->share->ctx0->safepoint;
	KNH_SYS_UNLOCK(_ctx);
	return newCtx;
}
Beispiel #2
0
static void *spawn_start(void *v)
{
	Thread_t *t = (Thread_t *)v;
	kcontext_t *ctx = t->ctx;

	KONOHA_BEGIN(ctx);
	// set ExceptionHandler
	//kExceptionHandler* hdr = new_(ExceptionHandler);
	//ctx->esp[0].hdr = hdr;
	//ctx->esp++;
	// set args
	ksfp_t *sfp = ctx->esp;
	int i, argc = knh_Array_size(t->args);
	for(i=0; i<argc; i++) {
		kObject *o = knh_Array_n(t->args, i);
		switch(O_cid(o)) {
		case CLASS_Int:
			sfp[K_CALLDELTA + i + 1].ivalue = N_toint(o);
			break;
		case CLASS_Float:
			sfp[K_CALLDELTA + i + 1].fvalue = N_tofloat(o);
			break;
		case CLASS_Boolean:
			sfp[K_CALLDELTA + i + 1].bvalue = N_tobool(o);
			break;
		default:
			KNH_SETv(ctx, sfp[K_CALLDELTA + i + 1].o, o);
		}
	}
	knh_Func_invoke(ctx, t->func, sfp, argc);

	//int jump = knh_setjmp(DP(hdr)->jmpbuf);
	//if(jump == 0) {
	//	hdr->espidx = (ctx->esp - ctx->stack);
	//	hdr->parentNC = ctx->ehdrNC;
	//	((kcontext_t*)ctx)->ehdrNC = hdr;
	//	knh_Func_invoke(ctx, t->func, sfp, argc);
	//} else {
	//	/* catch exception */
	//	hdr = ctx->ehdrNC;
	//	((kcontext_t*)ctx)->ehdrNC = hdr->parentNC;
	//}
	//kthread_detach(ctx, t->thread);
	//KNH_FREE(ctx, t, sizeof(Thread_t));

	KNH_SYSLOCK(ctx);
	ctx->ctxobjNC = NULL;
	ctx->wshare->threadCounter--;
	KONOHA_END(ctx);
	if(ctx->share->gcStopCounter != 0) {
		kthread_cond_signal(ctx->share->start_cond);
	}else if(ctx->share->threadCounter == 1) {
		kthread_cond_signal(ctx->share->close_cond);
	}
	KNH_SYSUNLOCK(ctx);
	return NULL;
}