void SAVEDS handler(void) { struct Process *me = (struct Process *)FindTask(NULL); struct startMsg *smsg; struct MsgPort *port; BOOL res = FALSE; ENTER(); WaitPort(&me->pr_MsgPort); smsg = (struct startMsg *)GetMsg(&me->pr_MsgPort); #if defined(__amigaos4__) port = AllocSysObject(ASOT_PORT, TAG_DONE); #else port = CreateMsgPort(); #endif if(port != NULL) res = localSendRexxMsg(port, smsg->port, smsg->cmd); smsg->res = res; ReplyMsg((struct Message *)smsg); if(res == TRUE) { struct RexxMsg *rxmsg; WaitPort(port); rxmsg = (struct RexxMsg *)GetMsg(port); DeleteArgstring((APTR)rxmsg->rm_Args[0]); DeleteRexxMsg(rxmsg); } if(port != NULL) { #if defined(__amigaos4__) FreeSysObject(ASOT_PORT, port); #else DeleteMsgPort(port); #endif } ObtainSemaphore(&OpenURLBase->libSem); OpenURLBase->rexx_use--; ReleaseSemaphore(&OpenURLBase->libSem); #if !defined(__amigaos4__) // all systems except OS4 should leave this function in forbidden state Forbid(); #endif LEAVE(); }
void RegisterARexxFunctionHost(int add) { struct RexxMsg *mess; struct MsgPort *rexxmastport; if(!(mess=(struct RexxMsg *)AllocMem(sizeof(struct RexxMsg), MEMF_CLEAR | MEMF_PUBLIC))) { cleanup(EXIT_ERROR, "Out of memory."); } mess->rm_Node.mn_Node.ln_Type = NT_MESSAGE; mess->rm_Node.mn_Length = sizeof(struct RexxMsg); mess->rm_Node.mn_ReplyPort=rexxport; mess->rm_Action = add ? RXADDFH : RXREMLIB; mess->rm_Args[0] = "NIKOMREXXHOST"; mess->rm_Args[1] = 0L; Forbid(); rexxmastport = (struct MsgPort *)FindPort("REXX"); if(rexxmastport) { PutMsg((struct MsgPort *)rexxmastport,(struct Message *)mess); } Permit(); if(rexxmastport == NULL) { FreeMem(mess, sizeof(struct RexxMsg)); if(add) { cleanup(EXIT_ERROR, "Can't find port 'REXX' (ARexx master server)"); } return; } WaitPort(rexxport); GetMsg(rexxport); FreeMem(mess, sizeof(struct RexxMsg)); }
static void action(void) { struct IntuiMessage *msg; do { WaitPort(win->UserPort); while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort))) { switch (msg->Class) { case IDCMP_CLOSEWINDOW: Keys[KC_ESC] = 1; break; case IDCMP_RAWKEY: { WORD code = msg->Code & ~IECODE_UP_PREFIX; Keys[code] = (code == msg->Code) ? 1 : 0; } break; } ReplyMsg((struct Message *)msg); } } while(!Keys[KC_ESC]); }
static void entry(void) { struct MsgPort *port1,*port2; struct Message *msg; Forbid(); port1=FindPort("message test port"); Permit(); port2=CreateMsgPort(); if(port2!=NULL) { msg=(struct Message *)CreateIORequest(port2,sizeof(struct Message)); if(msg!=NULL) { int i; for(i=0;i<10;i++) { msg->mn_Node.ln_Name=(char *)i; PutMsg(port1,msg); WaitPort(port2); GetMsg(port2); } DeleteIORequest((struct IORequest *)msg); } DeleteMsgPort(port2); } Signal(port1->mp_SigTask,1<<port1->mp_SigBit); Wait(0);/* Let the parent remove me */ }
VOID __saveds PingFunc( VOID ) { struct MsgPort *ClientPort, *ReplyPort; struct Library *SysBase; BlankMsg PingMsg; SysBase = *( struct Library ** )4L; if( ReplyPort = CreateMsgPort()) { PingMsg.bm_Mess.mn_ReplyPort = ReplyPort; PingMsg.bm_Mess.mn_Length = sizeof( BlankMsg ); PingMsg.bm_Type = BM_PING; /* Stealthimania, to alleviate processing at the blanker */ PingMsg.bm_Mess.mn_Node.ln_Name = ( UBYTE * )( &Blanking ); for( ;; ) { if( SetSignal( 0L, SIGBREAKF_CTRL_C ) & SIGBREAKF_CTRL_C ) break; if( ClientPort = FindPort( "GarshneClient" )) { PingMsg.bm_Flags = 0L; PutMsg( ClientPort, ( struct Message * )( &PingMsg )); WaitPort( ReplyPort ); GetMsg( ReplyPort ); } } DeletePort( ReplyPort ); } }
/* * Start proxy thread */ static int start_proxy_thread (void) { int result = -1; struct MsgPort *replyport = CreateMsgPort(); struct Process *p; if (replyport) { p = myCreateNewProcTags (NP_Name, (ULONG) "E-UAE semaphore proxy", NP_Priority, 10, NP_StackSize, 2048, NP_Entry, (ULONG) proxy_thread_main, TAG_DONE); if (p) { /* Send startup message */ struct Message msg; msg.mn_ReplyPort = replyport; msg.mn_Length = sizeof msg; PutMsg (&p->pr_MsgPort, (struct Message*)&msg); WaitPort (replyport); proxy_thread = p; atexit (stop_proxy_thread); result = 0; } DeleteMsgPort (replyport); } return result; }
// Send an IPC startup int ASM L_IPC_Startup( REG(a0, IPCData *ipc), REG(a1, APTR data), REG(a2, struct MsgPort *reply)) { struct MsgPort *port=0; IPCMessage startup; // If no message port supplied, create one if (!reply) port=reply=CreateMsgPort(); // Fill out startup message startup.msg.mn_ReplyPort=reply; startup.command=IPC_STARTUP; startup.flags=(ULONG)ipc; startup.data=data; // Send the startup message PutMsg(&ipc->proc->pr_MsgPort,(struct Message *)&startup); // Wait for reply back WaitPort(reply); GetMsg(reply); // Delete port if we created one if (port) DeleteMsgPort(port); // If there's no command port, report failure if (startup.command!=IPC_STARTUP) return 0; return 1; }
int uae_start_thread (void *(*f) (void *), void *arg, uae_thread_id *foo) { struct MsgPort *replyport = CreateMsgPort(); if (replyport) { *foo = (struct Task *)myCreateNewProcTags (NP_Output, Output (), NP_Input, Input (), NP_Name, (ULONG) "UAE thread", NP_CloseOutput, FALSE, NP_CloseInput, FALSE, NP_StackSize, 16384, NP_Entry, (ULONG) do_thread, TAG_DONE); if(*foo) { struct startupmsg msg; msg.msg.mn_ReplyPort = replyport; msg.msg.mn_Length = sizeof msg; msg.func = f; msg.arg = arg; PutMsg (&((struct Process*)*foo)->pr_MsgPort, (struct Message*)&msg); WaitPort (replyport); } DeleteMsgPort (replyport); } return *foo!=0; }
/* this function waits for a packet to come back from the file system. If no * packet is pending, state from the previous packet is returned. This ensures * that once an error occurs, it state is maintained for the rest of the life * of the file handle. * * This function also deals with IO errors, bringing up the needed DOS * requesters to let the user retry an operation or cancel it. */ LONG AS_WaitPacket( AsyncFile *file ) { #ifdef ASIO_NOEXTERNALS struct ExecBase *SysBase = file->af_SysBase; struct DosLibrary *DOSBase = file->af_DOSBase; #endif LONG bytes; if( file->af_PacketPending ) { while( TRUE ) { /* This enables signalling when a packet comes back to the port */ file->af_PacketPort.mp_Flags = PA_SIGNAL; /* Wait for the packet to come back, and remove it from the message * list. Since we know no other packets can come in to the port, we can * safely use Remove() instead of GetMsg(). If other packets could come in, * we would have to use GetMsg(), which correctly arbitrates access in such * a case */ Remove( ( struct Node * ) WaitPort( &file->af_PacketPort ) ); /* set the port type back to PA_IGNORE so we won't be bothered with * spurious signals */ file->af_PacketPort.mp_Flags = PA_IGNORE; /* mark packet as no longer pending since we removed it */ file->af_PacketPending = FALSE; bytes = file->af_Packet.sp_Pkt.dp_Res1; if( bytes >= 0 ) { /* packet didn't report an error, so bye... */ return( bytes ); } /* see if the user wants to try again... */ if( ErrorReport( file->af_Packet.sp_Pkt.dp_Res2, REPORT_STREAM, file->af_File, NULL ) ) { return( -1 ); } /* user wants to try again, resend the packet */ AS_SendPacket( file, file->af_Buffers[ file->af_ReadMode ? file->af_CurrentBuf : 1 - file->af_CurrentBuf ] ); } } /* last packet's error code, or 0 if packet was never sent */ SetIoErr( file->af_Packet.sp_Pkt.dp_Res2 ); return( file->af_Packet.sp_Pkt.dp_Res1 ); }
BOOL IPC_PutMsg( struct MsgPort *destino, IPCACT_T action, APTR udata ) { struct MsgPort *replyport = NULL; BOOL error = TRUE; ENTER(); DBG_POINTER(destino); if(destino && (replyport = CreateMsgPort())) { struct IPCMsg ipcmsg; APTR xMsg; ipcmsg.ipc_msg.mn_ReplyPort = replyport; ipcmsg.ipc_msg.mn_Length = sizeof(struct IPCMsg); ipcmsg.ipc_ID = IPC_MAGIC; ipcmsg.ipc_action = action; ipcmsg.ipc_result = IPCR_ABORTED; ipcmsg.ipc_data = udata; DBG("Sending action '%ld' from %lx to %lx\n", action, replyport, destino); Forbid(); PutMsg( destino, &ipcmsg.ipc_msg); WaitPort(replyport); while((xMsg = GetMsg( replyport ))) { DBG("Got reply...\n"); switch(((struct IPCMsg *)xMsg)->ipc_result) { // TODO case IPCR_ABORTED: DBG("IPCR_ABORTED\n"); break; case IPCR_FAIL: DBG("IPCR_FAIL\n"); break; case IPCR_OK: DBG("IPCR_OK\n"); break; default: break; } } Permit(); DeleteMsgPort(replyport); error = FALSE; } LEAVE(); return !error; }
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); }
void ASERDPort::send_to_proc(uint32 what, uint32 pb) { D(bug("sending %08lx to serial_proc\n", what)); SerMessage msg(what, reply_port); msg.pb = pb; PutMsg(proc_port, &msg); WaitPort(reply_port); GetMsg(reply_port); D(bug(" sent\n")); }
int commonsendrexx(int komnr,int hasarg) { char rexxCmd[1081]; struct RexxMsg *nikrexxmess, *mess; sendrexxrc = -5; if(!hasarg) { sprintf(rexxCmd, "NiKom:rexx/ExtKom%d %d %d", komnr, nodnr, inloggad); } else { sprintf(rexxCmd, "NiKom:rexx/ExtKom%d %d %d %s", komnr, nodnr, inloggad, argument); } if(!(nikrexxmess = (struct RexxMsg *) CreateRexxMsg( rexxport, "nik", rexxport->mp_Node.ln_Name))) { LogEvent(SYSTEM_LOG, ERROR, "Couldn't allocate a RexxMsg."); return -5; } if(!(nikrexxmess->rm_Args[0] = (STRPTR)CreateArgstring(rexxCmd,strlen(rexxCmd)))) { DeleteRexxMsg(nikrexxmess); LogEvent(SYSTEM_LOG, ERROR, "Couldn't allocate a rexx ArgString."); return -5; } nikrexxmess->rm_Action = RXCOMM | RXFB_TOKEN; if(!SafePutToPort((struct Message *)nikrexxmess, "REXX")) { LogEvent(SYSTEM_LOG, ERROR, "Can't launch ARexx script, REXX port not found."); return -5; } for(;;) { mess = (struct RexxMsg *)WaitPort(rexxport); while(mess = (struct RexxMsg *)GetMsg(rexxport)) { if(mess->rm_Node.mn_Node.ln_Type == NT_REPLYMSG) { DeleteArgstring(nikrexxmess->rm_Args[0]); if(nikrexxmess->rm_Result1) { LogEvent(SYSTEM_LOG, WARN, "Error return code %d from ARexx script: '%s'", nikrexxmess->rm_Result1, rexxCmd); SendString("\r\n\nError executing ARexx script.\r\n\n"); } DeleteRexxMsg(nikrexxmess); if(!rxlinecount) { rxlinecount=TRUE; radcnt = 0; } return sendrexxrc; } handleRexxCommand(mess->rm_Args[0], mess); ReplyMsg((struct Message *)mess); } } if(carrierdropped()) return(-8); return(sendrexxrc); }
// Send an ARexx command long __asm __saveds HookRexxCommand( register __a0 char *command, register __a1 char *result, register __d0 long length, register __a2 struct MsgPort *replyport, register __d1 ULONG flags) { struct MsgPort *rexx,*reply; struct RexxMsg *msg; long rc=-1; // Clear result if (result) *result=0; // Get rexx port if (!GUI->rexx_proc || !(rexx=(struct MsgPort *)IPCDATA(GUI->rexx_proc))) return -1; // Create reply port if needed if ((reply=replyport) || (reply=CreateMsgPort())) { // Create message if (msg=BuildRexxMsgExTags( reply, ".dopus5", rexx->mp_Node.ln_Name, RexxTag_Arg0,command, TAG_END)) { // Initialise message msg->rm_Action|=1|RXCOMM; if (result) msg->rm_Action|=RXFF_RESULT; // Send the message and wait for reply PutMsg(rexx,(struct Message *)msg); WaitPort(reply); GetMsg(reply); // String reply? if (msg->rm_Result2 && result) stccpy(result,(char *)msg->rm_Result2,length); rc=msg->rm_Result1; // Free message FreeRexxMsgEx(msg); } // Free message port if (reply!=replyport) DeleteMsgPort(reply); } return rc; }
int getchar(void) { struct AmigaIO *ior; char c = '\n'; struct Console *mc = ConsoleBase; unsigned long ticks; #ifdef SERCONSOLE int32_t r; #endif mc->cnior->length = 1; mc->cnior->buf = &c; mc->cnior->cmd = Cmd_Rd; SendIO(mc->cnior); ticks = 10 * timelimit; do { if (timelimit == 0) ticks = 2; mc->tmior->cmd = Cmd_Addtimereq; mc->tmior->secs = 0; mc->tmior->usec = 100000; SendIO((struct AmigaIO *)mc->tmior); ior = WaitPort(mc->cnmp); if (ior == mc->cnior) { AbortIO((struct AmigaIO *)mc->tmior); ticks = 1; } else /* if (ior == mc->tmior) */ { #ifdef SERCONSOLE if (use_serconsole) { r = RawMayGetChar(); if (r != -1) { c = r; ticks = 1; } } #endif if (ticks == 1) AbortIO((struct AmigaIO *)mc->cnior); } WaitIO((struct AmigaIO *)mc->tmior); --ticks; } while (ticks != 0); timelimit = 0; (void)WaitIO(mc->cnior); return c; }
static int16 send_to_proc(uint32 what, uint32 pointer = 0, uint16 type = 0) { D(bug("sending %08lx to net_proc\n", what)); NetMessage msg(what, reply_port); msg.pointer = pointer; msg.type = type; PutMsg(proc_port, &msg); WaitPort(reply_port); GetMsg(reply_port); D(bug(" sent\n")); return msg.result; }
int uae_start_thread (const TCHAR *name, void *(*f)(void *), void *arg, uae_thread_id *tid) { struct MsgPort *replyport; struct Process *newtask = NULL; struct TagItem procTags[] = { { NP_Name, (IPTR) NULL}, { NP_StackSize, (IPTR)(64 * 1024)}, { NP_Entry, (IPTR) do_thread}, //{ NP_Output, Output ()}, //{ NP_Input, Input ()}, //{ NP_CloseOutput, FALSE}, //{ NP_CloseInput, FALSE}, { TAG_DONE, 0} }; #warning Do we need to care for priorities here? WinUAE does.. if(!name) procTags[0].ti_Data = (IPTR)default_name; else procTags[0].ti_Data = (IPTR)name; bug("[JUAE:PX] %s('%s', f %lx, arg %lx, tid %lx)\n", __PRETTY_FUNCTION__, procTags[0].ti_Data, f, arg, tid); replyport = CreateMsgPort(); if(!replyport) { write_log("ERROR: Unable to create MsgPort!\n"); } newtask = CreateNewProc (procTags); bug("[JUAE:PX] %s: Process @ %p, MsgPort @ %p\n", __PRETTY_FUNCTION__, newtask, newtask->pr_MsgPort); if(newtask) { struct startupmsg msg; msg.msg.mn_ReplyPort = replyport; msg.msg.mn_Length = sizeof msg; msg.func = f; msg.arg = arg; PutMsg (&newtask->pr_MsgPort, (struct Message*)&msg); WaitPort (replyport); } DeleteMsgPort (replyport); if(tid) { *tid=newtask; } return (newtask != 0); }
/************* * DESCRIPTION: send a message to a subtask and wait for reply * INPUT: st subtask structure * command * params * OUTPUT: result returned from subtask *************/ LONG SendSubTaskMsg(struct SubTask *st, WORD command, APTR params) { st->st_Message.stm_Message.mn_ReplyPort = (struct MsgPort*)&st->st_Reply; st->st_Message.stm_Message.mn_Length = sizeof(struct SubTaskMsg); st->st_Message.stm_Command = command; st->st_Message.stm_Parameter = params; st->st_Message.stm_Result = 0; PutMsg(command==STC_STARTUP ? &((struct Process *)st->st_Task)->pr_MsgPort : st->st_Port,(struct Message *)&st->st_Message); WaitPort(&st->st_Reply); GetMsg(&st->st_Reply); return(st->st_Message.stm_Result); }
static void do_thread (void) { struct Process *pr = (struct Process *) FindTask (NULL); struct startupmsg *msg; void *(*func) (void *); void *arg; WaitPort (&pr->pr_MsgPort); msg = (struct startupmsg *) GetMsg(&pr->pr_MsgPort); func = msg->func; arg = msg->arg; ReplyMsg ((struct Message*)msg); func (arg); }
/* virtual */ void Join() { struct OTTDThreadStartupMessage *reply; /* You cannot join yourself */ assert(!IsCurrent()); KPutStr("[OpenTTD] Join threads...\n"); KPutStr("[OpenTTD] Wait for child to quit...\n"); WaitPort(m_replyport); GetMsg(m_replyport); DeleteMsgPort(m_replyport); m_thr = 0; }
ULONG TellWBTaskToCloseWindows(struct IntuitionBase *IntuitionBase) { DEBUG_WORKBENCH(dprintf("TellWBTaskToCloseWindows: currenttask <%s>\n", FindTask(NULL)->tc_Node.ln_Name)); if ( GetPrivIBase(IntuitionBase)->WorkBenchMP != NULL && GetPrivIBase(IntuitionBase)->WorkBenchMP->mp_SigTask != FindTask(NULL) ) { struct MsgPort replymp; struct IntuiMessage imsg; /* Setup our reply port. By doing this manually, we can use SIGB_SINGLE * and thus avoid allocating a signal (which may fail). */ memset( &replymp, 0, sizeof( replymp ) ); replymp.mp_Node.ln_Type = NT_MSGPORT; replymp.mp_Flags = PA_SIGNAL; replymp.mp_SigBit = SIGB_SINGLE; replymp.mp_SigTask = FindTask( NULL ); NEWLIST( &replymp.mp_MsgList ); /* Setup our message */ imsg.ExecMessage.mn_ReplyPort = &replymp; imsg.Class = IDCMP_WBENCHMESSAGE; imsg.Code = WBENCHCLOSE; SetSignal(0, SIGF_SINGLE); DEBUG_WORKBENCH(dprintf("TellWBTaskToCloseWindows: Send Msg\n")); /* Sends it to the handler and wait for the reply */ PutMsg( GetPrivIBase(IntuitionBase)->WorkBenchMP, (struct Message *) &imsg ); WaitPort( &replymp ); /* After leaving this block imsg and repymp will be automagically freed, * so we don't have to deallocate them ourselves. */ DEBUG_WORKBENCH(dprintf("TellWBTaskToCloseWindows: done\n")); return(TRUE); } else { DEBUG_WORKBENCH(dprintf("TellWBTaskToCloseWindows: no Workbench port\n")); } return(FALSE); }
static void action(void) { UBYTE *buf = AllocVec(SCREENWIDTH * SCREENHEIGHT * sizeof(ULONG), MEMF_PUBLIC); ULONG i; if (buf) { ReadPixelArray(buf, 0, 0, SCREENWIDTH * sizeof(ULONG), win->RPort, win->BorderLeft, win->BorderTop, SCREENWIDTH, SCREENHEIGHT, RECTFMT_ARGB); for(i = 0; i < SCREENWIDTH * SCREENHEIGHT * 4; i += 4) { buf[i + 1] /= 2; buf[i + 2] /= 2; buf[i + 3] /= 2; } WritePixelArray(buf, 0, 0, SCREENWIDTH * sizeof(ULONG), win->RPort, win->BorderLeft, win->BorderTop, SCREENWIDTH, SCREENHEIGHT, RECTFMT_ARGB); } while (!Keys[KC_ESC]) { WaitPort(win->UserPort); getevents(); } /* while(!Keys[KC_ESC]) */ if (buf) FreeVec(buf); }
// USER int emulator::doEvents(context *ctx) { DEBUG(3) dprintf("emulator::doEvents() called. this=%p, ctx=%p\n", this, ctx); struct Message *aros_msg; message *msg; while(1) { while((aros_msg = GetMsg(ctx->port))) { msg = message::fromAros(aros_msg); switch(msg->getCmd()) { case message::RUN_EXIT: msg->free(); return 0; case message::SYS_CALL: if(ctx->currentModule) { module::hook_status ret = ctx->currentModule->syscall_hook_2(ctx); if(ret == module::HOOK_DONE) { msg->setCmd(message::SYS_RETURN); msg->sendToEmulator(); } else if(ret == module::HOOK_CALLBACK) { msg->free(); return 1; } else { DEBUG(2) dprintf("emulator::doEvents(): Unknown return code from hook::syscall_2(), ignoring\n"); msg->free(); } } break; default: DEBUG(2) dprintf("emulator::doEvents(): Unknown message received, ignoring\n"); msg->free(); break; } } // Nothing in queue DEBUG(5) dprintf("emulator::doEvents(): Nothing to do, sleeping...\n"); WaitPort(ctx->port); DEBUG(5) dprintf("emulator::doEvents(): Woke up!\n"); } return 0; }
static void handleall(void) { struct IntuiMessage *msg; BOOL quitme = FALSE; while(!quitme) { WaitPort(win->UserPort); while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort))) { switch(msg->Class) { case IDCMP_CLOSEWINDOW: quitme = TRUE; break; case IDCMP_IDCMPUPDATE: { struct ColorWheelRGB rgb; struct ColorWheelHSB hsb; struct TagItem *tags = (struct TagItem *)msg->IAddress; hsb.cw_Hue = GetTagData(WHEEL_Hue, 0, tags); hsb.cw_Saturation = GetTagData(WHEEL_Saturation, 0, tags); hsb.cw_Brightness = 0xFFFFFFFF; ConvertHSBToRGB(&hsb, &rgb); SetRGB32(vp, pen1, rgb.cw_Red, rgb.cw_Green, rgb.cw_Blue); if (truecolor) { RefreshGList(gradgad, win, 0, 1); } } break; } /* switch(msg->Class) */ ReplyMsg((struct Message *)msg); } /* while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort))) */ } /* while(!quitme) */ }
static void action(void) { int x, y; for(y = 0; y < SCREENHEIGHT; y++) { for(x = 0; x < SCREENWIDTH; x++) { buf[y * SCREENWIDTH + x] = (y + x) & 255; } } SetABPenDrMd(rp, 1, 2, JAM1); BltTemplateAlpha(buf, 0, SCREENWIDTH, rp, win->BorderLeft, win->BorderTop, SCREENWIDTH, SCREENHEIGHT); WaitPort(win->UserPort); }
static void do_thread (void) { struct Process *pr = (struct Process *) FindTask (NULL); struct startupmsg *msg; void *(*func) (void *); void *arg; bug("[JUAE:PX] %s()\n", __PRETTY_FUNCTION__); bug("[JUAE:PX] %s: task = %p\n", __PRETTY_FUNCTION__, pr); WaitPort (&pr->pr_MsgPort); msg = (struct startupmsg *) GetMsg(&pr->pr_MsgPort); func = msg->func; arg = msg->arg; ReplyMsg ((struct Message*)msg); func (arg); }
/************* * DESCRIPTION: initialize a subtask and reply INIT message * INPUT: - * OUTPUT: subtask structure received from main task *************/ struct SubTask *InitSubTask() { struct Process *me = (struct Process*)FindTask(NULL); struct SubTask *st; struct SubTaskMsg *stm; BOOL done=FALSE; // Wait for our startup message and ignore all other messages while(!done) { WaitPort(&me->pr_MsgPort); while((stm = (struct SubTaskMsg *)GetMsg(&me->pr_MsgPort))) { if(stm->stm_Command == STC_STARTUP) { done = TRUE; break; } } } st = (struct SubTask *)stm->stm_Parameter; st->st_Port = CreateMsgPort(); if(st->st_Port) { /* ** Reply startup message, everything ok. ** Note that if the initialization fails, the code falls ** through and replies the startup message with a stm_Result ** of 0 after a Forbid(). This tells the calling function that the ** sub task failed to run. */ stm->stm_Result = TRUE; ReplyMsg((struct Message *)stm); return(st); } ExitSubTask(st,stm); return(NULL); }
long DoSyncPacket(MsgPort *dport, long action, long a1, long a2, long a3, long a4) { __aligned StdPacket std; clrmem(&std, sizeof(std)); std.sp_Msg.mn_Node.ln_Name = (char *)&std.sp_Pkt; std.sp_Pkt.dp_Link = &std.sp_Msg; std.sp_Pkt.dp_Port = AuxPort; std.sp_Pkt.dp_Type = action; std.sp_Pkt.dp_Arg1 = a1; std.sp_Pkt.dp_Arg2 = a2; std.sp_Pkt.dp_Arg3 = a3; std.sp_Pkt.dp_Arg4 = a4; dbprintf(("DoSynchPacket to %08lx type %08lx (%d) args %lx %lx %lx %lx\n", dport, std.sp_Pkt.dp_Type, std.sp_Pkt.dp_Type, std.sp_Pkt.dp_Arg1, std.sp_Pkt.dp_Arg2, std.sp_Pkt.dp_Arg3, std.sp_Pkt.dp_Arg4 )); PutMsg(dport, &std.sp_Msg); WaitPort(AuxPort); GetMsg(AuxPort); dbprintf(("Res1 %08lx Res2 %08lx\n", std.sp_Pkt.dp_Res1, std.sp_Pkt.dp_Res2 )); if (std.sp_Pkt.dp_Res1 == DOS_FALSE) return(-std.sp_Pkt.dp_Res2); /* if (std.sp_Pkt.dp_Res2 > 0) return(-std.sp_Pkt.dp_Res2); */ return(std.sp_Pkt.dp_Res1); }
/************* * FUNCTION: GetRexxMsg * VERSION: 0.1 08.03.1995 * DESCRIPTION: Picks up pending RexxMessages from a RexxHost and * returns them to the caller. I desired, will wait * for new messages to arrive if none is present yet * INPUT: RexxHost rexx host message port * Wait TRUE: wait for new messages * OUTPUT: received RexxMessage * HISTORY: DATE NAME COMMENT * 08.03.95 ah first release *************/ struct RexxMsg *GetRexxMsg(struct MsgPort *RexxHost,LONG Wait) { struct RexxMsg *RexxMessage = NULL; /* Valid pointer given? */ if(RexxHost) { /* Try to pick up a message. */ RexxMessage = (struct RexxMsg *)GetMsg((struct MsgPort *)RexxHost); while(!RexxMessage) { /* No message available. Are we to wait? */ if(Wait) WaitPort((struct MsgPort *)RexxHost); else break; } } /* Return the result (may be NULL). */ return(RexxMessage); }
void REGARGS DebugMail(struct Data *scr, MailSubj flag, long data2, void *data) { struct ExecBase *SysBase = *(struct ExecBase **)4; struct Messy mess; struct MsgPort *port; if(scr->flags&FPLDATA_DEBUG) { Forbid(); port=FindPort(MSGPORT_NAME); if (port) { struct MsgPort *answerport; answerport=CreateMsgPort(); if (answerport) { mess.mess.mn_Length=sizeof(struct Messy); mess.mess.mn_ReplyPort=answerport; mess.scr = scr; /* give them the world of FPL! */ mess.flag = flag; switch(flag) { case MAIL_START: case MAIL_EXIT: mess.data = NULL; break; default: mess.data = data; } mess.data2 = (void *)data2; PutMsg(port, (struct Message *)&mess); Permit(); WaitPort(answerport); DeleteMsgPort(answerport); /* Message sent */ } else { Permit(); } } else { Permit(); } } }