diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2012-10-23 10:06:48 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2012-12-06 20:26:29 +0100 |
commit | ee54109d9b784c72b25418933494e0691f42c2e8 (patch) | |
tree | 25fe1e3793887a5ab1c16b507149d416dd5c4b2c /libmsi/handle.c | |
parent | 4194f5245fd2c0277f432bc0b7be4e681d546af2 (diff) | |
download | msitools-ee54109d9b784c72b25418933494e0691f42c2e8.tar.gz msitools-ee54109d9b784c72b25418933494e0691f42c2e8.tar.xz msitools-ee54109d9b784c72b25418933494e0691f42c2e8.zip |
get rid of handles
Diffstat (limited to 'libmsi/handle.c')
-rw-r--r-- | libmsi/handle.c | 213 |
1 files changed, 23 insertions, 190 deletions
diff --git a/libmsi/handle.c b/libmsi/handle.c index cf6f901..bf1fb98 100644 --- a/libmsi/handle.c +++ b/libmsi/handle.c @@ -31,16 +31,6 @@ #include "msipriv.h" -static CRITICAL_SECTION MSI_handle_cs; -static CRITICAL_SECTION_DEBUG MSI_handle_cs_debug = -{ - 0, 0, &MSI_handle_cs, - { &MSI_handle_cs_debug.ProcessLocksList, - &MSI_handle_cs_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": MSI_handle_cs") } -}; -static CRITICAL_SECTION MSI_handle_cs = { &MSI_handle_cs_debug, -1, 0, 0, 0, 0 }; - static CRITICAL_SECTION MSI_object_cs; static CRITICAL_SECTION_DEBUG MSI_object_cs_debug = { @@ -51,109 +41,24 @@ static CRITICAL_SECTION_DEBUG MSI_object_cs_debug = }; static CRITICAL_SECTION MSI_object_cs = { &MSI_object_cs_debug, -1, 0, 0, 0, 0 }; -typedef struct msi_handle_info_t -{ - MSIOBJECTHDR *obj; - DWORD dwThreadId; -} msi_handle_info; - -static msi_handle_info *msihandletable = NULL; -static unsigned int msihandletable_size = 0; - -void msi_free_handle_table(void) -{ - msi_free( msihandletable ); - msihandletable = NULL; - msihandletable_size = 0; - DeleteCriticalSection(&MSI_handle_cs); - DeleteCriticalSection(&MSI_object_cs); -} - -static MSIHANDLE alloc_handle_table_entry(void) -{ - UINT i; - - /* find a slot */ - for(i=0; i<msihandletable_size; i++) - if( !msihandletable[i].obj ) - break; - if( i==msihandletable_size ) - { - msi_handle_info *p; - int newsize; - if (msihandletable_size == 0) - { - newsize = 256; - p = msi_alloc_zero(newsize*sizeof(msi_handle_info)); - } - else - { - newsize = msihandletable_size * 2; - p = msi_realloc_zero(msihandletable, - newsize*sizeof(msi_handle_info)); - } - if (!p) - return 0; - msihandletable = p; - msihandletable_size = newsize; - } - return i + 1; -} - -MSIHANDLE alloc_msihandle( MSIOBJECTHDR *obj ) -{ - msi_handle_info *entry; - MSIHANDLE ret; - - EnterCriticalSection( &MSI_handle_cs ); - - ret = alloc_handle_table_entry(); - if (ret) - { - entry = &msihandletable[ ret - 1 ]; - msiobj_addref( obj ); - entry->obj = obj; - entry->dwThreadId = GetCurrentThreadId(); - } - - LeaveCriticalSection( &MSI_handle_cs ); - - TRACE("%p -> %d\n", obj, ret ); - - return ret; -} - -void *msihandle2msiinfo(MSIHANDLE handle, UINT type) +void *msihandle2msiinfo(PMSIOBJECT obj, UINT type) { - MSIOBJECTHDR *ret = NULL; - - EnterCriticalSection( &MSI_handle_cs ); - handle--; - if( handle >= msihandletable_size ) - goto out; - if( !msihandletable[handle].obj ) - goto out; - if( msihandletable[handle].obj->magic != MSIHANDLE_MAGIC ) - goto out; - if( type && (msihandletable[handle].obj->type != type) ) - goto out; - ret = msihandletable[handle].obj; - msiobj_addref( ret ); - -out: - LeaveCriticalSection( &MSI_handle_cs ); + if( !obj ) + return NULL; + if( type && obj->type != type ) + return NULL; - return ret; + msiobj_addref( obj ); + return obj; } void *alloc_msiobject(UINT type, UINT size, msihandledestructor destroy ) { - MSIOBJECTHDR *info; + MSIOBJECT *info; info = msi_alloc_zero( size ); if( info ) { - info->magic = MSIHANDLE_MAGIC; info->type = type; info->refcount = 1; info->destructor = destroy; @@ -162,50 +67,38 @@ void *alloc_msiobject(UINT type, UINT size, msihandledestructor destroy ) return info; } -void msiobj_addref( MSIOBJECTHDR *info ) +void msiobj_addref( MSIOBJECT *info ) { if( !info ) return; - if( info->magic != MSIHANDLE_MAGIC ) - { - ERR("Invalid handle!\n"); - return; - } - InterlockedIncrement(&info->refcount); } -void msiobj_lock( MSIOBJECTHDR *info ) +void msiobj_lock( MSIOBJECT *obj ) { EnterCriticalSection( &MSI_object_cs ); } -void msiobj_unlock( MSIOBJECTHDR *info ) +void msiobj_unlock( MSIOBJECT *obj ) { LeaveCriticalSection( &MSI_object_cs ); } -int msiobj_release( MSIOBJECTHDR *info ) +int msiobj_release( MSIOBJECT *obj ) { int ret; - if( !info ) - return -1; - - if( info->magic != MSIHANDLE_MAGIC ) - { - ERR("Invalid handle!\n"); + if( !obj ) return -1; - } - ret = InterlockedDecrement( &info->refcount ); + ret = InterlockedDecrement( &obj->refcount ); if( ret==0 ) { - if( info->destructor ) - info->destructor( info ); - msi_free( info ); - TRACE("object %p destroyed\n", info); + if( obj->destructor ) + obj->destructor( obj ); + msi_free( obj ); + TRACE("object %p destroyed\n", obj); } return ret; @@ -214,72 +107,12 @@ int msiobj_release( MSIOBJECTHDR *info ) /*********************************************************** * MsiCloseHandle [MSI.@] */ -UINT WINAPI MsiCloseHandle(MSIHANDLE handle) +UINT WINAPI MsiCloseHandle(PMSIOBJECT obj) { - MSIOBJECTHDR *info = NULL; - UINT ret = ERROR_INVALID_HANDLE; - - TRACE("%x\n",handle); - - if (!handle) - return ERROR_SUCCESS; - - EnterCriticalSection( &MSI_handle_cs ); - - handle--; - if (handle >= msihandletable_size) - goto out; - - info = msihandletable[handle].obj; - if( !info ) - goto out; - - if( info->magic != MSIHANDLE_MAGIC ) - { - ERR("Invalid handle!\n"); - goto out; - } - - msihandletable[handle].obj = NULL; - msihandletable[handle].dwThreadId = 0; + TRACE("%x\n",obj); - ret = ERROR_SUCCESS; - - TRACE("handle %x destroyed\n", handle+1); -out: - LeaveCriticalSection( &MSI_handle_cs ); - if( info ) - msiobj_release( info ); - - return ret; -} - -/*********************************************************** - * MsiCloseAllHandles [MSI.@] - * - * Closes all handles owned by the current thread - * - * RETURNS: - * The number of handles closed - */ -UINT WINAPI MsiCloseAllHandles(void) -{ - UINT i, n=0; - - TRACE("\n"); - - EnterCriticalSection( &MSI_handle_cs ); - for(i=0; i<msihandletable_size; i++) - { - if(msihandletable[i].dwThreadId == GetCurrentThreadId()) - { - LeaveCriticalSection( &MSI_handle_cs ); - MsiCloseHandle( i+1 ); - EnterCriticalSection( &MSI_handle_cs ); - n++; - } - } - LeaveCriticalSection( &MSI_handle_cs ); + if( obj ) + msiobj_release( obj ); - return n; + return ERROR_SUCCESS; } |