Esempio n. 1
0
LOCAL void rfb_exit(RFBDISPLAY *mod)
{
	TAPTR TExecBase = TGetExecBase(mod);
	if (mod->rfb_Task)
	{
		TSignal(mod->rfb_Task, TTASK_SIG_ABORT);
		TDestroy((struct THandle *) mod->rfb_Task);
	}
}
Esempio n. 2
0
LOCAL void
fb_exit(WINDISPLAY *mod)
{
	struct TExecBase *TExecBase = TGetExecBase(mod);
	if (mod->fbd_Task)
	{
		TSignal(mod->fbd_Task, TTASK_SIG_ABORT);
		TDestroy((struct THandle *) mod->fbd_Task);
	}
}
Esempio n. 3
0
LOCAL void
fb_closewindow(WINDISPLAY *mod, struct TVRequest *req)
{
	struct TExecBase *TExecBase = TGetExecBase(mod);
	WINWINDOW *win = req->tvr_Op.CloseWindow.Window;
	if (win == TNULL)
		return;
	TSignal(win->fbv_Task, TTASK_SIG_ABORT);
	PostMessage(win->fbv_HWnd, WM_USER, 0, 0);
	TDestroy(win->fbv_Task);
}
Esempio n. 4
0
static void tek_lib_exec_checkabort(lua_State *L, struct TExecBase *TExecBase,
	TUINT sig)
{
	if (sig & TTASK_SIG_ABORT)
	{
		struct LuaExecTask *parent = getparent(TExecBase);
		if (parent)
			TSignal(parent->task, TTASK_SIG_ABORT);
		luaL_error(L, "received abort signal");
	}
}
Esempio n. 5
0
static void rfb_exit(struct rfb_Display *mod)
{
	TAPTR TExecBase = TGetExecBase(mod);

	if (mod->rfb_Task)
	{
		TSignal(mod->rfb_Task, TTASK_SIG_ABORT);
#if defined(ENABLE_LINUXFB)
		rfb_linux_wake(mod);
#endif
		TDestroy((struct THandle *) mod->rfb_Task);
	}
}
Esempio n. 6
0
static THOOKENTRY TTAG
tek_lib_exec_run_dispatch(struct THook *hook, TAPTR task, TTAG msg)
{
	struct LuaExecChild *ctx = hook->thk_Data;
	struct TExecBase *TExecBase = ctx->exec;
	switch (msg)
	{
		case TMSG_INITTASK:
		{
			TAPTR atom;
			if (!ctx->taskname)
			{
				sprintf(ctx->atomname, "task.task: %p", task);
				ctx->taskname = ctx->atomname + TEK_LIB_TASK_ATOMNAME_OFFSET;
			}
			atom = TLockAtom(ctx->atomname, 
				TATOMF_CREATE | TATOMF_NAME | TATOMF_TRY);
			if (!atom)
				return TFALSE;
			TSetAtomData(atom, (TTAG) task);
			TUnlockAtom(atom, TATOMF_KEEP);
			return TTRUE;
		}

		case TMSG_RUNTASK:
		{
			struct LuaExecTask *parent = ctx->parent;
			TUINT sig = TTASK_SIG_CHLD;
			ctx->task = TFindTask(TNULL);
			lua_pushcfunction(ctx->L, &tek_lib_exec_runchild);
			lua_pushlightuserdata(ctx->L, ctx);
			ctx->status = lua_pcall(ctx->L, 1, 1, 0);
			TDBPRINTF(TDB_TRACE,("pcall2 ctx->status=%d\n", ctx->status));
			report(ctx->L, ctx->status);
			lua_close(ctx->L);
			if (ctx->status)
				sig |= TTASK_SIG_ABORT;
			TSignal(parent->task, sig);
			if (ctx->taskname)
			{
				TAPTR atom = TLockAtom(ctx->atomname, TATOMF_NAME);
				TUnlockAtom(atom, TATOMF_DESTROY);
			}
			break;
		}
	}
	return 0;
}
Esempio n. 7
0
LOCAL void tek_lib_visual_io_close(TEKVisual *vis)
{
	if (vis->vis_IOTask)
	{
		struct TExecBase *TExecBase = vis->vis_ExecBase;
		TSignal(vis->vis_IOTask, TTASK_SIG_ABORT);
		#if defined(ENABLE_FILENO) || defined(ENABLE_DGRAM)
		struct IOData *iodata = vis->vis_IOData;
		tek_lib_visual_io_wake(iodata);
		#endif
		TDestroy((struct THandle *) vis->vis_IOTask);
		vis->vis_IOTask = TNULL;
		TFree(vis->vis_IOData);
		vis->vis_IOData = TNULL;
	}
}
Esempio n. 8
0
static int tek_lib_exec_signal(lua_State *L)
{
	struct LuaExecTask *lexec = tek_lib_exec_check(L);
	struct TExecBase *TExecBase = lexec->exec;
	const char *taskname = luaL_checkstring(L, 1);
	TUINT sig = tek_lib_exec_string2sig(luaL_optstring(L, 2, "t"));
	TAPTR ref;
	TAPTR task = tek_lib_exec_locktask(TExecBase, taskname, &ref);
	if (task)
	{
		TSignal(task, sig);		
		tek_lib_exec_unlocktask(TExecBase, ref);
		lua_pushboolean(L, TTRUE);
	}
	else
		lua_pushnil(L);
	return 1;
}
Esempio n. 9
0
static int tek_lib_exec_child_sigjoin(lua_State *L, TUINT sig, TBOOL sigparent,
	TBOOL do_results)
{
	struct LuaExecChild *ctx = luaL_checkudata(L, 1, TEK_LIB_TASK_CLASSNAME);
	struct TExecBase *TExecBase = ctx->exec;
	struct TTask *self = TFindTask(TNULL), *task = ctx->task;
	union TTaskRequest *req = &self->tsk_Request;
	TBOOL abort = TFALSE;
	int nres = 0;
	if (!task)
		return 0;
	
	TDBPRINTF(TDB_TRACE,("child_join sig=%d sigparent=%d\n", sig, sigparent));
	
	/* signal task */
	TSignal(task, sig);
	/* prepare destroy request */
	self->tsk_ReqCode = TTREQ_DESTROYTASK;
	req->trq_Task.trt_Task = task;
	/* send to exec */
	TPutMsg(TExecBase->texb_ExecPort, &self->tsk_SyncPort, self);
	for (;;)
	{
		/* wait for return of request or receiving abort ourselves: */
		TUINT sig = TWait(TTASK_SIG_SINGLE | TTASK_SIG_ABORT);
		if (sig & TTASK_SIG_SINGLE)
			break;
		if (sig & TTASK_SIG_ABORT)
		{
			/* forward to child task */
			TSignal(task, TTASK_SIG_ABORT);
			if (sigparent)
			{
				/* also forward to own parent task */
				struct LuaExecTask *parent = getparent(TExecBase);
				if (parent)
					TSignal(parent->task, TTASK_SIG_ABORT);
				abort = TTRUE;
			}
		}
	}
	/* take delivery of replied destroy request */
	TGetMsg(&self->tsk_SyncPort);
	/* free task */	
	TFreeTask(task);
	
	ctx->task = TNULL;
	tek_lib_exec_freectxargs(ctx);
	if (!abort && do_results)
	{
		int i;
		nres = ctx->numres + 1;
		lua_pushboolean(L, ctx->luastatus == 0);
		for (i = 0; i < ctx->numres; ++i)
			lua_pushlstring(L, ctx->results[i].arg, ctx->results[i].len);
	}
	tek_lib_exec_freeargs(TExecBase, ctx->results, ctx->numres);
	luaL_unref(L, lua_upvalueindex(1), ctx->ref);
	if (abort)
		luaL_error(L, "received abort signal");
	return nres;
}
Esempio n. 10
0
static int tek_lib_exec_runchild(lua_State *L)
{
	int i;
	struct LuaExecChild *ctx = lua_touserdata(L, 1);
	struct TExecBase *TExecBase = ctx->exec;
	
	lua_gc(L, LUA_GCSTOP, 0);
	luaL_openlibs(L);
	lua_gc(L, LUA_GCRESTART, 0);
	
	lua_createtable(L, ctx->numargs + 1, 0);
	lua_pushvalue(L, -1);
	lua_setglobal(L, "arg");
	
	for (i = 0; i < ctx->numargs; ++i)
	{
		if (ctx->args[i].arg == TNULL)
			continue;
		lua_pushlstring(L, ctx->args[i].arg, ctx->args[i].len);
		lua_rawseti(L, -2, i);
	}
	tek_lib_exec_freectxargs(ctx);
	
	if (ctx->fname)
	{
		lua_pushstring(L, ctx->fname);
		lua_rawseti(L, -2, 0);
		ctx->status = luaL_loadfile(ctx->L, ctx->fname);
	}
	else if (ctx->chunklen)
		ctx->status = luaL_loadbuffer(L, (const char *) (ctx + 1), 
			ctx->chunklen, "...");
	if (ctx->status == 0)
	{
		int narg = 0;
		int base = lua_gettop(L) - narg;
#if LUA_VERSION_NUM < 502
		lua_pushcfunction(L, traceback);
#else
		lua_pushcfunction(L, msghandler);
#endif
		lua_insert(L, base);
		tek_lib_exec_register_task_hook(ctx->L, TExecBase);
		ctx->status = ctx->luastatus = lua_pcall(L, narg, LUA_MULTRET, base);
		lua_remove(L, base);
		if (ctx->status)
		{
			TDBPRINTF(TDB_TRACE,("pcall ctx->status=%d, signal to parent\n",
				ctx->status));
			struct LuaExecTask *parent = ctx->parent;
			TSignal(parent->task, TTASK_SIG_ABORT);
		}
		else
		{
			int nres = ctx->numres = lua_gettop(L) - 2;
			ctx->results = tek_lib_exec_getargs(L, TExecBase, 3, nres, 0);
		}
	}
	TDBPRINTF(TDB_TRACE,("collecting1...\n"));
	lua_gc(L, LUA_GCCOLLECT, 0);
	return report(L, ctx->status);
}