Ejemplo n.º 1
0
struct AHI_AudioDatabase *
LockDatabaseWrite(void)
{
  struct AHI_AudioDatabase *audiodb;

  Forbid();

  audiodb = (struct AHI_AudioDatabase *) FindSemaphore(ADB_NAME);

  if(audiodb != NULL)
  {
    ObtainSemaphore((struct SignalSemaphore *) audiodb);
  }
  else
  {
    audiodb = (struct AHI_AudioDatabase *)
        AllocVec(sizeof(struct AHI_AudioDatabase), MEMF_PUBLIC|MEMF_CLEAR);

    if(audiodb != NULL)
    {

      NewList( (struct List *) &audiodb->ahidb_AudioModes);

      audiodb->ahidb_Semaphore.ss_Link.ln_Name = audiodb->ahidb_Name;
      audiodb->ahidb_Semaphore.ss_Link.ln_Pri  = 20;
      strcpy(audiodb->ahidb_Semaphore.ss_Link.ln_Name, ADB_NAME);

      AddSemaphore((struct SignalSemaphore *) audiodb);
      ObtainSemaphore((struct SignalSemaphore *) audiodb);
    }
  }
  Permit();

  return audiodb;
}
Ejemplo n.º 2
0
int uae_sem_wait (uae_sem_t *sem)
{
    int result = -1;

    ObtainSemaphore (&sem->mutex);

    if (sem->live) {
	if (sem->value > 0) {
	    --sem->value;
	    result = 0;
        } else {
	    ReleaseSemaphore (&sem->mutex);

	    /* Block on this semaphore by waiting for
	     * the proxy thread to reply to our lock request
	     */
	    result = BlockMe (sem);

	    ObtainSemaphore (&sem->mutex);

	    if (result != -1)
		--sem->value;
	}
    }
    ReleaseSemaphore (&sem->mutex);
    return result;
}
Ejemplo n.º 3
0
VOID
DriverCleanup( struct DriverBase* AHIsubBase )
{
  struct EMU10kxBase* EMU10kxBase = (struct EMU10kxBase*) AHIsubBase;
  int i;

  if( EMU10kxBase->camd.Semaphore.ss_Link.ln_Name != NULL )
  {
    ObtainSemaphore( &EMU10kxBase->camd.Semaphore );
    RemSemaphore( &EMU10kxBase->camd.Semaphore );
    ReleaseSemaphore( &EMU10kxBase->camd.Semaphore );
  }

  if( EMU10kxBase->ac97.Semaphore.ss_Link.ln_Name != NULL )
  {
    ObtainSemaphore( &EMU10kxBase->ac97.Semaphore );
    RemSemaphore( &EMU10kxBase->ac97.Semaphore );
    ReleaseSemaphore( &EMU10kxBase->ac97.Semaphore );
  }
  
  for( i = 0; i < EMU10kxBase->cards_found; ++i )
  {
    emu10k1_irq_disable( &EMU10kxBase->driverdatas[ i ]->card,
			 INTE_MIDIRXENABLE );
    emu10k1_irq_disable( &EMU10kxBase->driverdatas[ i ]->card,
			 INTE_MIDITXENABLE );
    
    FreeDriverData( EMU10kxBase->driverdatas[ i ], AHIsubBase );
  }

  FreeVec( EMU10kxBase->driverdatas ); 
 
  CloseLibrary( OpenPciBase );
  CloseLibrary( (struct Library*) DOSBase );
}
Ejemplo n.º 4
0
BOOL AddClusterReceiver(
	struct MidiCluster *cluster,
	struct Node *node,
	ULONG *ErrorCode,
	struct CamdBase *CamdBase
){
	struct MidiLink *midilink;
	struct DriverData *driverdata;
	struct MyMidiCluster *mycluster=(struct MyMidiCluster *)cluster;

	if(node->ln_Type!=NT_USER-MLTYPE_NTypes){
	  driverdata=FindSenderDriverInCluster(cluster);
	  if(driverdata!=NULL){
			if(driverdata->isInOpen==FALSE && driverdata->isOutOpen==FALSE){
				if(OpenDriver(driverdata,ErrorCode,CamdBase)==FALSE){
					return FALSE;
				}
	  
				driverdata->isInOpen=TRUE;
			}
		}
		midilink=(struct MidiLink *)node;
		ObtainSemaphore(&mycluster->semaphore);
		midilink->ml_Location=cluster;
	}else{
		/* The receiver is a hardware-receiver, not a midilink. */
		ObtainSemaphore(&mycluster->semaphore);
	}

	Enqueue(&cluster->mcl_Receivers,node);
	ReleaseSemaphore(&mycluster->semaphore);

	return TRUE;
}
Ejemplo n.º 5
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 :( */
  }
Ejemplo n.º 6
0
OOP_Object *SDLMouse__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg) {
    BOOL has_mouse_hidd = FALSE;
    struct mousedata *mousedata;

    D(bug("[sdl] SDLMouse::New\n"));

    ObtainSemaphoreShared(&LIBBASE->lock);
    if (LIBBASE->mousehidd != NULL)
        has_mouse_hidd = TRUE;
    ReleaseSemaphore(&LIBBASE->lock);

    if (has_mouse_hidd) {
        D(bug("[sdl] mouse hidd already present, can't make another one\n"));
        return NULL;
    }

    if ((o = (OOP_Object *) OOP_DoSuperMethod(cl, o, (OOP_Msg) msg)) == NULL) {
        D(bug("[sdl] supermethod failed, bailing out\n"));
        return NULL;
    }

    mousedata = OOP_INST_DATA(cl, o);

    mousedata->callback = GetTagData(aHidd_Mouse_IrqHandler, NULL, msg->attrList);
    mousedata->callbackdata = GetTagData(aHidd_Mouse_IrqHandlerData, NULL, msg->attrList);

    ObtainSemaphore(&LIBBASE->lock);
    LIBBASE->mousehidd = o;
    ReleaseSemaphore(&LIBBASE->lock);

    D(bug("[sdl] created mouse hidd, callback 0x%08x, data 0x%08x\n", mousedata->callback, mousedata->callbackdata));

    return (OOP_Object *) o;
}
Ejemplo n.º 7
0
int __saveds __asm LIBReadUnreadTexts(
  register __a0 struct UnreadTexts *unreadTexts,
  register __d0 int userId,
  register __a6 struct NiKomBase *NiKomBase) {
  BPTR file;
  char filepath[41];
  int readRes, convertRes;

  ObtainSemaphore(&NiKomBase->Servermem->semaphores[NIKSEM_UNREAD]);

  convertRes = maybeConvertUnreadTextsData(userId, unreadTexts, NiKomBase);
  if(convertRes != 2) {
    ReleaseSemaphore(&NiKomBase->Servermem->semaphores[NIKSEM_UNREAD]);
    return convertRes;
  }

  MakeUserFilePath(filepath, userId, "UnreadTexts");
  if(!(file = Open(filepath, MODE_OLDFILE))) {
    ReleaseSemaphore(&NiKomBase->Servermem->semaphores[NIKSEM_UNREAD]);
    return 0;
  }
  readRes = Read(file, unreadTexts, sizeof(struct UnreadTexts));
  Close(file);
  ReleaseSemaphore(&NiKomBase->Servermem->semaphores[NIKSEM_UNREAD]);

  return readRes == sizeof(struct UnreadTexts);
}
Ejemplo n.º 8
0
void
RethinkPlayers ( struct AHIDevUnit *iounit,
                 struct AHIBase *AHIBase )
{
  struct MinList templist;
  struct AHIRequest *ioreq;

  NewList((struct List *) &templist);

  ObtainSemaphore(&iounit->ListLock);

  RemPlayers((struct List *) &iounit->PlayingList, iounit, AHIBase);
  RemPlayers((struct List *) &iounit->SilentList, iounit, AHIBase);

  // Move all silent requests to our temporary list

  while((ioreq = (struct AHIRequest *) RemHead((struct List *) &iounit->SilentList)))
  {
    AddTail((struct List *) &templist, (struct Node *) ioreq);
  }

  // And add them back...
  while((ioreq = (struct AHIRequest *) RemHead((struct List *) &templist)))
  {
    AddWriter(ioreq, iounit, AHIBase);
  }

  ReleaseSemaphore(&iounit->ListLock);
}
Ejemplo n.º 9
0
int writefiles(int area)
{
	struct Node *nod;
	BPTR fh;
	char datafil[110];
	int index;

	ObtainSemaphore(&Servermem->semaphores[NIKSEM_FILEAREAS]);

	sprintf(datafil,"nikom:datocfg/areor/%d.dat",area);

	if(!(fh=Open(datafil,MODE_NEWFILE)))
	{
		ReleaseSemaphore(&Servermem->semaphores[NIKSEM_FILEAREAS]);
		return 1;
	}

	index=0;
	nod = ((struct List *)&Servermem->areor[area].ar_list)->lh_Head;
	while(nod->ln_Succ)
	{
		if(Write(fh,nod,sizeof(struct DiskFil)) != sizeof(struct DiskFil)) {
			Close(fh);
			ReleaseSemaphore(&Servermem->semaphores[NIKSEM_FILEAREAS]);
			return 3;
		}
		((struct Fil *)nod)->index = index++;
		nod = nod->ln_Succ;
	}
	Close(fh);

	ReleaseSemaphore(&Servermem->semaphores[NIKSEM_FILEAREAS]);

	return 0;
}
Ejemplo n.º 10
0
void MorphOS_LockMutex(struct SignalSemaphore *mutex)
{
	if (mutex)
	{
		ObtainSemaphore(mutex);
	}
}
Ejemplo n.º 11
0
/*********  BitMap::Clear()  *************************************/
VOID MNAME_BM(Clear)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_Clear *msg)
{
    IPTR width, height;
    struct bitmap_data *data = OOP_INST_DATA(cl, o);
    struct Box box = {0, 0, 0, 0};
    
    /* Get width & height from bitmap superclass */

    OOP_GetAttr(o, aHidd_BitMap_Width,  &width);
    OOP_GetAttr(o, aHidd_BitMap_Height, &height);

    box.x2 = width - 1;
    box.y2 = height - 1;

    memset(data->VideoData, GC_BG(msg->gc), width*height);

#ifdef OnBitmap
    ObtainSemaphore(&XSD(cl)->HW_acc);
    vgaRefreshArea(data, 1, &box);
    draw_mouse(XSD(cl));
    ReleaseSemaphore(&XSD(cl)->HW_acc);
#endif /* OnBitmap */
    
    return;
}
Ejemplo n.º 12
0
void
FeedReaders ( struct AHIDevUnit *iounit,
              struct AHIBase *AHIBase )
{
  struct AHIRequest *ioreq;

  ObtainSemaphore(&iounit->ListLock);
  for(ioreq = (struct AHIRequest *)iounit->ReadList.mlh_Head;
      ioreq->ahir_Std.io_Message.mn_Node.ln_Succ;
      ioreq = (struct AHIRequest *)ioreq->ahir_Std.io_Message.mn_Node.ln_Succ)
  {
    FillReadBuffer(ioreq, iounit, AHIBase);
  }

  // Check if Reader-list is empty. If so, stop recording (after a small delay).

  if( ! iounit->ReadList.mlh_Head->mln_Succ )
  {
    if(--iounit->RecordOffDelay == 0)
    {
      AHI_ControlAudio(iounit->AudioCtrl,
          AHIC_Record,FALSE,
          TAG_DONE);
      iounit->IsRecording = FALSE;
    }
  }
  else
  {
    iounit->RecordOffDelay = 2;
  }

  ReleaseSemaphore(&iounit->ListLock);
}
Ejemplo n.º 13
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);
}
Ejemplo n.º 14
0
BOOL util_RemNamedObject(pUtility UtilBase, struct NamedObject *object, struct Message *message)
{
	Forbid();
	struct NameSpace *ns = SYSTEM(object)->no_Nos.nos_NameSpace;
	if (ns == NULL)
	{
		if (message != NULL) 
		{
			message->mn_Node.ln_Name = NULL;
			ReplyMsg(message);
		}
		Permit();
		return TRUE;
	}
	if (message == NULL) 
	{
		if (SYSTEM(object)->no_Non.non_UseCount != 1)
		{
			Permit();
			return TRUE;
		}
	}

	SYSTEM(object)->no_Nos.nos_NameSpace = NULL;
	ObtainSemaphore(&ns->ns_Semaphore);
	Remove(&SYSTEM(object)->no_Non.non_Node);
	if (message != NULL)
	{
		SYSTEM(object)->no_Nos.nos_RemoveMsg = message;
		message->mn_Node.ln_Name = (STRPTR)object;
	}
	ReleaseSemaphore(&ns->ns_Semaphore);
	Permit();
	return ReleaseNamedObject(object);
}
Ejemplo n.º 15
0
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
{
	int retval;


	if ( ! sem ) {
		SDL_SetError("Passed a NULL semaphore");
		return -1;
	}

	D(bug("WaitTimeout (%ld) semaphore...%lx\n",timeout,sem));

	/* A timeout of 0 is an easy case */
	if ( timeout == 0 ) {
		ObtainSemaphore(&sem->Sem);
		return 1;
	}
	if(!(retval=AttemptSemaphore(&sem->Sem)))
	{
		SDL_Delay(timeout);
		retval=AttemptSemaphore(&sem->Sem);
	}

	if(retval==TRUE)
	{
//		ReleaseSemaphore(&sem->Sem);
		retval=1;
	}

	return retval;
}
Ejemplo n.º 16
0
///
/// DumpDbgMalloc
// output all current allocations
void DumpDbgMalloc(void)
{
  ENTER();

  if(isFlagSet(debug_classes, DBC_MTRACK))
  {
    ULONG i;

    ObtainSemaphore(&DbgMallocListSema);

    D(DBF_ALWAYS, "%ld memory areas tracked", DbgMallocCount);
    for(i = 0; i < ARRAY_SIZE(DbgMallocList); i++)
    {
      struct Node *curNode;

      for(curNode = GetHead((struct List *)&DbgMallocList[i]); curNode != NULL; curNode = GetSucc(curNode))
      {
        struct DbgMallocNode *dmn = (struct DbgMallocNode *)curNode;

        _DPRINTF(DBC_MTRACK, DBF_ALWAYS, dmn->file, dmn->line, "memarea 0x%08lx, size/type %ld, func (%s)", dmn->memory, dmn->size, dmn->func);
      }
    }

    ReleaseSemaphore(&DbgMallocListSema);
  }

  LEAVE();
}
Ejemplo n.º 17
0
///
/// _UNMEMTRACK
// remove a node from the memory tracking lists
void _UNMEMTRACK(const char *file, const int line, const char *func, const void *ptr)
{
  if(isFlagSet(debug_classes, DBC_MTRACK) && ptr != NULL)
  {
    BOOL success = FALSE;
    struct DbgMallocNode *dmn;

    ObtainSemaphore(&DbgMallocListSema);

    if((dmn = findDbgMallocNode(ptr)) != NULL)
    {
      Remove((struct Node *)dmn);

      if(matchAllocFunc(dmn->func, func) == FALSE)
      {
        _DPRINTF(DBC_WARNING, DBF_ALWAYS, file, line, "free of tracked memory area 0x%08lx with unsuitable function (allocated with %s, freed with %s counterpart)", ptr, dmn->func, func);
        DbgUnsuitableFreeCount++;
      }

      FreeVec(dmn);

      DbgMallocCount--;

      success = TRUE;
    }

    if(success == FALSE)
      _DPRINTF(DBC_WARNING, DBF_ALWAYS, file, line, "free of untracked memory area 0x%08lx attempted", ptr);

    ReleaseSemaphore(&DbgMallocListSema);
  }
}
Ejemplo n.º 18
0
///
/// _MEMTRACK
// add a new node to the memory tracking lists
void _MEMTRACK(const char *file, const int line, const char *func, void *ptr, size_t size)
{
  if(isFlagSet(debug_classes, DBC_MTRACK))
  {
    if(ptr != NULL && size != 0)
    {
      struct DbgMallocNode *dmn;

      if((dmn = AllocVec(sizeof(*dmn), MEMF_ANY)) != NULL)
      {
        dmn->memory = ptr;
        dmn->size = size;
        dmn->file = file;
        dmn->line = line;
        dmn->func = func;

        ObtainSemaphore(&DbgMallocListSema);

        AddTail((struct List *)&DbgMallocList[ptr2hash(ptr)], (struct Node *)&dmn->node);
        DbgMallocCount++;

        ReleaseSemaphore(&DbgMallocListSema);
      }
    }
    else
      _DPRINTF(DBC_WARNING, DBF_ALWAYS, file, line, "potential invalid %s call with return (0x%08lx, 0x%08lx)", func, ptr, size);
  }
}
Ejemplo n.º 19
0
int updatefile(int area,struct Fil *fil)
{
	BPTR fh;
	char datafil[110];

	ObtainSemaphore(&Servermem->semaphores[NIKSEM_FILEAREAS]);

	sprintf(datafil,"nikom:datocfg/areor/%d.dat",area);

	if(!(fh=Open(datafil,MODE_OLDFILE)))
	{
		ReleaseSemaphore(&Servermem->semaphores[NIKSEM_FILEAREAS]);
		return 1;
	}

	if(Seek(fh,fil->index * sizeof(struct DiskFil),OFFSET_BEGINNING)==-1)
	{
		ReleaseSemaphore(&Servermem->semaphores[NIKSEM_FILEAREAS]);
		Close(fh);
		return 2;
	}

	if(Write(fh,fil,sizeof(struct DiskFil)) != sizeof(struct DiskFil))
	{
		ReleaseSemaphore(&Servermem->semaphores[NIKSEM_FILEAREAS]);
		Close(fh);
		return 3;
	}

	Seek(fh,0,OFFSET_END);
	Close(fh);
	ReleaseSemaphore(&Servermem->semaphores[NIKSEM_FILEAREAS]);
	return 0;
}
Ejemplo n.º 20
0
LIBPROTO(CleanupAmiSSLA, LONG, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, UNUSED struct TagItem *tagList))
{
  AMISSL_STATE *state;

  SHOWREGISTERS();

  if((state = GetAmiSSLState()))
  {
#ifdef __amigaos4__
    if(state->SocketBase && state->ISocketPtr && *state->ISocketPtr)
    {
      DropInterface((struct Interface *)*state->ISocketPtr);
      state->ISocketPtr = NULL;
    }
#endif

    ObtainSemaphore(&parentBase->openssl_cs);
    D(DBF_STARTUP, "h_delete(parentBase->thread_hash)");
    h_delete(parentBase->thread_hash, state->pid);
    ReleaseSemaphore(&parentBase->openssl_cs);

    FreeVec(state);
  }

  return(0);
}
Ejemplo n.º 21
0
OOP_Object *LinuxMouse__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
{
    BOOL has_mouse_hidd = FALSE;

    ObtainSemaphore(&LSD(cl)->sema);    
    if (LSD(cl)->mousehidd)
    	has_mouse_hidd = TRUE;
    ReleaseSemaphore(&LSD(cl)->sema);
    
    if (has_mouse_hidd) /* Cannot open twice */
    	return NULL; /* Should have some error code here */

    o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
    if (o)
    {
	struct mouse_data *data = OOP_INST_DATA(cl, o);
	struct TagItem *tag, *tstate;
	
	tstate = msg->attrList;
	while ((tag = NextTagItem((const struct TagItem **)&tstate)))
	{
	    ULONG idx;
	    
	    if (IS_HIDDMOUSE_ATTR(tag->ti_Tag, idx))
	    {
	    	switch (idx)
		{
		    case aoHidd_Mouse_IrqHandler:
		    	data->mouse_callback = (VOID (*)())tag->ti_Data;
			break;
			
		    case aoHidd_Mouse_IrqHandlerData:
		    	data->callbackdata = (APTR)tag->ti_Data;
			break;
		}
	    }
	    
	} /* while (tags to process) */
	
	/* Install the mouse hidd */
    	ObtainSemaphore(&LSD(cl)->sema);	
	LSD(cl)->mousehidd = o;
    	ReleaseSemaphore(&LSD(cl)->sema);
    }
    return o;
}
Ejemplo n.º 22
0
/**************************************************************************
 MUIM_Semaphore_Obtain
**************************************************************************/
IPTR Semaphore__MUIM_Obtain(struct IClass *cl, Object *obj, struct MUIP_Semaphore_Obtain *msg)
{
    struct MUI_SemaphoreData *data = INST_DATA(cl, obj);

    ObtainSemaphore(&data->sem);

    return 0;
}
Ejemplo n.º 23
0
void DoSyncAction(void (*func)(struct IntuiActionMsg *, struct IntuitionBase *),
                  struct IntuiActionMsg *msg,
                  struct IntuitionBase *IntuitionBase)
{
    struct IIHData *iihd = (struct IIHData *)GetPrivIBase(IntuitionBase)->InputHandler->is_Data;
    struct Task    *me = FindTask(NULL);

    if (me == iihd->InputDeviceTask)
    {
        func(msg, IntuitionBase);
    }
    else
    {
    #ifdef __MORPHOS__
        struct IOStdReq   req;
        struct MsgPort    port;
        struct InputEvent ie;
    #endif

        msg->handler = func;
        msg->task    = me;
        msg->done    = FALSE;
    
        ObtainSemaphore(&GetPrivIBase(IntuitionBase)->IntuiActionLock);
        AddTail((struct List *)GetPrivIBase(IntuitionBase)->IntuiActionQueue, (struct Node *)msg);
        ReleaseSemaphore(&GetPrivIBase(IntuitionBase)->IntuiActionLock);

    #ifdef __MORPHOS__
        port.mp_Flags 	= PA_SIGNAL;
        port.mp_SigTask = me;
        port.mp_SigBit  = SIGB_INTUITION;
        NEWLIST(&port.mp_MsgList);

        req.io_Message.mn_ReplyPort = &port;
        req.io_Device 	    	    = GetPrivIBase(IntuitionBase)->InputIO->io_Device;
        req.io_Unit 	    	    = GetPrivIBase(IntuitionBase)->InputIO->io_Unit;
        req.io_Command      	    = IND_WRITEEVENT;
        req.io_Length 	    	    = sizeof(ie);
        req.io_Data 	    	    = &ie;

        ie.ie_Class = IECLASS_NULL;
    #endif
    
        if (!msg->done)
        {
    	#ifdef __MORPHOS__
            DoIO((APTR)&req);
    	#else
    	    AddNullEvent();
    	#endif
            while (!msg->done)
            {
                Wait(SIGF_INTUITION);
            }
        }
    }
}
Ejemplo n.º 24
0
VOID SDLMouse__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg) {
    D(bug("[sdl] SDLMouse::Dispose\n"));

    ObtainSemaphore(&LIBBASE->lock);
    LIBBASE->mousehidd = NULL;
    ReleaseSemaphore(&LIBBASE->lock);

    OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
}
Ejemplo n.º 25
0
VOID LinuxMouse__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
{
    ObtainSemaphore(&LSD(cl)->sema);
    LSD(cl)->mousehidd = NULL;
    ReleaseSemaphore(&LSD(cl)->sema);
    
    OOP_DoSuperMethod(cl, o, msg);
    
}
Ejemplo n.º 26
0
int
main( void )
{
  struct Library* EMU10kxBase;
  struct EMU10kxAC97* EMU10kxAC97;
  ULONG value;

  EMU10kxBase = OpenLibrary( "DEVS:AHI/emu10kx.audio", VERSION );
  
  if( EMU10kxBase == NULL )
  {
    Printf( "Unable to open DEVS:AHI/emu10kx.audio version %ld.\n", VERSION );
    return RETURN_FAIL;
  }

  Forbid();
  EMU10kxAC97 = (struct EMU10kxAC97*) FindSemaphore( EMU10KX_AC97_SEMAPHORE );
  if( EMU10kxAC97 != NULL )
  {
    ObtainSemaphore( &EMU10kxAC97->Semaphore );
  }
  Permit();

  if( EMU10kxAC97 == NULL )
  {
    CloseLibrary( EMU10kxBase );
    Printf( "Unable to find semaphore '%s'.\n", (ULONG) EMU10KX_AC97_SEMAPHORE );
    return RETURN_FAIL;
  }

  Printf( "%ld EMU10kx cards found.\n", EMU10kxAC97->Cards );
  
  value = CallHook( &EMU10kxAC97->GetFunc, (Object*) EMU10kxBase,
		    0, AC97_CD_VOL );

  Printf( "CD volume on card 0 is 0x%04lx\n", value );

  Printf( "Setting it to 0x0000.\n" );
  CallHook( &EMU10kxAC97->SetFunc, (Object*) EMU10kxBase, 0, AC97_CD_VOL, 0 );

  Delay( 3 * 50 );

  Printf( "Restoring it.\n" );
  CallHook( &EMU10kxAC97->SetFunc, (Object*) EMU10kxBase, 0, AC97_CD_VOL, value );

  Printf( "Exiting.\n" );
  
  if( EMU10kxAC97 != NULL )
  {
    ReleaseSemaphore( &EMU10kxAC97->Semaphore );
  }

  CloseLibrary( EMU10kxBase );

  return RETURN_OK;
}
Ejemplo n.º 27
0
sem_t *sem_open(const char *name, int oflag, mode_t mode, unsigned int value)
{
    sem_t *sem;

    D(bug("%s(%s, %d, %u, %u)\n", __FUNCTION__, name, oflag, mode, value));

    pthread_once(&once_control, _Init_Semaphore);

    if (name == NULL)
    {
        errno = EINVAL;
        return SEM_FAILED;
    }

    ObtainSemaphore(&sema_sem);
    sem = (sem_t *)FindName(&semaphores, (STRPTR)name);
    if (sem != NULL)
    {
        if ((oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
        {
            ReleaseSemaphore(&sema_sem);
            errno = EEXIST;
            return SEM_FAILED;
        }
    }
    else
    {
        if (!(oflag & O_CREAT))
        {
            ReleaseSemaphore(&sema_sem);
            errno = ENOENT;
            return SEM_FAILED;
        }
        
        sem = malloc(sizeof(sem_t));
        if (sem == NULL)
        {
            ReleaseSemaphore(&sema_sem);
            errno = ENOMEM;
            return SEM_FAILED;
        }

        if (sem_init(sem, 0, value))
        {
            free(sem);
            ReleaseSemaphore(&sema_sem);
            return SEM_FAILED;
        }
        // TODO: this string should be duplicated
        sem->node.ln_Name = (char *)name;
        AddTail(&semaphores, (struct Node *)sem);
    }
    ReleaseSemaphore(&sema_sem);

    return sem;
}
Ejemplo n.º 28
0
LIBPROTO(__UserLibCleanup, void, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, struct LibraryHeader *libBase))
{
  TRACELINE();

  // we call OPENSSL_cleanup to clean everything for the
  // current instance.
  OPENSSL_cleanup();

  if(libBase->parent->thread_hash)
  {
    D(DBF_STARTUP, "Performing unfreed states cleanup for %08lx (group %lu)", FindTask(NULL), libBase->ThreadGroupID);
    ObtainSemaphore(&libBase->parent->openssl_cs);
    D(DBF_STARTUP, "h_doall(thread_hash)");
    h_doall(libBase->parent->thread_hash, (void (*)(long, void *))ThreadGroupStateCleanup);
    ReleaseSemaphore(&libBase->parent->openssl_cs);
  }
  else
    W(DBF_STARTUP, "No thread_hash");

#if defined(__amigaos4__)
  if(IUtility != NULL)
  {
    DropInterface((struct Interface *)IUtility);
    IUtility = NULL;
  }
  if(IIntuition != NULL)
  {
    DropInterface((struct Interface *)IIntuition);
    IIntuition = NULL;
  }
  if(IDOS != NULL)
  {
    DropInterface((struct Interface *)IDOS);
    IDOS = NULL;
  }
#endif

  if(UtilityBase != NULL)
  {
    CloseLibrary((struct Library *)UtilityBase);
    UtilityBase = NULL;
  }
  if(IntuitionBase != NULL)
  {
    CloseLibrary((struct Library *)IntuitionBase);
    IntuitionBase = NULL;
  }
  if(DOSBase != NULL)
  {
    CloseLibrary((struct Library *)DOSBase);
    DOSBase = NULL;
  }

  // make sure to free all resources of libcmt
  __free_libcmt();
}
Ejemplo n.º 29
0
void freeArbitrateVecPooled(APTR mem)
{
  ENTER();

  ObtainSemaphore(&CodesetsBase->poolSem);
  freeVecPooled(CodesetsBase->pool, mem);
  ReleaseSemaphore(&CodesetsBase->poolSem);

  LEAVE();
}
Ejemplo n.º 30
0
int uae_sem_get_value (uae_sem_t *sem)
{
    int value;

    ObtainSemaphore (&sem->mutex);
    value = sem->value;
    ReleaseSemaphore (&sem->mutex);

    return value;
}