示例#1
0
static int WBInit(LIBBASETYPEPTR LIBBASE)
{
    /* Make sure that the libraries are opened in L_OpenLib() --------------*/
    WorkbenchBase->wb_Initialized = FALSE;

    /* Initialize our private lists ----------------------------------------*/
    NEWLIST(&(WorkbenchBase->wb_AppWindows));
    NEWLIST(&(WorkbenchBase->wb_AppIcons));
    NEWLIST(&(WorkbenchBase->wb_AppMenuItems));
    NEWLIST(&(WorkbenchBase->wb_HiddenDevices));

    /* Initialize our semaphores -------------------------------------------*/
    InitSemaphore(&(WorkbenchBase->wb_WorkbenchPortSemaphore));
    InitSemaphore(&(WorkbenchBase->wb_InitializationSemaphore));
    InitSemaphore(&(WorkbenchBase->wb_BaseSemaphore));
    
    /* Initialize handler message port -------------------------------------*/
    WorkbenchBase->wb_HandlerPort.mp_SigBit  = SIGBREAKB_CTRL_F;
    WorkbenchBase->wb_HandlerPort.mp_SigTask = NULL;      
    WorkbenchBase->wb_HandlerPort.mp_Flags   = PA_IGNORE;
    NEWLIST(&(WorkbenchBase->wb_HandlerPort.mp_MsgList));

#warning "TODO:  DefaultStackSize should differ depending on the platform AROS is compiled for"
    /* Initialize miscellanous variables -----------------------------------*/
    WorkbenchBase->wb_DefaultStackSize = 1024 * 32; /* 32kiB */ // FIXME: also read from preferences */
D(bug("[WBLIB] WBInit: Using %d Bytes for DefaultStackSize\n", WorkbenchBase->wb_DefaultStackSize));

    return TRUE;
}
示例#2
0
文件: hd.c 项目: jamjr/Helios-NG
/*
 * Initialise the device routines
 */
void hd_init(void)
{
	int h,i,j;

	for (h=0; h<MAX_HELIOS_DEVICES; h++) {
		InitSemaphore(&(hd[h].numbufs),0);
		InitSemaphore(&(hd[h].abort),0);
		hd[h].old = 0;
		hd[h].dcb = NULL;
		for (i=0; i<MAXDISKS; i++) {
			hd[h].disk[i].dk_lab = dflt_sizes;
			hd[h].disk[i].dk_wlabel = 0;
			hd[h].disk[i].dk_state = CLOSED;
			hd[h].disk[i].dk_protected = FALSE;
			hd[h].disk[i].dk_reads = 0;
			hd[h].disk[i].dk_writes = 0;
			InitSemaphore(&hd[h].disk[i].dk_numq,0);
			InitSemaphore(&hd[h].disk[i].dk_guard,1);
			hd[h].disk[i].dk_queue.b_actf = NULL;
			hd[h].disk[i].dk_queue.b_forw = NULL;
			for (j=0; j<MAXPARTITIONS; j++)
				hd[h].disk[i].dk_pstatus[j]=CLOSED;
		}
	}
}
示例#3
0
static struct ExpansionBase *exp_Init(struct ExpansionBase *ExpansionBase, UINT32 *segList, APTR SysBase)
{
	ExpansionBase->SysBase	= SysBase;

	NewListType(&ExpansionBase->BoardList, NT_PCILIST);
	InitSemaphore(&ExpansionBase->BoardListLock);

	NewListType(&ExpansionBase->MountList, NT_DOSLIST);
	InitSemaphore(&ExpansionBase->MountListLock);

	return ExpansionBase;
}
示例#4
0
void GetReady(void)
{
   /* get the parameters from the configure file. */
   InitNetworkParam();

   InitConfig();

   /* connect the parameter server from the master node. */
   InitParamClient();

   /* get the parameters from the master node. */
   GetParam();

   /* connect the message server from the master node,
	* the message server is used for inform the slave nodes
	* that every nodes have loaded the data. */
   InitMessageClient();

   /* the semaphore is used to synchronize the storage process and the transaction process. */
   InitSemaphore();

   InitProc();
   /* if the process-array is shared between storage and transaction, so is the process-array-lock. */
   InitProcLock();
   InitInvisibleTable();
}
示例#5
0
/* auto init */
static int BattClock_Init(struct BattClockBase *BattClockBase)
{
    InitSemaphore(&BattClockBase->sem);
    BattClockBase->century = CENTURY;	/* Default offset */

    if ((ACPICABase = OpenLibrary("acpica.library",0)))
    {
        ACPI_TABLE_FADT *fadt;
        ACPI_STATUS err;

        err = AcpiGetTable("FACP", 1, (ACPI_TABLE_HEADER **)&fadt);
        if (err == AE_OK) {
            if ((fadt->Header.Length >= offsetof(ACPI_TABLE_FADT, Century)) &&
                fadt->Century)
            {
                D(bug("[BattClock] Got RTC century offset 0x%02X from ACPI\n", fadt->Century));
                BattClockBase->century = fadt->Century;
            }
        }
        CloseLibrary(ACPICABase);
        ACPICABase = NULL;
    }

    return 1;
}
示例#6
0
文件: semaphore.c 项目: michalsc/AROS
static void _Init_Semaphore(void)
{
    DB2(bug("%s()\n", __FUNCTION__));

    InitSemaphore(&sema_sem);
    NEWLIST(&semaphores);
}
示例#7
0
void __saveds Pdebug(const char *fmt, ...){
	va_list argp;

	if(dodebug==0) return;

	if(0==semaphoreinit){
		InitSemaphore(&PdebugSemaphore);
		semaphoreinit=1;
	}

	va_start(argp,fmt);

	ObtainSemaphore(&PdebugSemaphore);

		if(lastpdebug<19){

			vsprintf(&pdebugg[lastpdebug][0],fmt,argp);
			lastpdebug++;

			Signal(mytask,debugsig);
		}

	ReleaseSemaphore(&PdebugSemaphore);

	va_end(argp);
}
示例#8
0
static int thylacine_Init(struct ThylacineBase *tb)
{
    struct Library *ExpansionBase;
    int unit = 0;

    InitSemaphore(&tb->tb_UnitLock);

    NEWLIST(&tb->tb_Units);

    if ((ExpansionBase = OpenLibrary("expansion.library", 36))) {
        struct ConfigDev *cd = NULL;

        while ((cd = FindConfigDev(cd, THYLACINE_VENDOR, THYLACINE_PRODUCT))) {
            struct sl811hs *sl;
            ULONG addr = (ULONG)(IPTR)cd->cd_BoardAddr;
            ULONG data = addr + 0x4000;
            // ULONG reset = addr + 0x100;
            sl = sl811hs_Attach(addr, data, INTB_EXTER);
            if (sl) {
                ((struct Node *)sl)->ln_Pri = unit++;
                ((struct Node *)sl)->ln_Name = "thylacine.device";
                AddTail(&tb->tb_Units, (struct Node *)sl);
            }
        }

        CloseLibrary(ExpansionBase);
    }

    return IsListEmpty(&tb->tb_Units) ? 0 : 1;
}
示例#9
0
文件: clusters.c 项目: jgideonr/camd
struct MidiCluster *NewCluster(char *name,struct CamdBase *CamdBase){
	struct MyMidiCluster *mymidicluster;
	struct MidiCluster *midicluster;


	mymidicluster=AllocMem(sizeof(struct MyMidiCluster),MEMF_ANY | MEMF_CLEAR | MEMF_PUBLIC);

	if(mymidicluster==NULL) return NULL;

	InitSemaphore(&mymidicluster->semaphore);

	midicluster=&mymidicluster->cluster;

	midicluster->mcl_Node.ln_Name=AllocVec(mystrlen(name) + 1,MEMF_ANY|MEMF_PUBLIC);

	if(midicluster->mcl_Node.ln_Name==NULL){
		FreeMem(midicluster,sizeof(struct MyMidiCluster));
		return NULL;
	}

	mysprintf(CamdBase,midicluster->mcl_Node.ln_Name,"%s",name);

	NEWLIST(&midicluster->mcl_Receivers);
	NEWLIST(&midicluster->mcl_Senders);

	AddTail(&CB(CamdBase)->midiclusters,&midicluster->mcl_Node);


	return midicluster;
}
示例#10
0
文件: sarun.c 项目: jamjr/Helios-NG
int main(int argc, char **argv)
{
	int e;
	
	if( argc < 3 ) error("usage: sarun link bootfile");

	link = atoi(argv[1]);

	/* open the link for raw I/O */	
	if( !link_open(link) ) error("failed to open link %d",link);

	/* boot the program through it */
	if( (e=link_boot(link,argv[2]))!=0 ) error("link_boot error %d",e);

	/* now spool stdin into the link and	*/
	/* anything from the link to stdout	*/
	
	InitSemaphore(&sync,0);
	
	Fork(2000,input,4,link);
	
	Fork(2000,output,4,link);
	
	Wait(&sync);
	Wait(&sync);
	
	if( !link_close(link) ) error("failed to close link %d",link);
}
示例#11
0
bool Error_init(void){

	errortaskname=malloc(400);

	sprintf(errortaskname,"ErrorPortProc for: %s",screenname);

	InitSemaphore(&ErrorSemaphore);


	if(
		CreateNewProcTags(
			NP_Entry,ErrorProcess,
			NP_Name,errortaskname,
//			NP_Output,Open(constring,0x3ee),
			TAG_END
		)==NULL
	){
		fprintf(stderr,"Could not open Error Process\n");
		return false;
	}

	do{
		Delay(1);
	}while(ErrorTask==NULL);

	hassent=0;

	return true;
}
示例#12
0
BOOL pkt_init(void)
{
    packet_t *p;
    int i;
    UBYTE *pkt_data;
    
    /* allocate packets with nodes for tx and rx queue */
    int totalPkt = tx_pkt_size + rx_pkt_size;
    pkts_size = totalPkt * sizeof(packet_t);
    pkts = (packet_t *)AllocMem(pkts_size, MEMF_CLEAR);
    if(pkts == NULL) {
        return FALSE;
    }
    
    /* allocate packet data for rx packets */
    rx_pkt_data_size = rx_pkt_size * max_pkt_size;
    rx_pkt_data = (UBYTE *)AllocMem(rx_pkt_data_size, MEMF_CLEAR);
    if(rx_pkt_data == NULL) {
        return FALSE;
    }
    
    NewList(&tx_free);
    NewList(&rx_free);
    InitSemaphore(&tx_sem);
    InitSemaphore(&rx_sem);
    
    /* init tx queue packets and insert them into free list */
    p = pkts;
    for(i=0;i<tx_pkt_size;i++) {
        AddHead(&tx_free, &p->p_Node);
        p++;
    }
    
    /* init rx queue packets and insert them into free list 
       store the pre-allocated buffer as 
    */
    pkt_data = rx_pkt_data;
    for(i=0;i<rx_pkt_size;i++) {
        AddHead(&rx_free, &p->p_Node);
        p->p_OwnBuffer = pkt_data;
        p->p_OwnBufferSize = max_pkt_size;
        pkt_data += max_pkt_size;
        p++;
    }
    
    return TRUE;
}
示例#13
0
static int UUID_Init(LIBBASETYPEPTR LIBBASE)
{
    struct timeval tv;
    uuid_time_t time_now;
    
    /* Set up global lock (class and interface locks are separate!) */
    InitSemaphore(&LIBBASE->uuid_GlobalLock);
    
    D(bug("[UUID] UUID Init\n"));
    
    LIBBASE->uuid_Initialized = 0;
    
    /* I need timer.device in order to obtain system time */
    if (OpenDevice("timer.device", UNIT_MICROHZ, &LIBBASE->uuid_TR, 0))
    {
        D(bug("[UUID] Could not open timer.device. ABORT!\n"));
        return FALSE;
    }
    
    /* get the system time and convert it to UUID time */
    GetSysTime(&tv);
    time_now = LIBBASE->uuid_NextUpdate = LIBBASE->uuid_LastTime = 
        ((uint64_t)tv.tv_secs + 2922) * 10000000 +
        ((uint64_t)tv.tv_micro) * 10 +
        ((uint64_t)0x01B21DD213814000LL);
    
    D(bug("[UUID] UUID time: 0x%08lx%08lx\n", 
          (uint32_t)((LIBBASE->uuid_LastTime >> 32) & 0xffffffff),
          (uint32_t)((LIBBASE->uuid_LastTime & 0xffffffff))
          ));
    
    /* Seed the random generator */
    time_now /= UUIDS_PER_TICK;
    UUIDBase->uuid_RandomSeed = (time_now >> 32) ^ time_now; 
    UUIDBase->uuid_UUIDs_ThisTick = 0;
    
    /* Try to open dos.library for GetVar/SetVar */
    DOSBase = OpenLibrary("dos.library", 0);
    if (DOSBase)
    {
        D(bug("[UUID] dos.library opened. Trying to get the UUID state.\n"));
        
        /* DOS is there. Try to get the last UUID state. */
        if (GetVar("uuid_state", (UBYTE*)&LIBBASE->uuid_State, sizeof(uuid_state_t),
               GVF_BINARY_VAR | GVF_DONT_NULL_TERM) == sizeof(uuid_state_t))
        {
            D(bug("[UUID] got last UUID state\n"));
            LIBBASE->uuid_Initialized = 1;
        }
        else
        {
            D(bug("[UUID] no UUID state found. Staying uninitlaized\n"));
        }
    }
    else
        D(bug("[UUID] dos.library not yet available. I will try later."));
    
    return TRUE;
}
示例#14
0
// Initialise a ListLock
void LIBFUNC L_InitListLock(
	REG(a0, struct ListLock *ll),
	REG(a1, char *name))
{
	NewList(&ll->list);
	InitSemaphore(&ll->lock);
	ll->lock.ss_Link.ln_Name=name;
}
示例#15
0
文件: flock.c 项目: michalsc/AROS
int main()
{
    tmpname = mktemp("T:flockXXXXXX");
    int fd = open(tmpname, O_CREAT);
    TEST((fd != -1));

    TEST((flock(fd, LOCK_SH|LOCK_NB) == 0));
    TEST((flock(fd, LOCK_UN) == 0));

    TEST((flock(fd, LOCK_EX|LOCK_NB) == 0));
    TEST((flock(fd, LOCK_UN) == 0));

    TEST((flock(fd, LOCK_SH) == 0));
    TEST((flock(fd, LOCK_UN) == 0));

    TEST((flock(fd, LOCK_EX) == 0));
    TEST((flock(fd, LOCK_UN) == 0));

    close(fd);

    /* Create NPROCS processes increasing counter ITERATIONS times in an ugly 
       way */
    int counter = 0;
    struct Process *procs[NPROCS];
    ULONG ids[NPROCS];
    struct TagItem tags[] =
    {
	{ NP_Entry,         (IPTR) entry     },
        { NP_Name,          (IPTR) "flocker" },
        { NP_Output,        (IPTR) Output()  },
        { NP_CloseOutput,   (IPTR) FALSE     },
        { NP_UserData,      (IPTR) &counter  },
        { NP_NotifyOnDeath, (IPTR) TRUE      },
        { TAG_DONE,         0                }
    };

    int i;
    InitSemaphore(&sem);
    for(i = 0; i < NPROCS; i++)
    {
	procs[i] = CreateNewProc(tags);
	TEST((procs[i]));
	ids[i] = GetETask(procs[i])->et_UniqueID;
	Signal((struct Task *)procs[i], SIGBREAKF_CTRL_C);
    }
    
    for(i = 0; i < NPROCS; i++)
    {
	ChildWait(ids[i]);
	ChildFree(ids[i]);
    }
    putchar('\n');
    
    TEST((counter == NPROCS * ITERATIONS));
    
    cleanup();
    return OK;
}
示例#16
0
static LIB_BASE_T *LibInit(LIB_BASE_T *LibBase, BPTR Segment, struct ExecBase *ExecBase)
{
	SysBase = ExecBase;

	LibBase->LibSegment = Segment;
	LibBase->ExecBase = ExecBase;
	InitSemaphore(&LibBase->LockSemaphore);
	return LibBase;
}
示例#17
0
static int GFX_Init(LIBBASETYPEPTR LIBBASE)
{
    struct class_static_data *csd = &LIBBASE->hdg_csd;
    
    EnterFunc(bug("GfxHIDD_Init()\n"));

    InitSemaphore(&csd->rgbconvertfuncs_sem);

    ReturnInt("GfxHIDD_Init", ULONG, TRUE);
}
示例#18
0
文件: init.c 项目: roskakori/envSOF
BOOL
InitC(void)
{
    InitSemaphore(&MemorySemaphore);

    if (MemoryPool = AsmCreatePool(MEMF_ANY | MEMF_PUBLIC, 4096, 4096, SysBase))
        return(TRUE);
    else
        return(FALSE);

}
示例#19
0
struct SignalSemaphore*	MorphOS_CreateMutex(void)
{
	struct SignalSemaphore *mutex = (struct SignalSemaphore*) AllocVec(sizeof (struct SignalSemaphore), MEMF_PUBLIC);

	if (mutex)
	{
		InitSemaphore(mutex);
	}

	return mutex;
}
示例#20
0
// Create a new backdrop handle
BackdropInfo *backdrop_new(IPCData *ipc,ULONG flags)
{
	BackdropInfo *info;

	// Allocate structure
	if (!(info=AllocVec(sizeof(BackdropInfo),MEMF_CLEAR)))
		return 0;

	// Create memory pool
	info->memory=NewMemHandle(2048,512,MEMF_CLEAR);

	// Initialise stuff
	InitListLock(&info->objects,0);
	InitSemaphore(&info->window_lock);
	InitSemaphore(&info->idcmp_lock);
	NewList(&info->boopsi_list);
	info->ipc=ipc;
	info->flags=flags;

	return info;
}
示例#21
0
static int GM_UNIQUENAME(Init)(LIBBASETYPEPTR hdskBase)
{
    HostLibBase = OpenResource("hostlib.resource");
    D(bug("hostdisk: HostLibBase: 0x%p\n", HostLibBase));
    if (!HostLibBase)
        return FALSE;

    InitSemaphore(&hdskBase->sigsem);
    NEWLIST(&hdskBase->units);

   D(bug("hostdisk: in libinit func. Returning %x (success) :-)\n", hdskBase));
   return TRUE;
}
示例#22
0
static int MUIMasterInit(LIBBASETYPEPTR lh)
{
    MUIMasterBase = (struct Library *)lh;
    
    InitSemaphore(&MUIMB(lh)->ZuneSemaphore);
    
    NewList((struct List *)&MUIMB(lh)->BuiltinClasses);
    NewList((struct List *)&MUIMB(lh)->Applications);

    ((struct MUIMasterBase_intern *)MUIMasterBase)->topaz8font = OpenFont(&topaz8Attr);

    return TRUE;
}
示例#23
0
// Allocate a new environment structure
Cfg_Environment *environment_new(void)
{
	Cfg_Environment *env;

	// Allocate new environment structure
	if (!(env=AllocVec(sizeof(Cfg_Environment),MEMF_CLEAR)) ||
		!(env->memory=NewMemHandle(0,0,MEMF_CLEAR)) ||
		!(env->desktop_memory=NewMemHandle(1024,512,MEMF_PUBLIC|MEMF_CLEAR)) ||
		!(env->volatile_memory=NewMemHandle(1024,sizeof(ButtonBankNode)+256,MEMF_PUBLIC|MEMF_CLEAR)))
	{
		environment_free(env);
		return 0;
	}

	// Initialise environment
	InitSemaphore(&env->lock);
	NewList((struct List *)&env->path_formats);
	NewList((struct List *)&env->path_list);
	NewList((struct List *)&env->sound_list);
	strcpy(env->toolbar_path,"dopus5:buttons/toolbar");
	strcpy(env->menu_path,"dopus5:buttons/lister menu");
	strcpy(env->user_menu_path,"dopus5:buttons/user menu");
	strcpy(env->hotkeys_path,"dopus5:buttons/hotkeys");
	strcpy(env->scripts_path,"dopus5:buttons/scripts");
	NewList((struct List *)&env->desktop);
	InitSemaphore(&env->desktop_lock);
	InitSemaphore(&env->sound_lock);

	// Allocate space for settings
	if (!(env->env=AllocMemH(env->memory,sizeof(CFG_ENVR))))
	{
		environment_free(env);
		return 0;
	}

	// Get default settings
	DefaultEnvironment(env->env);
	return env;
}
示例#24
0
文件: hwtest.c 项目: jamjr/Helios-NG
	/* automatically.						*/
static void initialise_statics(void)
{ int	i;

  InitSemaphore(&LibraryLock, 1);
  MachineName(Results.ProcessorName);
  Results.OffchipMemory		= 0;
  Results.OffchipFailures	= 0;
  Results.OnchipMemory		= 0;
  Results.OnchipFailures	= 0;
  Results.NumberLinks		= 0;
  for (i = 0; i < MaxLinks; i++)
   { Results.LinkStats[i].LinkNumber		= 0;
     Results.LinkStats[i].ReadIterations	= 0;
     Results.LinkStats[i].ReadFailures		= 0;
     Results.LinkStats[i].WriteIterations	= 0;
   }

  NumberThreads	= 0;
  InitSemaphore(&ThreadsReady, 0);
  InitSemaphore(&ResultsLock, 1);
  InitSemaphore(&ResultsReady, 0);
}
示例#25
0
void ProcessFile_Threaded(Document *doc)
{
  if (jobs_start == -1) {
    threads_running = 0;
    memset((void *)jobs, 0, sizeof(jobs));

    InitSemaphore(&sem_jobs_ready, 0, 0);
    for (int i = 0; i < JOB_POOL; i++) {
      InitSemaphore(&sem_job_avail[i], 0, 1);
    }

    threadpool_size = GetIntegerConfig("THREADS", 1)+1;
    threadpool = malloc(sizeof(pthread_t) * threadpool_size);
    threadcache = malloc(sizeof(SignatureCache *) * threadpool_size);

    jobs_start = 0;
    jobs_end = 0;
    current_jobs = 0;
    jobs_complete = 0;
    finishup = 0;

    threadcache[0] = NewSignatureCache(2, 0);
    pthread_create(threadpool+0, NULL, start_work_writer, threadcache[0]);
    for (int i = 1; i < threadpool_size; i++) {
      threadcache[i] = NewSignatureCache(0, 1);
      pthread_create(threadpool+i, NULL, start_work, threadcache[i]);
    }
  }
  int currjob = atomicFetchAndAdd(&jobs_end, 1) % JOB_POOL;

  WaitSemaphore(&sem_job_avail[currjob]);

  jobs[currjob].doc = doc;
  jobs[currjob].state = READY;

  atomicFetchAndAdd(&current_jobs, 1);
  PostSemaphore(&sem_jobs_ready);
}
示例#26
0
/**************************************************************************
 OM_NEW
**************************************************************************/
IPTR Semaphore__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
{
    struct MUI_SemaphoreData *data;

    obj = (Object *)DoSuperMethodA(cl, obj, (Msg)msg);
    if (obj)
    {
        data = INST_DATA(cl, obj);

        InitSemaphore(&data->sem);
    }

    return (IPTR)obj;
}
示例#27
0
struct SysMutex *Sys_Thread_CreateMutex(void)
{
	struct SysMutex *mutex;

	mutex = AllocVec(sizeof(*mutex), MEMF_ANY);
	if (mutex)
	{
		InitSemaphore(&mutex->sem);

		return mutex;
	}

	return 0;
}
示例#28
0
void __initdetach(void)
{ struct Library *DOSBase,*SysBase = *(struct Library **)4;
  struct SignalSemaphore *sema;

  if (_WBenchMsg)
    return;

  if ((sema=sem)) {        /* I must be the child process */
    ObtainSemaphore(sema); /* Assert that my parent is already dead */
    ReleaseSemaphore(sema);
    FreeMem(sema,sizeof(*sema));
    return;
  }
                          /* I must be the parent */
  if ((sem=sema=(struct SignalSemaphore *)AllocMem(sizeof(*sema),MEMF_PUBLIC|MEMF_CLEAR))) {

    InitSemaphore(sema);

    if ((DOSBase=OpenLibrary(__dosname,30))) {

      struct CommandLineInterface *cli = Cli();
      APTR pr,stack = __SaveSP;

      ObtainSemaphore(sema); /* Assert that my child is suspended until I'm finished */

      pr = CreateNewProcTags(NP_Seglist,cli->cli_Module, /* child process gets my seglist */
                             NP_FreeSeglist,1,           /* and must free it */
                             NP_Cli,1,                   /* it must be a CLI process */
                             NP_StackSize,__stack,       /* it gets a stack */
                             NP_Name,(ULONG)__procname,  /* a name */
                             NP_Priority,__priority,     /* a priority */
                             NP_Arguments,(ULONG)__commandline,/* and my commandline Arguments */
                             TAG_END);
      CloseLibrary(DOSBase);

      if (pr) {

        cli->cli_Module = 0; /* I'm no longer owner of this */

        /* Adjust stack, release semaphore and return 0 in one.
         * Maybe the 3 movel are a bit too cautious, but they ARE working
         */
        asm("movel %0,sp;movel %1,a6;movel %2,a0;moveql #0,d0;jmp a6@(-570)"::
            "r"(stack),"r"(SysBase),"r"(sema):"sp","a6","a0");
      }

      ReleaseSemaphore(sema); /* Again only caution - you never know */
    }
    FreeMem(sema,sizeof(*sema)); /* Couldn't start child :( */
  }
示例#29
0
int main(int argc, char **argv)
{
  printf("Microlink test (%s %s)\n", __DATE__, __TIME__);

  buffer = (unsigned char *)Malloc(MAXMSGSIZE);
  if (buffer == 0)
    { printf("failed to get buffer\n"); exit(1); }

  BuildCommandTable(); 
  
  /* Start a separate process to announce when a message handler	*/
  /* a message.								*/
  
  InitSemaphore(&handlerArg.sem, 0); /* Process sleeps on this */
  
  if (Fork(5000, HandlerProcess, 0, 0) < 0)
  {
    printf("failed to start child process\n");
    exit(1);
  }

  /* Main command loop */
   
  while (!finished)
  {
    char com[256], a1[256], a2[256], a3[256], a4[256], a5[256], a6[256];
    char line[256];
    int nwords;
    
    printf("> "); fflush(stdout);
    gets(line);
    com[0] = 0; 
    a1[0] = 0; a2[0] = 0; a3[0] = 0; a4[0] = 0; a5[0] = 0; a6[0] = 0;
    nwords = sscanf(line, "%s %s %s %s %s %s %s", com, a1, a2, a3, a4, a5, a6);

    if (nwords > 0)
    {
      void (*proc)() = LookupCommand(com);
      
      if ((int)proc) 
        (*proc)(com, a1, a2, a3, a4, a5, a6);
      else
        printf("Unknown command '%s'\n", com);
    }
  }

  Free(buffer);
  return 0;
}
示例#30
0
struct NamedObject *util_AllocNamedObjectA(pUtility UtilBase, STRPTR name, struct TagItem *tagList)
{
	if (name == NULL) return NULL;
	UINT32 ns = GetTagData(ANO_NameSpace, FALSE, tagList);
	if (ns == TRUE) ns = sizeof(struct NameSpace);
	
	UINT32 us = GetTagData(ANO_UserSpace, 0, tagList);
	
	if (us != 0) us +=3;
	
	UINT32 nameSize = Strlen((const char*)name);
	UINT32 allocSize = ns + us + sizeof(struct NamedObj) + nameSize + 1;

	UINT8 *mem = AllocVec(allocSize, MEMF_PUBLIC|MEMF_CLEAR);

	if (mem == NULL) return NULL;	
	struct NamedObj *object = (struct NamedObj *) mem;
	mem += sizeof(struct NamedObj);

	if (ns) {
		object->no_Nos.nos_NameSpace = (struct NameSpace *)mem;
		mem += ns;
	}
	object->no_Non.non_Node.ln_Name = (STRPTR)mem;
	Strcpy((char *)mem, (const char *)name);
	mem += nameSize+1;
	struct NamedObject *ret = (struct NamedObject *)BASEOBJECT(object); //&object->no_Nos;

	if (us)
	{
		UINT32 align = (UINT32)mem;
		align = (align+3) & ~0x03;
		SYSTEM(ret)->no_Nos.nos_Object = (UINT8*)align;
	}
	
	UINT32 flags = GetTagData(ANO_Flags, 0, tagList);
	struct NameSpace *namSp = SYSTEM(ret)->no_Nos.nos_NameSpace;
	if (namSp != NULL)
	{
		namSp->ns_Flags = flags;
		NewList((struct List *)&namSp->ns_Entries);
		InitSemaphore(&namSp->ns_Semaphore);
	} 
	INT8 prio = GetTagData(ANO_Priority, 0, tagList);
	SYSTEM(ret)->no_Non.non_Node.ln_Pri = prio;
	SYSTEM(ret)->no_Non.non_UseCount = 1;
	return ret;
}