Skip to content
Snippets Groups Projects
iax2-parser.c 31.4 KiB
Newer Older
  • Learn to ignore specific revisions
  • 	/* Attempt to get a frame from this thread's cache */
    	if ((iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) {
    		AST_LIST_TRAVERSE_SAFE_BEGIN(iax_frames, fr, list) {
    
    			if (fr->afdatalen >= datalen) {
    				size_t afdatalen = fr->afdatalen;
    
    				AST_LIST_REMOVE_CURRENT(iax_frames, list);
    				memset(fr, 0, sizeof(*fr));
    
    				fr->afdatalen = afdatalen;
    
    				break;
    			}
    		}
    		AST_LIST_TRAVERSE_SAFE_END
    	}
    	if (!fr) {
    
    		if (!(fr = ast_calloc_cache(1, sizeof(*fr) + datalen)))
    
    			return NULL;
    
    		fr->afdatalen = datalen;
    
    Mark Spencer's avatar
    Mark Spencer committed
    	}
    
    #else
    	if (!(fr = ast_calloc(1, sizeof(*fr) + datalen)))
    		return NULL;
    
    	fr->afdatalen = datalen;
    
    
    	fr->direction = direction;
    	fr->retrans = -1;
    
    	fr->cacheable = cacheable;
    
    	
    	if (fr->direction == DIRECTION_INGRESS)
    		ast_atomic_fetchadd_int(&iframes, 1);
    	else
    		ast_atomic_fetchadd_int(&oframes, 1);
    	
    
    	ast_atomic_fetchadd_int(&frames, 1);
    
    
    Mark Spencer's avatar
    Mark Spencer committed
    	return fr;
    }
    
    
    void iax_frame_free(struct iax_frame *fr)
    
    Mark Spencer's avatar
    Mark Spencer committed
    {
    
    #if !defined(LOW_MEMORY)
    
    	struct iax_frames *iax_frames;
    
    Mark Spencer's avatar
    Mark Spencer committed
    	/* Note: does not remove from scheduler! */
    	if (fr->direction == DIRECTION_INGRESS)
    
    		ast_atomic_fetchadd_int(&iframes, -1);
    
    Mark Spencer's avatar
    Mark Spencer committed
    	else if (fr->direction == DIRECTION_OUTGRESS)
    
    		ast_atomic_fetchadd_int(&oframes, -1);
    
    Mark Spencer's avatar
    Mark Spencer committed
    	else {
    		errorf("Attempt to double free frame detected\n");
    		return;
    	}
    
    	ast_atomic_fetchadd_int(&frames, -1);
    
    #if !defined(LOW_MEMORY)
    
    	if (!fr->cacheable || !(iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) {
    
    	fr->direction = 0;
    
    	AST_LIST_INSERT_HEAD(iax_frames, fr, list);
    
    #if !defined(LOW_MEMORY)
    
    static void frame_cache_cleanup(void *data)
    {
    	struct iax_frames *frames = data;
    	struct iax_frame *cur;
    
    	while ((cur = AST_LIST_REMOVE_HEAD(frames, list)))
    
    Mark Spencer's avatar
    Mark Spencer committed
    int iax_get_frames(void) { return frames; }
    int iax_get_iframes(void) { return iframes; }
    int iax_get_oframes(void) { return oframes; }