本文整理汇总了C++中ObtainSemaphore函数的典型用法代码示例。如果您正苦于以下问题:C++ ObtainSemaphore函数的具体用法?C++ ObtainSemaphore怎么用?C++ ObtainSemaphore使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ObtainSemaphore函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LockDatabaseWrite
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: uae_sem_wait
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;
}
示例3: DriverCleanup
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 );
}
示例4: AddClusterReceiver
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;
}
示例5: __initdetach
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 [email protected](-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 :( */
}
示例6: D
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;
}
示例7: LIBReadUnreadTexts
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);
}
示例8: RethinkPlayers
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);
}
示例9: writefiles
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;
}
示例10: MorphOS_LockMutex
void MorphOS_LockMutex(struct SignalSemaphore *mutex)
{
if (mutex)
{
ObtainSemaphore(mutex);
}
}
示例11: FeedReaders
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);
}
示例12: Pdebug
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);
}
示例13: util_RemNamedObject
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);
}
示例14: SDL_SemWaitTimeout
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;
}
示例15: DumpDbgMalloc
///
/// 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();
}