summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-09-03 22:53:28 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-10-14 17:56:44 -0700
commit2704bdb24a2c7bac65b90e05f1a68438b34ecf58 (patch)
tree72eb3ff1aacc4bd65ab34abb3b3e270ae3383905 /hw
parent6c06c268adbab63ebe7490489aa030724cbdc54b (diff)
DMX glxproxy: Don't allocate & copy data just to free it unused
Two functions in the DMX glxproxy code loop over all the backend screens, starting at the highest numbered and counting down to the lowest. Previously, for each screen, the code would allocate a buffer large enough to read the reply from the backend, copy that reply into the buffer, and then if it wasn't the final screen, free it. Only the buffer from the final screen is used, to pass on to the client in the reply. This modifies it to just immediately discard the responses from the screens as we loop through it, only doing the allocate & copy work for the one buffer we pass back to the client. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: Alex Deucher <aleander.deucher@amd.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/dmx/glxProxy/glxsingle.c30
-rw-r--r--hw/dmx/glxProxy/glxvendor.c30
2 files changed, 34 insertions, 26 deletions
diff --git a/hw/dmx/glxProxy/glxsingle.c b/hw/dmx/glxProxy/glxsingle.c
index abfb880a3..679a302ea 100644
--- a/hw/dmx/glxProxy/glxsingle.c
+++ b/hw/dmx/glxProxy/glxsingle.c
@@ -349,25 +349,29 @@ __glXForwardAllWithReply(__GLXclientState * cl, GLbyte * pc)
* get the reply from the back-end server
*/
_XReply(dpy, (xReply *) &be_reply, 0, False);
- be_buf_size = be_reply.length << 2;
- if (be_buf_size > 0) {
- be_buf = (char *) malloc(be_buf_size);
- if (be_buf) {
- _XRead(dpy, be_buf, be_buf_size);
+ if (s == from_screen) {
+ /* Save data from last reply to send on to client */
+ be_buf_size = be_reply.length << 2;
+ if (be_buf_size > 0) {
+ be_buf = malloc(be_buf_size);
+ if (be_buf) {
+ _XRead(dpy, be_buf, be_buf_size);
+ }
+ else {
+ /* Throw data on the floor */
+ _XEatDataWords(dpy, be_reply.length);
+ return BadAlloc;
+ }
}
- else {
- /* Throw data on the floor */
+ }
+ else {
+ /* Just discard data from all replies before the last one */
+ if (be_reply.length > 0)
_XEatDataWords(dpy, be_reply.length);
- return BadAlloc;
- }
}
UnlockDisplay(dpy);
SyncHandle();
-
- if (s > from_screen && be_buf_size > 0) {
- free(be_buf);
- }
}
/*
diff --git a/hw/dmx/glxProxy/glxvendor.c b/hw/dmx/glxProxy/glxvendor.c
index 50d505c4b..b475daf0f 100644
--- a/hw/dmx/glxProxy/glxvendor.c
+++ b/hw/dmx/glxProxy/glxvendor.c
@@ -332,25 +332,29 @@ __glXVForwardAllWithReply(__GLXclientState * cl, GLbyte * pc)
* get the reply from the back-end server
*/
_XReply(dpy, (xReply *) &be_reply, 0, False);
- be_buf_size = be_reply.length << 2;
- if (be_buf_size > 0) {
- be_buf = (char *) malloc(be_buf_size);
- if (be_buf) {
- _XRead(dpy, be_buf, be_buf_size);
+ if (s == from_screen) {
+ /* Save data from last reply to send on to client */
+ be_buf_size = be_reply.length << 2;
+ if (be_buf_size > 0) {
+ be_buf = malloc(be_buf_size);
+ if (be_buf) {
+ _XRead(dpy, be_buf, be_buf_size);
+ }
+ else {
+ /* Throw data on the floor */
+ _XEatDataWords(dpy, be_reply.length);
+ return BadAlloc;
+ }
}
- else {
- /* Throw data on the floor */
+ }
+ else {
+ /* Just discard data from all replies before the last one */
+ if (be_reply.length > 0)
_XEatDataWords(dpy, be_reply.length);
- return BadAlloc;
- }
}
UnlockDisplay(dpy);
SyncHandle();
-
- if (s > from_screen && be_buf_size > 0) {
- free(be_buf);
- }
}
/*