diff options
author | Keith Whitwell <keith@tungstengraphics.com> | 2006-08-02 10:24:01 +0000 |
---|---|---|
committer | Keith Whitwell <keith@tungstengraphics.com> | 2006-08-02 10:24:01 +0000 |
commit | f378bcd8bf419153a0681bfc9a0f40fd3e7a4be2 (patch) | |
tree | 1c28d5f4c93a7e1ce903bbd672ed34ccc077f6a6 | |
parent | ded29089f336c3b457d8b4eba13822156e27d338 (diff) | |
download | mesa-f378bcd8bf419153a0681bfc9a0f40fd3e7a4be2.tar.gz |
drmOpen/Close once
-rw-r--r-- | src/glx/x11/glxext.c | 69 | ||||
-rw-r--r-- | src/mesa/drivers/dri/common/dri_util.c | 2 |
2 files changed, 67 insertions, 4 deletions
diff --git a/src/glx/x11/glxext.c b/src/glx/x11/glxext.c index 7ceed42fa23..acc72796871 100644 --- a/src/glx/x11/glxext.c +++ b/src/glx/x11/glxext.c @@ -722,6 +722,68 @@ static const __DRIinterfaceMethods interface_methods = { glXGetMscRateOML, }; +#define DRM_MAX_FDS 16 +static struct { + char *BusID; + int fd; + int refcount; +} connection[DRM_MAX_FDS]; + +static int nr_fds = 0; + +int drmOpenOnce(void *unused, + const char *BusID, + int *newlyopened) +{ + int i; + int fd; + + for (i = 0; i < nr_fds; i++) + if (strcmp(BusID, connection[i].BusID) == 0) { + connection[i].refcount++; + *newlyopened = 0; + return connection[i].fd; + } + + fd = drmOpen(unused, BusID); + if (fd <= 0 || nr_fds == DRM_MAX_FDS) + return fd; + + connection[nr_fds].BusID = strdup(BusID); + connection[nr_fds].fd = fd; + connection[nr_fds].refcount = 1; + *newlyopened = 1; + + fprintf(stderr, "saved connection %d for %s %d\n", + nr_fds, connection[nr_fds].BusID, + strcmp(BusID, connection[nr_fds].BusID)); + + nr_fds++; + + return fd; +} + +void drmCloseOnce(int fd) +{ + int i; + + + + for (i = 0; i < nr_fds; i++) { + if (fd == connection[i].fd) { + if (--connection[i].refcount == 0) { + drmClose(connection[i].fd); + free(connection[i].BusID); + + if (i < --nr_fds) + connection[i] = connection[nr_fds]; + + return; + } + } + } +} + /** * Perform the required libGL-side initialization and call the client-side @@ -773,7 +835,8 @@ CallCreateNewScreen(Display *dpy, int scrn, __DRIscreen *psc, framebuffer.dev_priv = NULL; if (XF86DRIOpenConnection(dpy, scrn, &hSAREA, &BusID)) { - fd = drmOpen(NULL,BusID); + int newlyopened; + fd = drmOpenOnce(NULL,BusID, &newlyopened); Xfree(BusID); /* No longer needed */ err_msg = "open DRM"; @@ -800,7 +863,7 @@ CallCreateNewScreen(Display *dpy, int scrn, __DRIscreen *psc, } err_msg = "XF86DRIAuthConnection"; - if (XF86DRIAuthConnection(dpy, scrn, magic)) { + if (!newlyopened || XF86DRIAuthConnection(dpy, scrn, magic)) { char *driverName; /* @@ -904,7 +967,7 @@ CallCreateNewScreen(Display *dpy, int scrn, __DRIscreen *psc, } if ( fd >= 0 ) { - (void)drmClose(fd); + (void)drmCloseOnce(fd); } (void)XF86DRICloseConnection(dpy, scrn); diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c index b5c20a066a5..bac5bee6d4a 100644 --- a/src/mesa/drivers/dri/common/dri_util.c +++ b/src/mesa/drivers/dri/common/dri_util.c @@ -841,7 +841,7 @@ static void driDestroyScreen(__DRInativeDisplay *dpy, int scrn, void *screenPriv (void)drmUnmap((drmAddress)psp->pSAREA, SAREA_MAX); (void)drmUnmap((drmAddress)psp->pFB, psp->fbSize); _mesa_free(psp->pDevPriv); - (void)drmClose(psp->fd); + (void)drmCloseOnce(psp->fd); if ( psp->modes != NULL ) { (*dri_interface->destroyContextModes)( psp->modes ); } |