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; }
/************************************************************************** MUIM_Semaphore_ObtainShared **************************************************************************/ IPTR Semaphore__MUIM_ObtainShared(struct IClass *cl, Object *obj, struct MUIP_Semaphore_ObtainShared *msg) { struct MUI_SemaphoreData *data = INST_DATA(cl, obj); ObtainSemaphoreShared(&data->sem); return 0; }
/// /// LockMailTransferListShared() void LockMailTransferListShared(const struct MailTransferList *tlist) { ENTER(); if(AttemptSemaphoreShared(tlist->lockSemaphore) == FALSE) { if(transferLocks > 0) E(DBF_ALWAYS, "nested (%ld) shared lock of MailTransferList %08lx", transferLocks + 1, tlist); ObtainSemaphoreShared(tlist->lockSemaphore); } transferLocks++; LEAVE(); }
struct hostent *gethtent(struct SocketBase *libPtr) { struct HostentNode *hn; hn = libPtr->HostentNode; if (!hn) { ObtainSemaphoreShared (&ndb_Lock); hn = (struct HostentNode *)NDB->ndb_Hosts.mlh_Head; } if (hn->hn_Node.mln_Succ) { libPtr->HostentNode = (struct HostentNode *)hn->hn_Node.mln_Succ; return &hn->hn_Ent; } else return NULL; }
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; }
void DebugResource(struct xadMasterBaseP *xadMasterBase, const xadSTRING *format, ...) { if(format > (xadSTRPTR)1) { va_list va; va_start(va, format); DoDebug(DEBUGFLAG_RESOURCE, format, 0, va); va_end(va); } else { struct xadObject *obj; struct Task *t = 0; if(format != (xadSTRPTR)1) t = FindTask(NULL); /* else { DebugResource(xadMasterBase, "LibExpunge: resource checkup"); } */ ObtainSemaphoreShared(&xadMasterBase->xmb_ResourceLock); for(obj = xadMasterBase->xmb_Resource; obj; obj = obj->xo_Last) { if(obj->xo_Cookie != XADOBJCOOKIE) { DebugResource(xadMasterBase, "xadFreeObjectA: %s ($%08lx) has cookie $%08lx", xadGetObjectTypeName(obj->xo_Type), obj+1, obj->xo_Cookie); } if(format || t == obj->xo_Task) { DebugResource(xadMasterBase, "Lib%s: %s ($%08lx) task $%08lx size %ld not freed", format ? "Expunge" : "Close", xadGetObjectTypeName(obj->xo_Type), obj+1, obj->xo_Task, obj->xo_Size); } } ReleaseSemaphore(&xadMasterBase->xmb_ResourceLock); } }
struct NamedObject *util_FindNamedObject(pUtility UtilBase, struct NamedObject *nameSpace, STRPTR name, struct NamedObject *lastObject) { struct NamedObj *tmp; struct NamedObject *ret = NULL; struct NameSpace *ns = getNameSpace(UtilBase, nameSpace); if (ns == NULL) return NULL; ObtainSemaphoreShared(&ns->ns_Semaphore); if (lastObject == NULL) tmp = (struct NamedObj *)ns->ns_Entries.mlh_Head; else tmp = (struct NamedObj *)SYSTEM(lastObject)->no_Non.non_Node.ln_Succ; tmp = searchns(UtilBase, tmp, ns, name); if (tmp) { tmp->no_Non.non_UseCount++; ret = (struct NamedObject *) BASEOBJECT(tmp); } ReleaseSemaphore(&ns->ns_Semaphore); return ret; }
void sethtent(struct SocketBase *libPtr) { ObtainSemaphoreShared (&ndb_Lock); libPtr->HostentNode = (struct HostentNode *)NDB->ndb_Hosts.mlh_Head; }
long LIBFUNC L_GetSemaphore( REG(a0, struct SignalSemaphore *sem), REG(d0, long exclusive), REG(a1, char *name)) { #ifdef TRAP_SEMAPHORE SemaphoreNode *node; SemaphoreOwner *owner=0; struct MyLibrary *libbase; struct LibData *data; #endif // Attempt only? if (exclusive&SEMF_ATTEMPT) { long res; // Want exclusive lock? if (exclusive&SEMF_EXCLUSIVE) res=AttemptSemaphore(sem); // Shared lock else { // Try for shared semaphore if (!(res=AttemptSemaphoreShared(sem))) { // Fix <v39 bug if (((struct Library *)SysBase)->lib_Version<39) { // Try for exclusive instead res=AttemptSemaphore(sem); } } } return res; } #ifdef TRAP_SEMAPHORE // Get our library data libbase=GET_DOPUSLIB; data=(struct LibData *)libbase->ml_UserData; // Lock semaphore list ObtainSemaphore(&data->semaphores.lock); // Look for semaphore in list for (node=(SemaphoreNode *)data->semaphores.list.lh_Head; node->node.mln_Succ; node=(SemaphoreNode *)node->node.mln_Succ) { // Try to match semaphore if (node->sem==sem) break; } // Not matched? if (!node->node.mln_Succ) { // Allocate node if (node=AllocVec(sizeof(SemaphoreNode),MEMF_CLEAR)) { // Add to semaphore list AddTail(&data->semaphores.list,(struct Node *)node); // Set semaphore pointer node->sem=sem; // Initialise lists NewList((struct List *)&node->owners); NewList((struct List *)&node->waiters); } } // Got a valid node? if (node) { // Allocate owner node if (owner=AllocVec(sizeof(SemaphoreOwner),MEMF_CLEAR)) { // Fill out owner owner->task=FindTask(0); owner->exclusive=exclusive; owner->data=name; // Add to waiter list AddTail((struct List *)&node->waiters,(struct Node *)owner); } } // Unlock semaphore list ReleaseSemaphore(&data->semaphores.lock); #endif // Try to get the actual semaphore if (exclusive&SEMF_EXCLUSIVE) ObtainSemaphore(sem); else { // Fix <v39 bug if (((struct Library *)SysBase)->lib_Version<39) { // Try to get shared semaphore if (!AttemptSemaphoreShared(sem)) { // Try for exclusive semaphore if (!AttemptSemaphore(sem)) { // Wait for shared lock ObtainSemaphoreShared(sem); } } } // Under 39, just ask for shared lock else ObtainSemaphoreShared(sem); } #ifdef TRAP_SEMAPHORE // Valid owner? if (owner) { // Lock semaphore list ObtainSemaphore(&data->semaphores.lock); // Remove us from the waiter queue Remove((struct Node *)owner); // Add us to the owner queue AddTail((struct List *)&node->owners,(struct Node *)owner); // Unlock semaphore list ReleaseSemaphore(&data->semaphores.lock); } #endif return TRUE; }
int get_site_entry(struct opusftp_globals *og,struct site_entry *e,IPCData *ipc) { struct List *list; struct Node *node,*next; int type=MATCH_NONE; int result=0; struct site_entry *site; if (!e) return(FALSE); ObtainSemaphoreShared(&og->og_SiteList_semaphore); if (!og->og_SiteList) read_build_addressbook(og,ipc); if (!og->og_SiteList) goto done; if (*e->se_name) type=MATCH_NAME; else if (*e->se_host) type=MATCH_HOST; else goto done; list=&og->og_SiteList->list; if (list && !IsListEmpty(list)) { if ((node=list->lh_Head)) { int count=0; while ((next=node->ln_Succ)) { int found; count++; site=(struct site_entry *)((Att_Node *)node)->data; if (type==MATCH_NAME) found=stricmp(e->se_name,site->se_name); else found=stricmp(e->se_host,site->se_host); if (found==0) { // copy site entry copy_site_entry(og,e,site); // keep match position as return value result=count; break; } node=next; } } } done: ReleaseSemaphore(&og->og_SiteList_semaphore); return(result); }