wait_queue_head_t osl_waitqueue_create ( int options /* semaphore option modes */ ) { SEM_ID semId;/*lint !e578 */ if ((semId = (SEM_ID) objAlloc (semClassId)) == NULL) return (NULL); /* initialize allocated semaphore */ if (semQueueInit (semId, options, 0) != OK) { objFree (semClassId, (char *) semId); return (NULL); } /* mark object memory to be freed during automatic resource reclamation */ /*lint -save -e115*/ OBJ_SET_DEALLOC_MEM (&semId->objCore); /*lint -restore +e115*/ #ifdef _WRS_CONFIG_SV_INSTRUMENTATION /* system viewer - level 1 event logging */ EVT_OBJ_3 (semId, semClassId, EVENT_SEMCCREATE, semId, options, initialCount); #endif /* _WRS_CONFIG_SV_INSTRUMENTATION */ return (wait_queue_head_t)(semId); }
STATUS memPartFree ( PART_ID partId, /* memory partition to add block to */ char *pBlock /* pointer to block of memory to free */ ) { FAST BLOCK_HDR *pHdr; FAST unsigned nWords; FAST BLOCK_HDR *pNextHdr; if (ID_IS_SHARED (partId)) /* partition is shared? */ { if (smMemPartFreeRtn == NULL) { errno = S_smObjLib_NOT_INITIALIZED; return (ERROR); } return ((*smMemPartFreeRtn) (SM_OBJ_ID_TO_ADRS (partId), pBlock)); } /* partition is local */ if (OBJ_VERIFY (partId, memPartClassId) != OK) return (ERROR); if (pBlock == NULL) return (OK); /* ANSI C compatibility */ pHdr = BLOCK_TO_HDR (pBlock); /* get exclusive access to the partition */ semTake (&partId->sem, WAIT_FOREVER); /* optional check for validity of block */ if ((partId->options & MEM_BLOCK_CHECK) && !memPartBlockIsValid (partId, pHdr, FALSE)) { semGive (&partId->sem); /* release mutual exclusion */ if (memPartBlockErrorRtn != NULL) (* memPartBlockErrorRtn) (partId, pBlock, "memPartFree"); if (partId->options & MEM_BLOCK_ERROR_SUSPEND_FLAG) { if ((taskIdCurrent->options & VX_UNBREAKABLE) == 0) taskSuspend (0); } errnoSet (S_memLib_BLOCK_ERROR); return (ERROR); } #ifdef WV_INSTRUMENTATION EVT_OBJ_3 (OBJ, partId, memPartClassId, EVENT_MEMFREE, partId, pBlock, 2 * (pHdr->nWords)); #endif nWords = pHdr->nWords; /* check if we can coalesce with previous block; * if so, then we just extend the previous block, * otherwise we have to add this as a new free block */ if (PREV_HDR (pHdr)->free) { pHdr->free = FALSE; /* this isn't a free block */ pHdr = PREV_HDR (pHdr); /* coalesce with prev block */ pHdr->nWords += nWords; } else { pHdr->free = TRUE; /* add new free block */ dllInsert (&partId->freeList, (DL_NODE *) NULL, HDR_TO_NODE (pHdr)); } /* check if we can coalesce with next block; * if so, then we can extend our block delete next block from free list */ pNextHdr = NEXT_HDR (pHdr); if (pNextHdr->free) { pHdr->nWords += pNextHdr->nWords; /* coalesce with next */ dllRemove (&partId->freeList, HDR_TO_NODE (pNextHdr)); } /* fix up prev info of whatever block is now next */ NEXT_HDR (pHdr)->pPrevHdr = pHdr; /* adjust allocation stats */ partId->curBlocksAllocated--; partId->curWordsAllocated -= nWords; semGive (&partId->sem); return (OK); }