Example #1
0
static kcontext_t* new_hcontext(CTX ctx0)
{
	kcontext_t *ctx;
	static volatile size_t ctxid_counter = 0;
	if(ctx0 == NULL) {
		ctxid_counter = 0;
		ctx = (kcontext_t*)malloc(sizeof(kcontext_t));
		knh_bzero(ctx, sizeof(kcontext_t));
	}
	else {
		KNH_ASSERT_CTX0(ctx0);
		ctx = (kcontext_t*)KNH_MALLOC(ctx0, sizeof(kcontext_t));
		knh_bzero(ctx, sizeof(kcontext_t));
	}
	ctx->flag = 0;
	ctx->ctxid = ctxid_counter;
	ctxid_counter++;
//	ctx->freeObjectList = NULL;
//	ctx->freeMemoryList = NULL;
	ctx->parent = ctx;
	ctx->api2 = getapi2();
	{
		kuintptr_t i = 0, ch;
		kuint_t t = knh_rand();
		ch = t % 26;
		ctx->trace[i] = 'A' + ch;
		for(i = 1; i < 9; i++) {
			t = t / 36;
			if (t == 0) t = knh_rand();
			ch = t % 36;
			ctx->trace[i] = (ch < 10) ? '0' + ch : 'A' + (ch - 10);
		}
	}
	ctx->seq = 0;
	ctx->ctxobjNC = NULL;
	if(ctx0 == NULL) {
		const char *ptrace = knh_getenv(K_DEOS_TRACE);
		if(ptrace == NULL) {
			ptrace = "$(setenv " K_DEOS_TRACE ")";
		}
		KNH_NTRACE2(ctx, "konoha:newtrace", K_NOTICE, KNH_LDATA(
					LOG_s("parent", ptrace)
#if defined(K_USING_POSIX_)
					, LOG_u("ppid", getppid())
#endif /* !defined(K_USING_POSIX_) */
					));
	}
	else {
		KNH_NTRACE2(ctx, "konoha:newtrace", K_NOTICE, KNH_LDATA(LOG_s("parent", ctx0->trace), LOG_u("seq", ctx0->seq)));
	}
	return ctx;
}
Example #2
0
knh_float_t knh_float_rand(void)
{
#if defined(K_USING_NOFLOAT)
	return (knh_float_t)knh_rand();
#elif defined(K_USING_INT32)
	return (knh_float_t)genrand_real1();
#else
	return (knh_float_t)genrand64_real1();
#endif
}