From 28b6b1519c4c526662302fac4ed9b7f540bafd4a Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Mon, 26 Jan 2009 07:47:46 -0500 Subject: [PATCH] loader: Simplify handle allocation and refcounting. --- hw/xfree86/loader/loader.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c index dad44d827..56322180c 100644 --- a/hw/xfree86/loader/loader.c +++ b/hw/xfree86/loader/loader.c @@ -77,20 +77,9 @@ extern void *xorg_symbols[]; -/* - * handles are used to identify files that are loaded. Even archives - * are counted as a single file. - */ #define MAX_HANDLE 256 -#define HANDLE_FREE 0 -#define HANDLE_USED 1 -static char freeHandles[MAX_HANDLE]; static int refCount[MAX_HANDLE]; -/* - * modules are used to identify compilation units (ie object modules). - * Archives contain multiple modules, each of which is treated seperately. - */ static int moduleseq = 0; /* Prototypes for static functions. */ @@ -250,7 +239,7 @@ LoaderOpen(const char *module, const char *cname, int handle, * Find a free handle. */ new_handle = 1; - while (freeHandles[new_handle] && new_handle < MAX_HANDLE) + while (refCount[new_handle] && new_handle < MAX_HANDLE) new_handle++; if (new_handle == MAX_HANDLE) { @@ -262,7 +251,6 @@ LoaderOpen(const char *module, const char *cname, int handle, return -1; } - freeHandles[new_handle] = HANDLE_USED; refCount[new_handle] = 1; tmp = _LoaderListPush(); @@ -276,7 +264,7 @@ LoaderOpen(const char *module, const char *cname, int handle, if ((tmp->private = DLLoadModule(tmp, flags)) == NULL) { xf86Msg(X_ERROR, "Failed to load %s\n", module); _LoaderListPop(new_handle); - freeHandles[new_handle] = HANDLE_FREE; + refCount[new_handle] = 0; if (errmaj) *errmaj = LDR_NOLOAD; if (errmin) @@ -293,7 +281,7 @@ LoaderHandleOpen(int handle) if (handle < 0 || handle >= MAX_HANDLE) return -1; - if (freeHandles[handle] != HANDLE_USED) + if (!refCount[handle]) return -1; refCount[handle]++; @@ -342,8 +330,6 @@ LoaderUnload(int handle) free(tmp); } - freeHandles[handle] = HANDLE_FREE; - return 0; }