示例#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;
}
示例#2
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;
}
示例#3
0
int sem_unlink (const char *__name)
{
	unsigned char name[_PSEM_NAME_MAXLENGTH];
	struct SignalSemaphore *ssem;
	psem_t *psem = NULL;
	
	if(strlen(__name) > (_PSEM_NAME_MAXLENGTH-20))
	{
		errno = ENAMETOOLONG;
		return -1;
	}
	
	psem_name(__name,name,sizeof(name)-1);
	
	Forbid();
	if((ssem = FindSemaphore((STRPTR)name)))
	{
		//if(((psem_t *)ssem)->magic == _PSEM_MAGIC)
			psem = (psem_t *)ssem;
	}
	Permit();
	
	if(_PSEM_INVALID(psem))
	{
		errno = ((ssem != NULL) ? EACCES:ENOENT);
		return -1;
	}
	
	Forbid();
	if(psem_trywait(psem)==0)
	{
		psem_destroy(psem);
	}
	else
	{
		/**
		 * Could a semaphore be unlinked by a process other
		 * than the one who created it? if so, this lib will
		 * require some rework...
		 */
		
		if(psem->owner == (unsigned)FindTask(NULL))
			psem->flags |= SEMF_EXPUNGE;
	}
	Permit();
	
	return 0;
}
示例#4
0
struct AHI_AudioDatabase *
LockDatabase(void)
{
  struct AHI_AudioDatabase *audiodb;

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

  if(audiodb != NULL)
  {
    ObtainSemaphoreShared((struct SignalSemaphore *) audiodb);
  }

  Permit();

  return audiodb;
}
示例#5
0
ULONG
RemoveAudioMode( ULONG           id,
                 struct AHIBase* AHIBase )
{
  struct AHI_AudioMode *node;
  struct AHI_AudioDatabase *audiodb;
  ULONG rc=FALSE;

  if(AHIBase->ahib_DebugLevel >= AHI_DEBUG_HIGH)
  {
    Debug_RemoveAudioMode(id);
  }


  /* Why ?? */

  audiodb = LockDatabaseWrite();

  if(audiodb != NULL)
  {
    UnlockDatabase(audiodb);
  }

  audiodb = LockDatabaseWrite();

  if(audiodb != NULL)
  {
    if(id != AHI_INVALID_ID)
    {
      for(node=(struct AHI_AudioMode *)audiodb->ahidb_AudioModes.mlh_Head;
          node->ahidbn_MinNode.mln_Succ;
          node=(struct AHI_AudioMode *)node->ahidbn_MinNode.mln_Succ)
      {
        if(id == GetTagData(AHIDB_AudioID, AHI_INVALID_ID, node->ahidbn_Tags))
        {
          Remove((struct Node *) node);
          FreeVec(node);
          rc = TRUE;
          break;
        }
      }

      // Remove the entire database if it's empty

      Forbid();

      if(audiodb->ahidb_AudioModes.mlh_Head->mln_Succ == NULL)
      {
        UnlockDatabase(audiodb);

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

        if(audiodb != NULL)
        {
          RemSemaphore((struct SignalSemaphore *) audiodb);
          FreeVec(audiodb);
        }

        audiodb = NULL;

      }

      Permit();

    }
    UnlockDatabase(audiodb);
  }

  if(AHIBase->ahib_DebugLevel >= AHI_DEBUG_HIGH)
  {
    KPrintF("=>%ld\n",rc);
  }

  return rc;
}