Beispiel #1
0
int sched_yield(void)
{
	BYTE oldpri;
	struct Task *task;

	D(bug("%s()\n", __FUNCTION__));

	task = FindTask(NULL);
	// changing the priority will trigger a reschedule
	oldpri = SetTaskPri(task, -10);
	SetTaskPri(task, oldpri);

	return 0;
}
Beispiel #2
0
	/**
	 * On thread creation, this function is called, which calls the real startup
	 *  function. This to get back into the correct instance again.
	 */
	static void Proxy()
	{
		struct Task *child = FindTask(NULL);
		struct OTTDThreadStartupMessage *msg;

		/* Make sure, we don't block the parent. */
		SetTaskPri(child, -5);

		KPutStr("[Child] Progressing...\n");

		if (NewGetTaskAttrs(NULL, &msg, sizeof(struct OTTDThreadStartupMessage *), TASKINFOTYPE_STARTUPMSG, TAG_DONE) && msg != NULL) {
			try {
				msg->func(msg->arg);
			} catch(OTTDThreadExitSignal e) {
				KPutStr("[Child] Returned to main()\n");
			} catch(...) {
				NOT_REACHED();
			}
		}

		/*  Quit the child, exec.library will reply the startup msg internally. */
		KPutStr("[Child] Done.\n");

		if (self_destruct) delete this;
	}
Beispiel #3
0
void amigaExit(void)
{
   #if USE_RESETHANDLER
   rem_resethandler();
   #endif

   #ifndef NO_GUI
   amigaCloseNewConsole();
   amigaGUIDeinit();
   #endif

   #ifdef __amigaos4__
   if (ISocket) DropInterface((struct Interface *)ISocket);
   #else
   CloseLibrary((struct Library *)LocaleBase);
   #endif
   CloseLibrary((struct Library *)SocketBase);

   #ifdef __OS3PPC__
   /*
   ** PPC
   */
   #ifdef CHANGE_MIRROR_TASK_PRI
   SetTaskPri(FindTask(NULL), Old68kMirrorPri);
   #endif
   #ifdef __POWERUP__
   /*
   ** PowerUp
   */
   if (TriggerPort) {
      while (!PPCDeletePort(TriggerPort)) amigaSleep(0,250000);
   }
   CloseLibrary(PPCLibBase);
   #else
   /*
   ** WarpOS
   */
   if (TriggerPort) {
      RemPortPPC(TriggerPort);
      DeleteMsgPortPPC(TriggerPort);
   }
   #endif
   #else
   /*
   ** 68K / OS4 / MorphOS
   */
   if (TriggerPort) {
      RemPort(TriggerPort);
      DeleteMsgPort(TriggerPort);
   }
   #endif

   GlobalTimerDeinit();

   #if USE_RESETHANDLER
   finish_resethandler();
   #endif
}
void Sys_Thread_DeleteThread(struct SysThread *thread)
{
	SetTaskPri(&thread->process->pr_Task, 0);

	while(!GetMsg(thread->msgport))
		WaitPort(thread->msgport);

	DeleteMsgPort(thread->msgport);
	FreeVec(thread);
}
Beispiel #5
0
/* 
 * UAE sets task priorities only to "1", no other values seem to
 * be used. As for AmigaOS uncommon values may cause severe problems,
 * we only accept NULL/1, everything else needs to be checked!
 *
 * Increasing the thread priority is important for the filesystem 
 * task, otherwise virtual filesystem access is *very* slow.
 */
void uae_set_thread_priority (uae_thread_id *tid, int pri) {

  DebOut("uae_thread_id %lx, pri %d\n", tid, pri);

  if(tid!=NULL || pri>1) {
    bug("ERROR: uae_set_thread_priority with unsupported values: uae_thread_id %lx, pri %d!\n", tid, pri);
    return;
  }

  SetTaskPri(FindTask(NULL), pri);
}
Beispiel #6
0
int main (int argc, char **argv)
{
    struct timerequest *timereq = 0;
    struct MsgPort *timeport;
    int result = calltrap (0, 0);

    if (result == 1)
	fprintf (stderr, "timehack already running.\n");
    else if (result == 2)
	fprintf (stderr, "timehack not supported with this version of UAE.\n");
    if (result != 0)
	exit (5);

    timeport = CreatePort (0, 0);
    if (timeport)
	timereq = CreateStdIO(timeport);

    if (timereq == 0)
	goto fail;

    if (OpenDevice ("timer.device", UNIT_VBLANK, timereq, 0) != 0)
	goto fail;

    SetTaskPri (FindTask (NULL), 20); /* same as input.device */
    for (;;) {
        struct timeval cur_sys_time;

        timereq->tr_node.io_Command = TR_GETSYSTIME;
        DoIO(timereq);
        cur_sys_time = timereq->tr_time;
        calltrap (1, &timereq->tr_time);
        if (timereq->tr_time.tv_secs > cur_sys_time.tv_secs
	    || (timereq->tr_time.tv_secs == cur_sys_time.tv_secs
		&& timereq->tr_time.tv_micro > cur_sys_time.tv_micro))
	{
            timereq->tr_node.io_Command = TR_SETSYSTIME;
            DoIO(timereq);
        }

        timereq->tr_time.tv_secs = 1;
	timereq->tr_time.tv_micro = 0;
        timereq->tr_node.io_Command = TR_ADDREQUEST;
	DoIO(timereq);
    }
    fail:
    fprintf (stderr, "Couldn't start timehack (that's bad!)\n");
    exit (5);
}
Beispiel #7
0
	/**
	 * Create a sub process and start it, calling proc(param).
	 */
	ThreadObject_MorphOS(OTTDThreadFunc proc, void *param, self_destruct) :
		m_thr(0), self_destruct(self_destruct)
	{
		struct Task *parent;

		KPutStr("[OpenTTD] Create thread...\n");

		parent = FindTask(NULL);

		/* Make sure main thread runs with sane priority */
		SetTaskPri(parent, 0);

		/* Things we'll pass down to the child by utilizing NP_StartupMsg */
		m_msg.func = proc;
		m_msg.arg  = param;

		m_replyport = CreateMsgPort();

		if (m_replyport != NULL) {
			struct Process *child;

			m_msg.msg.mn_Node.ln_Type = NT_MESSAGE;
			m_msg.msg.mn_ReplyPort    = m_replyport;
			m_msg.msg.mn_Length       = sizeof(struct OTTDThreadStartupMessage);

			child = CreateNewProcTags(
				NP_CodeType,     CODETYPE_PPC,
				NP_Entry,        ThreadObject_MorphOS::Proxy,
				NP_StartupMsg,   (IPTR)&m_msg,
				NP_Priority,     5UL,
				NP_Name,         (IPTR)"OpenTTD Thread",
				NP_PPCStackSize, 131072UL,
				TAG_DONE);

			m_thr = (APTR) child;

			if (child != NULL) {
				KPutStr("[OpenTTD] Child process launched.\n");
			} else {
				KPutStr("[OpenTTD] Couldn't create child process. (constructors never fail, yeah!)\n");
				DeleteMsgPort(m_replyport);
			}
		}
	}
int Sys_Thread_SetThreadPriority(struct SysThread *thread, enum SysThreadPriority priority)
{
	int pri;

	switch(priority)
	{
		case SYSTHREAD_PRIORITY_LOW:
			pri = -1;
			break;
		case SYSTHREAD_PRIORITY_HIGH:
			pri = 4;
			break;
		default:
			pri = 0;
			break;
	}

	SetTaskPri(&thread->process->pr_Task, pri);

	return 0;
}
Beispiel #9
0
int main(int argc, char **argv)
{
    struct IntuitionBase *ibase;
    struct InputEvent *iev;
    struct IOStdReq *ioreq = 0;
    struct MsgPort *port;

    struct timerequest *timereq = 0;
    struct MsgPort *timeport;
    int oldx = 0, oldy = 0;
    int i;

    i = (*calltrap) (0);
    if (i == 0) {
	fprintf(stderr, "mousehack not needed for this version of UAE.\n");
	exit (0);
    }
    if (i == -1) {
	fprintf(stderr, "mousehack already running.\n");
	exit (5);
    }

    i = AllocSignal (-1);
    if (i < 0)
	goto fail;
    foo.sigbit = 1 << i;

    port = CreatePort(0, 0);
    timeport = CreatePort (0, 0);
    if (port)
	ioreq = CreateStdIO(port);

    if (timeport)
	timereq = CreateStdIO(timeport);

    if (ioreq == 0)
	goto fail;
    if (timereq == 0)
	goto fail;

    iev = AllocMem (sizeof (struct InputEvent), MEMF_CLEAR + MEMF_PUBLIC);
    if (iev == 0)
	goto fail;
    if (OpenDevice ("input.device", 0, ioreq, 0) != 0)
	goto fail;
    if (OpenDevice ("timer.device", 0, timereq, 0) != 0)
	goto fail;

    foo.mx = (ULONG)-1;
    foo.my = (ULONG)-1;
    foo.mt = FindTask (0);
    AddIntServer(INTB_VERTB, &myint);

    ibase = OpenLibrary ("intuition.library", 0);
    SetTaskPri (foo.mt, 20); /* same as input.device */
    for (;;) {
	int newx, newy;

	Wait (foo.sigbit);
	ioreq->io_Command = IND_WRITEEVENT;
	ioreq->io_Length = sizeof (struct InputEvent);
	ioreq->io_Data = iev;
	ioreq->io_Flags = IOF_QUICK;
	iev->ie_Class = IECLASS_POINTERPOS;
	iev->ie_SubClass = 0;
	iev->ie_Code = 0;
	iev->ie_Qualifier = 0;
#if 0
	newx = (*calltrap) (1);
	newy = (*calltrap) (2);

	if (oldy != newy || oldx != newx)
#endif
	{
	    timereq->tr_node.io_Flags = IOF_QUICK;
	    timereq->tr_node.io_Command = TR_GETSYSTIME;
	    DoIO (timereq);
	    iev->ie_TimeStamp = timereq->tr_time;
	    /* Those are signed, so I hope negative values are OK... */
	    /* I wonder why I have to multiply those by 2... but it works,
	     * at least for me. */
	    iev->ie_position.ie_xy.ie_x = foo.mx - ibase->ViewLord.DxOffset*2;
	    iev->ie_position.ie_xy.ie_y = foo.my - ibase->ViewLord.DyOffset*2;

	    oldx = newx;
	    oldy = newy;
	    DoIO(ioreq);
	}
#if 0
	timereq->tr_node.io_Flags = IOF_QUICK;
	timereq->tr_time.tv_secs = 0;
	timereq->tr_time.tv_micro = 20000;
	timereq->tr_node.io_Command = TR_ADDREQUEST;
	DoIO(timereq);
#endif
    }
    fail:
    fprintf (stderr, "Couldn't start mousehack (that's bad!)\n");
    exit (5);
}
Beispiel #10
0
extern void uae_set_thread_priority (int pri)
{
    SetTaskPri (FindTask (NULL), pri);
}
Beispiel #11
0
int main(void)
{
    if (IntuitionBase->LibNode.lib_Version == VERSION_NUMBER)
    {
        struct MsgPort *port = CreateMsgPort();
        if (port)
        {
            struct IOStdReq *req = CreateIORequest(port, sizeof(*req));
            if (req)
            {
                if (OpenDevice("input.device", 0, req, 0) == 0)
                {
                    BYTE old_pri;

                    req->io_Command = IND_ADDHANDLER;
                    req->io_Data = &interrupt;
                    DoIO(req);

                    /* Make sure we have a higher priority than the
                     * input.device, in case it gets trapped in an
                     * endless loop.
                     */
                    old_pri = SetTaskPri(FindTask(NULL), 50);

                    /* Also dump if intuition's input handler has been
                     * frozen for more than 2s.
                     */
                    do
                    {
                        ULONG old_secs = IntuitionBase->Seconds;
                        ULONG old_micros = IntuitionBase->Micros;

                        Delay(200);

                        if (old_secs == IntuitionBase->Seconds &&
                                old_micros == IntuitionBase->Micros)
                        {
                            REG_A6 = (ULONG)IntuitionBase;
                            MyEmulHandle->EmulCallDirectOS(-152 * 6);

                            do
                            {
                                Delay(50);
                            }
                            while (old_secs == IntuitionBase->Seconds &&
                                    old_micros == IntuitionBase->Micros);

                        }
                    }
                    while ((SetSignal(0,0) & 0x1000) == 0);

                    SetTaskPri(FindTask(NULL), old_pri);

                    req->io_Command = IND_REMHANDLER;
                    req->io_Data = &interrupt;
                    DoIO(req);

                    CloseDevice(req);
                }

                DeleteIORequest(req);
            }

            DeleteMsgPort(port);
        }
    }

    return 0;
}
Beispiel #12
0
BOOPSI_DISPATCHER_END

int main(void) {

    SetTaskPri(FindTask(NULL), 15);

    struct MUI_CustomClass *mcc;

    if((ps = OpenLibrary("poseidon.library", 4))) {

        if((mcc = MUI_CreateCustomClass(NULL, "Area.mui", NULL, sizeof(struct InstData), classdispatcher))) {
            mybug(-1,("mui custon class at %p\n", mcc));

            Object *app, *window, *tick1, *custom;

            app = ApplicationObject,
            SubWindow, window = WindowObject,
                MUIA_Window_Title, "PS3Eye",
                    MUIA_Window_Activate, TRUE,
                        WindowContents, HGroup,
		    		        Child, HGroup,
		    			        MUIA_Weight, 100,
		    			        Child, custom = NewObject(mcc->mcc_Class, NULL, TAG_DONE),
		    		        End,

                            Child, VGroup,
                                MUIA_Weight, 1,
                                MUIA_Group_SameWidth, TRUE,
                                GroupFrameT("Configuration"),
                                    Child, HGroup,
                                        Child, tick1 = MUI_MakeObject(MUIO_Checkmark, NULL),
                                        Child, MUI_MakeObject(MUIO_Label,"640x480", 0),
                                    End,
                                Child, (IPTR) VSpace(0),
                            End,
                        End,
                    End,
                End;

            if(app) {
                ULONG sigs = 0;

                DoMethod(tick1, MUIM_Notify, MUIA_Selected, TRUE,  (IPTR)custom, 3, MUIM_Set, MUIA_Resolution, TRUE);
                DoMethod(tick1, MUIM_Notify, MUIA_Selected, FALSE, (IPTR)custom, 3, MUIM_Set, MUIA_Resolution, FALSE);

                DoMethod(window, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);

                set(window, MUIA_Window_Open, TRUE);

                while((LONG)DoMethod(app, MUIM_Application_NewInput, &sigs) != (LONG)MUIV_Application_ReturnID_Quit) {
                    if(sigs) {
                        sigs = Wait(sigs | SIGBREAKF_CTRL_C);
                        if(sigs & SIGBREAKF_CTRL_C)
                            break;
                    }
                }

                MUI_DisposeObject(app);
            }

            MUI_DeleteCustomClass(mcc);
        }
        CloseLibrary(ps);
    }

    mybug(-1,("Exiting\n"));
    return 0;
}
Beispiel #13
0
int main (int argc, char **argv)
{
    struct timerequest *timereq = 0;
    struct MsgPort *timeport;
    struct timeval *tz_offset;
    struct Device *TimerBase;
    int quit = 0;
    int result = calltrap (0, 0);

    if (result == 1)
        fputs ("timehack already running.\n", stderr);
    else if (result == 2)
        fputs ("timehack not supported with this version of UAE.\n", stderr);
    if (result != 0)
        exit (5);

    timeport = (struct MsgPort *) CreatePort (0, 0);
    if (timeport)
        timereq = (struct timerequest *) CreateStdIO(timeport);

    if (timereq == 0)
        goto fail;

    if (OpenDevice ("timer.device", UNIT_VBLANK, (struct IORequest *) timereq, 0) != 0)
        goto fail;
    TimerBase = timereq->tr_node.io_Device;

    SetTaskPri (FindTask (NULL), 20); /* same as input.device */

    tz_offset = get_tz_offset();

    while (!quit) {
        struct timeval cur_sys_time;

        timereq->tr_node.io_Command = TR_GETSYSTIME;
        DoIO ((struct IORequest *)timereq);
        cur_sys_time = timereq->tr_time;
        calltrap (1, &timereq->tr_time);
        if (timereq->tr_time.tv_secs != cur_sys_time.tv_secs
                || (timereq->tr_time.tv_secs == cur_sys_time.tv_secs
                    && ABS(timereq->tr_time.tv_micro - cur_sys_time.tv_micro) > 1000))
        {
            AddTime (&timereq->tr_time, tz_offset);
            timereq->tr_node.io_Command = TR_SETSYSTIME;
            DoIO ((struct IORequest *)timereq);
        }

        timereq->tr_time.tv_secs = 1;
        timereq->tr_time.tv_micro = 0;
        timereq->tr_node.io_Command = TR_ADDREQUEST;
        DoIO ((struct IORequest *)timereq);

        if (SetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
            quit = TRUE;
    }
    /* Exit and error handling badly needs tidying up - Rich */
    CloseDevice ((struct IORequest *)timereq);
    DeleteStdIO ((struct IOStdReq *)timereq);
    DeletePort (timeport);
    exit (0);

fail:
    fputs ("Couldn't start timehack (that's bad!)\n", stderr);
    exit (5);
}
Beispiel #14
0
int amigaInit(int *argc, char **argv[])
{
   int done = TRUE;

   #if !defined(__POWERUP__) && !defined(__amigaos4__) && !defined(__MORPHOS__)
   if (!MemInit()) return FALSE;
   #endif

   #ifdef __OS3PPC__
   /*
   ** PPC
   */

   /* Set the priority of the PPC 68k mirror main task */
   #ifdef CHANGE_MIRROR_TASK_PRI
   Old68kMirrorPri = SetTaskPri(FindTask(NULL), 2);
   #endif

   #ifdef __POWERUP__
   /*
   ** PowerUp
   */
   /* Requires ppc.library 46.30 (or PPCLibEmu), due to timer/signal bugs */
   #define PPCINFOTAG_EMULATION (TAG_USER + 0x1f0ff)
   if (PPCGetAttr(PPCINFOTAG_EMULATION) == 'WARP') {
      if (!((PPCVersion() == 46 && PPCRevision() >= 29) || PPCVersion() > 46)) {
         printf("Requires PPCLibEmu 0.8a or higher!\n");
         done = FALSE;
      }
   }
   else {
      if (!((PPCVersion() == 46 && PPCRevision() >= 30) || PPCVersion() > 46)) {
         printf("Requires ppc.library 46.30 or higher!\n");
         done = FALSE;
      }
   }
   if (done) {
      if (PPCGetTaskAttr(PPCTASKTAG_STACKSIZE) < 200000) {
         printf("Please increase stack size to at least 200000 bytes!\n");
         done = FALSE;
      }
   }
   if (done) {
      done = ((PPCLibBase = OpenLibrary("ppc.library",46)) != NULL);
   }
   if (done) {
      struct TagItem tags[2] = { {PPCPORTTAG_NAME, (ULONG)"dnetc"}, {TAG_END,0} };
      void *port;
      if (!(port = PPCObtainPort(tags))) {
         done = FALSE;
         if ((TriggerPort = PPCCreatePort(tags))) {
            done = TRUE;
         }
      }
      else {
         PPCReleasePort(port);
      }
   }
   #else
   /*
   ** WarpOs
   */
   if (!FindPortPPC("dnetc")) {
      if ((TriggerPort = CreateMsgPortPPC())) {
         TriggerPort->mp_Port.mp_Node.ln_Name = "dnetc";
         TriggerPort->mp_Port.mp_Node.ln_Pri = 0;
         AddPortPPC(TriggerPort);
      }
      else {
         done = FALSE;
      }
   }
   #endif

   #else
   /*
   ** 68K / OS4 / MorphOS
   */

   struct MsgPort *portexists;

   Forbid();

   portexists = FindPort("dnetc");
   if (!portexists) {
      if ((TriggerPort = CreateMsgPort())) {
         TriggerPort->mp_Node.ln_Name = "dnetc";
         TriggerPort->mp_Node.ln_Pri = 0;
         AddPort(TriggerPort);
      }
      else {
         done = FALSE;
      }
   }

   Permit();
   #endif

   if (!TimerBase && done) done = GlobalTimerInit();

   if (!done) amigaExit();

   #ifndef NO_GUI
   /* Workbench startup */
   if (done && *argc == 0) {
      struct WBStartup *wbs = (struct WBStartup *)*argv;
      struct WBArg *arg = wbs->sm_ArgList;
      static char *newargv[1];
      newargv[0] = (char *)arg->wa_Name;

      *argc = 1;
      *argv = newargv;

      if (wbs->sm_NumArgs > 1) {
         /* Started via a project icon */
         arg = &wbs->sm_ArgList[1];
      }

      if (!(amigaGUIInit((char *)wbs->sm_ArgList->wa_Name,arg))) {
         if (!(amigaOpenNewConsole("CON://630/300/distributed.net client/CLOSE/WAIT"))) {
            done = FALSE;
         }
      }
   }
   #endif

   #if USE_RESETHANDLER
   if (done) {
      add_resethandler();
   }
   #endif

   return(done);
}
Beispiel #15
0
// Initialise a new lister
IPC_StartupCode(lister_init, Lister *, lister, static)
{
	// Store IPC and lister pointers
	lister->ipc=ipc;
	ipc->userdata=lister;

	// Store IPC pointer in backdrop info
	lister->backdrop_info->ipc=ipc;

	// Path history list
	lister->path_history=Att_NewList(LISTF_LOCK);

	// Initialise reselection
	InitReselect(&lister->reselect);
	lister->abort_signal=-1;

	// Create message ports and signals
	if (!(lister->app_port=CreateMsgPort()) ||
		!(lister->timer_port=CreateMsgPort()) ||
		(lister->hot_name_bit=AllocSignal(-1))==-1 ||
		(lister->abort_signal=AllocSignal(-1))==-1)
		return 0;

	// Allocate some timers
	if (!(lister->busy_timer=AllocTimer(UNIT_VBLANK,lister->timer_port)) ||
		!(lister->scroll_timer=AllocTimer(UNIT_VBLANK,lister->timer_port)) ||
		!(lister->edit_timer=AllocTimer(UNIT_VBLANK,lister->timer_port)) ||
		!(lister->foo_timer=AllocTimer(UNIT_VBLANK,lister->timer_port)))
		return 0;
	StartTimer(lister->foo_timer,5,0);

	// Create regions
	if (!(lister->title_region=NewRegion()) ||
		!(lister->refresh_extra=NewRegion()))
		return 0;

	// Lock buffer list
	lock_listlock(&GUI->buffer_list,TRUE);

	// Allocate initial buffer
	if (!(lister->cur_buffer=lister_get_empty_buffer()) &&
		!(lister->cur_buffer=lister_new_buffer(lister)))
		return 0;
	lister->cur_buffer->buf_CurrentLister=lister;

	// Unlock buffer list
	unlock_listlock(&GUI->buffer_list);

	// Allocate "special" buffer
	if (!(lister->special_buffer=buffer_new()))
		return 0;

	// Build popup menu
	lister_build_menu(lister);

	// Initialise flags
	lister->flags|=LISTERF_FIRST_TIME;
	lister->flags2|=LISTERF2_UNAVAILABLE;
	lister->tool_sel=-1;
	lister->toolbar_offset=0;

	// Fix priority
	lister->normal_pri=environment->env->settings.pri_lister[0];
	lister->busy_pri=environment->env->settings.pri_lister[1];
	SetTaskPri((struct Task *)lister->ipc->proc,lister->normal_pri);

	// Get font to use
	lister->lister_font.ta_Name=lister->font_name;
	lister->lister_font.ta_YSize=lister->font_size;
	lister->lister_font.ta_Flags=0;
	lister->lister_font.ta_Style=0;

	// Open font
	if ((lister->font=OpenDiskFont(&lister->lister_font)))
	{
		// Proportional	font?
		if (lister->font->tf_Flags&FPF_PROPORTIONAL)
			lister->more_flags|=LISTERF_PROP_FONT;

		// Set font in text area
		InitRastPort(&lister->text_area.rast);
		SetFont(&lister->text_area.rast,lister->font);
	}

	return 1;
}