static DFBResult x11DeallocateBuffer( CoreSurfacePool *pool, void *pool_data, void *pool_local, CoreSurfaceBuffer *buffer, CoreSurfaceAllocation *allocation, void *alloc_data ) { x11AllocationData *alloc = alloc_data; x11PoolLocalData *local = pool_local; DFBX11 *x11 = local->x11; DFBX11Shared *shared = x11->shared; void *addr; D_DEBUG_AT( X11_Surfaces, "%s()\n", __FUNCTION__ ); D_MAGIC_ASSERT( pool, CoreSurfacePool ); CORE_SURFACE_ALLOCATION_ASSERT( allocation ); switch (alloc->type) { case X11_ALLOC_PIXMAP: case X11_ALLOC_WINDOW: if (allocation->type & CSTF_PREALLOCATED) { // don't delete } else XFreePixmap( x11->display, alloc->xid ); break; case X11_ALLOC_IMAGE: x11ImageDestroy( x11, &alloc->image ); // FIXME: also detach in other processes! (e.g. via reactor) addr = direct_hash_lookup( local->hash, alloc->image.seginfo.shmid ); if (addr) { x11ImageDetach( &alloc->image, addr ); direct_hash_remove( local->hash, alloc->image.seginfo.shmid ); } break; case X11_ALLOC_SHM: if (alloc->ptr) SHFREE( shared->data_shmpool, alloc->ptr ); break; default: D_BUG( "unexpected allocation type %d\n", alloc->type ); return DFB_BUG; } return DFB_OK; }
void direct_dbg_free( const char *file, int line, const char *func, const char *what, void *mem ) { unsigned long *val; MemDesc *desc; if (!mem) { D_WARN( "%s (NULL) called", __FUNCTION__ ); return; } val = (unsigned long*)((char*) mem - DISABLED_OFFSET); if (val[0] == ~0) { D_DEBUG_AT( Direct_Mem, " - number of bytes of %s [%s:%d in %s()] -> %p\n", what, file, line, func, mem ); val[0] = 0; direct_free( val ); return; } /* Debug only. */ direct_mutex_lock( &alloc_lock ); desc = (MemDesc*)((char*) mem - sizeof(MemDesc)); D_ASSERT( desc->mem == mem ); if (direct_hash_remove( &alloc_hash, (unsigned long) mem )) { D_ERROR( "Direct/Mem: Not freeing unknown %p (%s) from [%s:%d in %s()] - corrupt/incomplete list?\n", mem, what, file, line, func ); } else { D_DEBUG_AT( Direct_Mem, " -"_ZUn(6)" bytes [%s:%d in %s()] -> %p '%s'\n", desc->bytes, file, line, func, mem, what ); if (desc->trace) direct_trace_free_buffer( desc->trace ); direct_free( desc ); } direct_mutex_unlock( &alloc_lock ); }
static void InputHub_DeviceRemove( void *ctx, DFBInputDeviceID device_id ) { InputHubDeviceNode *node; D_DEBUG_AT( Input_Hub, "%s( ID %u )\n", __FUNCTION__, device_id ); node = direct_hash_lookup( m_nodes, device_id ); if (node) { dfb_input_remove_device( device_id, m_driver ); direct_hash_remove( m_nodes, device_id ); D_FREE( node ); } else D_WARN( "don't have device (ID %u)", device_id ); }
DirectResult DirectResultTypeUnregister( DirectResultType *type ) { DirectResult ret; D_DEBUG_AT( Direct_Result, "%s( %p )\n", __FUNCTION__, type ); D_MAGIC_ASSERT( type, DirectResultType ); D_DEBUG_AT( Direct_Result, " -> refs %d\n", type->refs ); D_DEBUG_AT( Direct_Result, " -> base 0x%08x\n", type->base ); D_DEBUG_AT( Direct_Result, " -> strings %p\n", type->result_strings ); D_DEBUG_AT( Direct_Result, " -> count %u\n", type->result_count ); D_ASSERT( type->result_count > 0 ); D_ASSERT( type->result_count <= D_RESULT_TYPE_SPACE ); D_DEBUG_AT( Direct_Result, " => %s\n", type->result_strings[0] ); ret = direct_mutex_lock( &result_mutex ); if (ret) return ret; D_ASSERT( type->refs > 0 ); D_ASSERT( direct_hash_lookup( &result_types, type->base ) == type ); if (! --(type->refs)) { D_MAGIC_CLEAR( type ); ret = direct_hash_remove( &result_types, type->base ); } direct_mutex_unlock( &result_mutex ); return ret; }
static void InputHub_DeviceAdd( void *ctx, DFBInputDeviceID device_id, const DFBInputDeviceDescription *desc ) { DirectResult ret; InputHubDeviceNode *node; D_DEBUG_AT( Input_Hub, "%s( ID %u, '%s' )\n", __FUNCTION__, device_id, desc->name ); node = direct_hash_lookup( m_nodes, device_id ); if (!node) { node = D_CALLOC( 1, sizeof(InputHubDeviceNode) ); if (!node) { D_OOM(); return; } node->device_id = device_id; node->description = *desc; ret = direct_hash_insert( m_nodes, device_id, node ); if (ret) { D_FREE( node ); return; } ret = dfb_input_create_device( device_id, m_core, m_driver ); if (ret) { direct_hash_remove( m_nodes, device_id ); D_FREE( node ); return; } } else D_WARN( "already have device (ID %u)", device_id ); }
static DFBResult x11DeallocateBuffer( CoreSurfacePool *pool, void *pool_data, void *pool_local, CoreSurfaceBuffer *buffer, CoreSurfaceAllocation *allocation, void *alloc_data ) { x11AllocationData *alloc = alloc_data; x11PoolLocalData *local = pool_local; DFBX11 *x11 = local->x11; DFBX11Shared *shared = x11->shared; void *addr; D_DEBUG_AT( X11_Surfaces, "%s()\n", __FUNCTION__ ); D_MAGIC_ASSERT( pool, CoreSurfacePool ); CORE_SURFACE_ALLOCATION_ASSERT( allocation ); // FIXME: also detach in other processes! (e.g. via reactor) addr = direct_hash_lookup( local->hash, alloc->image.seginfo.shmid ); if (addr) { x11ImageDetach( &alloc->image, addr ); direct_hash_remove( local->hash, alloc->image.seginfo.shmid ); } if (alloc->real) return x11ImageDestroy( x11, &alloc->image ); if (alloc->ptr) SHFREE( shared->data_shmpool, alloc->ptr ); return DFB_OK; }
void * direct_dbg_realloc( const char *file, int line, const char *func, const char *what, void *mem, size_t bytes ) { unsigned long *val; MemDesc *desc; D_DEBUG_AT( Direct_Mem, " *"_ZUn(6)" bytes [%s:%d in %s()] '%s' <- %p\n", bytes, file, line, func, what, mem ); if (!mem) return direct_dbg_malloc( file, line, func, bytes ); if (!bytes) { direct_dbg_free( file, line, func, what, mem ); return NULL; } val = (unsigned long*)((char*) mem - DISABLED_OFFSET); if (val[0] == ~0) { D_DEBUG_AT( Direct_Mem, " *"_ZUn(6)" bytes [%s:%d in %s()] '%s'\n", bytes, file, line, func, what ); val = direct_realloc( val, bytes + DISABLED_OFFSET ); D_DEBUG_AT( Direct_Mem, " '-> %p\n", val ); if (val) { D_ASSERT( val[0] == ~0 ); mem = val; return (char*) mem + DISABLED_OFFSET; } return NULL; } /* Debug only. */ direct_mutex_lock( &alloc_lock ); desc = (MemDesc*)((char*) mem - sizeof(MemDesc)); D_ASSERT( desc->mem == mem ); if (direct_hash_remove( &alloc_hash, (unsigned long) mem )) { D_ERROR( "Direct/Mem: Not reallocating unknown %p (%s) from [%s:%d in %s()] - corrupt/incomplete list?\n", mem, what, file, line, func ); mem = direct_dbg_malloc( file, line, func, bytes ); } else { void *new_mem = direct_realloc( desc, bytes + sizeof(MemDesc) ); D_DEBUG_AT( Direct_Mem, " '-> %p\n", new_mem ); D_DEBUG_AT( Direct_Mem, " %c"_ZUn(6)" bytes [%s:%d in %s()] (%s"_ZU") <- %p -> %p '%s'\n", (bytes > desc->bytes) ? '>' : '<', bytes, file, line, func, (bytes > desc->bytes) ? "+" : "", bytes - desc->bytes, mem, new_mem, what); if (desc->trace) { direct_trace_free_buffer( desc->trace ); desc->trace = NULL; } if (!new_mem) D_WARN( "could not reallocate memory (%p: "_ZU"->"_ZU")", mem, desc->bytes, bytes ); else desc = fill_mem_desc( new_mem, bytes, func, file, line, direct_trace_copy_buffer(NULL) ); mem = desc->mem; } direct_mutex_unlock( &alloc_lock ); return mem; }