void _mac_lock(void * address,unsigned long size) { static first=1; lock_mem * temp; if(first) atexit(mac_unlock_all); first=0; for(temp = top;temp != NULL;temp=temp->next){ if(address == temp->address){ if(size == temp->size){ temp->count++; } else{ UnholdMemory(temp->address,temp->size); HoldMemory(address,size); temp->address=address; temp->size=size; temp->count=1; } return; } } temp=(lock_mem *)NewPtr(sizeof(lock_mem)); if(temp){ temp->address=address; temp->size=size; temp->count=1; temp->next=top; top=temp; } HoldMemory(address,size); }
static void unlockMemory( INOUT MEM_INFO_HEADER *memHdrPtr ) { assert( isWritePtr( memHdrPtr, sizeof( MEM_INFO_HEADER ) ) ); /* If the memory was locked, unlock it now */ #if !defined( CALL_NOT_IN_CARBON ) || CALL_NOT_IN_CARBON if( memHdrPtr->flags & MEM_FLAG_LOCKED ) UnholdMemory( memPtr, memHdrPtr->size ); #endif /* Non Mac OS X memory locking */ }
static void mac_unlock_all() { lock_mem * temp; lock_mem * next; for(temp = top;temp != NULL;temp = next){ UnholdMemory(temp->address,temp->size); next = temp->next; DisposePtr((Ptr)temp); } }
void _mac_unlock(void * address,unsigned long size) { lock_mem * temp; lock_mem * last; last=NULL; for(temp = top;temp != NULL;temp=temp->next){ if(address == temp->address){ temp->count--; if(temp <= 0){ if(last == NULL) top=temp->next; else last->next=temp->next; UnholdMemory(temp->address,temp->size); DisposePtr((Ptr)temp); } return; } else{ last = temp; } } }