void SMSTPDUContainer::makeMessage(uint8 *pPayload, size_t nPayloadSize, const char *rxPhone, const char *sServiceCenter) { size_t len; reset(); // If there is a service center entry for this message - use it. if (strlen(sServiceCenter) > 0) { len = packAddressInto(position() + 2, countFree() - 2, sServiceCenter); if (len > 0) { *this << (uint8)(len + 1); *this << (uint8)(SMS_(SCA_ADDRESS_TYPE)); pnext += len; } else { *this << (uint8)0; } } /* start of the SMS TPDU */ // ptpdu = position(); /* TODO: concatenated SMS */ *this << SMS_(TP_MESSAGE_TYPE); *this << SMS_(TP_MESSAGE_REFERENCE); // destination address // Skip two bytes from pnext and write the phonenumber len = packAddressInto(position() + 2, countFree() - 2, rxPhone); // Write the length ( remember that pnext isn't affected by // packaddress. *this << ((uint8)strlen(rxPhone)); // putByte(strlen(sRecipientPhone)); *this << SMS_(DEST_ADDRESS_TYPE); // Now skip over the phonenumber. pnext += len; *this << SMS_(MESSAGE_TP_PID); *this << SMS_(MESSAGE_TP_DCS); *this << SMS_(MESSAGE_TP_VP); // TODO: check concatenation *this << (uint8)(SMS_(nPayloadSize)); pnext += SMSUtil::putEncoded120x8(pnext, pPayload, nPayloadSize); }
int BufDaemon() { Buf* pBuf; while(1) { semaLock(SEMA_IDX_DAEMON); while( countFree() <= ((MAX_BUF_NUM / 10) * 3) ) { pBuf = popLru(); removeHash(pBuf->blkno); if( existDirty(pBuf->blkno) ) { //write to device. DevWriteBlock(pBuf->blkno, (char*)pBuf->pMem); removeDirty(pBuf->blkno); } else { removeClean(pBuf->blkno); } free(pBuf->pMem); memset(pBuf, 0, sizeof(Buf)); pBuf->pMem = malloc(BLOCK_SIZE); pushFree(pBuf); } semaUnlock(SEMA_IDX_MAIN); } }
Buf* BufFind(int blkno) { //check count of buffers in free list int free_buf_cnt = countFree(); if( free_buf_cnt <= MAX_BUFLIST_NUM / 10 ) { //wake daemon semaUnlock(SEMA_IDX_DAEMON); //wait for daemon's work semaLock(SEMA_IDX_MAIN); } Buf** list_head = &ppHashHead[blkno % HASH_TBL_SIZE]; Buf** list_tail = &ppHashTail[blkno % HASH_TBL_SIZE]; Buf* pBuf = NULL; pBuf = *list_head; while( pBuf != NULL ) { if( pBuf->blkno == blkno ) { break; } else { pBuf = pBuf->phNext; } } return pBuf; }
/* * Frees the first numPtrs objects in the ptrs list and returns the * amount of reclaimed storage. The list must contain addresses all in * the same mspace, and must be in increasing order. This implies that * there are no duplicates, and no entries are NULL. */ size_t dvmHeapSourceFreeList(size_t numPtrs, void **ptrs) { HS_BOILERPLATE(); if (numPtrs == 0) { return 0; } assert(ptrs != NULL); assert(*ptrs != NULL); Heap* heap = ptr2heap(gHs, *ptrs); size_t numBytes = 0; if (heap != NULL) { mspace msp = heap->msp; // Calling mspace_free on shared heaps disrupts sharing too // much. For heap[0] -- the 'active heap' -- we call // mspace_free, but on the other heaps we only do some // accounting. if (heap == gHs->heaps) { // Count freed objects. for (size_t i = 0; i < numPtrs; i++) { assert(ptrs[i] != NULL); assert(ptr2heap(gHs, ptrs[i]) == heap); countFree(heap, ptrs[i], &numBytes); } // Bulk free ptrs. mspace_bulk_free(msp, ptrs, numPtrs); } else { // This is not an 'active heap'. Only do the accounting. for (size_t i = 0; i < numPtrs; i++) { assert(ptrs[i] != NULL); assert(ptr2heap(gHs, ptrs[i]) == heap); countFree(heap, ptrs[i], &numBytes); } } } return numBytes; }
void RegAlloc::checkCount() { NanoAssert(count == (countActive() + countFree())); }
/* * Frees the first numPtrs objects in the ptrs list and returns the * amount of reclaimed storage. The list must contain addresses all in * the same mspace, and must be in increasing order. This implies that * there are no duplicates, and no entries are NULL. */ size_t dvmHeapSourceFreeList(size_t numPtrs, void **ptrs) { HS_BOILERPLATE(); if (numPtrs == 0) { return 0; } assert(ptrs != NULL); assert(*ptrs != NULL); Heap* heap = ptr2heap(gHs, *ptrs); size_t numBytes = 0; if (heap != NULL) { mspace msp = heap->msp; // Calling mspace_free on shared heaps disrupts sharing too // much. For heap[0] -- the 'active heap' -- we call // mspace_free, but on the other heaps we only do some // accounting. if (heap == gHs->heaps) { // mspace_merge_objects takes two allocated objects, and // if the second immediately follows the first, will merge // them, returning a larger object occupying the same // memory. This is a local operation, and doesn't require // dlmalloc to manipulate any freelists. It's pretty // inexpensive compared to free(). // ptrs is an array of objects all in memory order, and if // client code has been allocating lots of short-lived // objects, this is likely to contain runs of objects all // now garbage, and thus highly amenable to this optimization. // Unroll the 0th iteration around the loop below, // countFree ptrs[0] and initializing merged. assert(ptrs[0] != NULL); assert(ptr2heap(gHs, ptrs[0]) == heap); countFree(heap, ptrs[0], &numBytes); void *merged = ptrs[0]; for (size_t i = 1; i < numPtrs; i++) { assert(merged != NULL); assert(ptrs[i] != NULL); assert((intptr_t)merged < (intptr_t)ptrs[i]); assert(ptr2heap(gHs, ptrs[i]) == heap); countFree(heap, ptrs[i], &numBytes); // Try to merge. If it works, merged now includes the // memory of ptrs[i]. If it doesn't, free merged, and // see if ptrs[i] starts a new run of adjacent // objects to merge. if (mspace_merge_objects(msp, merged, ptrs[i]) == NULL) { mspace_free(msp, merged); merged = ptrs[i]; } } assert(merged != NULL); mspace_free(msp, merged); } else { // This is not an 'active heap'. Only do the accounting. for (size_t i = 0; i < numPtrs; i++) { assert(ptrs[i] != NULL); assert(ptr2heap(gHs, ptrs[i]) == heap); countFree(heap, ptrs[i], &numBytes); } } } return numBytes; }