Commit fad78817 authored by dscho's avatar dscho

pthreads corrections

parent 631d3be5
...@@ -2,8 +2,8 @@ INCLUDES=-I. ...@@ -2,8 +2,8 @@ INCLUDES=-I.
VNCSERVERLIB=-L. -lvncserver -L/usr/local/lib -lz -ljpeg VNCSERVERLIB=-L. -lvncserver -L/usr/local/lib -lz -ljpeg
# Uncomment these two lines to enable use of PThreads # Uncomment these two lines to enable use of PThreads
#PTHREADDEF = -DHAVE_PTHREADS PTHREADDEF = -DHAVE_PTHREADS
#PTHREADLIB = -lpthread PTHREADLIB = -lpthread
# Comment the following line to disable the use of 3 Bytes/Pixel. # Comment the following line to disable the use of 3 Bytes/Pixel.
# The code for 3 Bytes/Pixel is not very efficient! # The code for 3 Bytes/Pixel is not very efficient!
......
...@@ -452,7 +452,11 @@ void rfbPrintXCursor(rfbCursorPtr cursor) ...@@ -452,7 +452,11 @@ void rfbPrintXCursor(rfbCursorPtr cursor)
extern void rfbSetCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr c,Bool freeOld) extern void rfbSetCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr c,Bool freeOld)
{ {
LOCK(rfbScreen->cursorMutex); LOCK(rfbScreen->cursorMutex);
rfbUndrawCursor(rfbScreen); while(rfbScreen->cursorIsDrawn) {
UNLOCK(rfbScreen->cursorMutex);
rfbUndrawCursor(rfbScreen);
LOCK(rfbScreen->cursorMutex);
}
if(freeOld && rfbScreen->cursor) if(freeOld && rfbScreen->cursor)
rfbFreeCursor(rfbScreen->cursor); rfbFreeCursor(rfbScreen->cursor);
......
...@@ -85,17 +85,15 @@ void rfbScheduleCopyRegion(rfbScreenInfoPtr rfbScreen,sraRegionPtr copyRegion,in ...@@ -85,17 +85,15 @@ void rfbScheduleCopyRegion(rfbScreenInfoPtr rfbScreen,sraRegionPtr copyRegion,in
/* while(!sraRgnEmpty(cl->copyRegion)) */ { /* while(!sraRgnEmpty(cl->copyRegion)) */ {
#ifdef HAVE_PTHREADS #ifdef HAVE_PTHREADS
if(cl->screen->backgroundLoop) { if(!cl->screen->backgroundLoop)
SIGNAL(cl->updateCond);
UNLOCK(cl->updateMutex);
LOCK(cl->updateMutex);
} else
#endif #endif
{ {
sraRegionPtr updateRegion = sraRgnCreateRgn(cl->modifiedRegion); sraRegionPtr updateRegion = sraRgnCreateRgn(cl->modifiedRegion);
sraRgnOr(updateRegion,cl->copyRegion); sraRgnOr(updateRegion,cl->copyRegion);
UNLOCK(cl->updateMutex);
rfbSendFramebufferUpdate(cl,updateRegion); rfbSendFramebufferUpdate(cl,updateRegion);
sraRgnDestroy(updateRegion); sraRgnDestroy(updateRegion);
continue;
} }
} }
} else { } else {
...@@ -525,7 +523,11 @@ void rfbScreenCleanup(rfbScreenInfoPtr rfbScreen) ...@@ -525,7 +523,11 @@ void rfbScreenCleanup(rfbScreenInfoPtr rfbScreen)
free(rfbScreen); free(rfbScreen);
} }
#ifdef HAVE_PTHREADS
void rfbInitServerWithPthreads(rfbScreenInfoPtr rfbScreen)
#else
void rfbInitServer(rfbScreenInfoPtr rfbScreen) void rfbInitServer(rfbScreenInfoPtr rfbScreen)
#endif
{ {
#ifdef WIN32 #ifdef WIN32
WSADATA trash; WSADATA trash;
......
...@@ -172,7 +172,7 @@ typedef struct { ...@@ -172,7 +172,7 @@ typedef struct {
#undef MUTEX #undef MUTEX
#define MUTEX(mutex) char dummy##mutex #define MUTEX(mutex) char dummy##mutex
#undef COND #undef COND
#define COND(cont) char dummy##cond #define COND(cond) char dummy##cond
#endif #endif
/* /*
...@@ -280,11 +280,6 @@ typedef struct ...@@ -280,11 +280,6 @@ typedef struct
char* underCursorBuffer; char* underCursorBuffer;
Bool dontConvertRichCursorToXCursor; Bool dontConvertRichCursorToXCursor;
struct rfbCursor* cursor; struct rfbCursor* cursor;
MUTEX(cursorMutex);
#ifdef HAVE_PTHREADS
Bool backgroundLoop;
#endif
/* the following members have to be supplied by the serving process */ /* the following members have to be supplied by the serving process */
char* frameBuffer; char* frameBuffer;
...@@ -300,6 +295,11 @@ typedef struct ...@@ -300,6 +295,11 @@ typedef struct
/* displayHook is called just before a frame buffer update */ /* displayHook is called just before a frame buffer update */
DisplayHookPtr displayHook; DisplayHookPtr displayHook;
MUTEX(cursorMutex);
#ifdef HAVE_PTHREADS
Bool backgroundLoop;
#endif
} rfbScreenInfo, *rfbScreenInfoPtr; } rfbScreenInfo, *rfbScreenInfoPtr;
...@@ -398,20 +398,6 @@ typedef struct rfbClientRec { ...@@ -398,20 +398,6 @@ typedef struct rfbClientRec {
int copyDX, copyDY; /* the translation by which the copy happens */ int copyDX, copyDY; /* the translation by which the copy happens */
#ifdef HAVE_PTHREADS
/* whenever a client is referenced, the refCount has to be incremented
and afterwards decremented.
Use the functions rfbIncrClientRef(cl) and rfbDecrClientRef(cl);
*/
int refCount;
MUTEX(refCountMutex);
COND(deleteCond);
MUTEX(outputMutex);
MUTEX(updateMutex);
COND(updateCond);
#endif
sraRegionPtr modifiedRegion; sraRegionPtr modifiedRegion;
/* As part of the FramebufferUpdateRequest, a client can express interest /* As part of the FramebufferUpdateRequest, a client can express interest
...@@ -488,6 +474,20 @@ typedef struct rfbClientRec { ...@@ -488,6 +474,20 @@ typedef struct rfbClientRec {
struct rfbClientRec *prev; struct rfbClientRec *prev;
struct rfbClientRec *next; struct rfbClientRec *next;
#ifdef HAVE_PTHREADS
/* whenever a client is referenced, the refCount has to be incremented
and afterwards decremented.
Use the functions rfbIncrClientRef(cl) and rfbDecrClientRef(cl);
*/
int refCount;
MUTEX(refCountMutex);
COND(deleteCond);
MUTEX(outputMutex);
MUTEX(updateMutex);
COND(updateCond);
#endif
} rfbClientRec, *rfbClientPtr; } rfbClientRec, *rfbClientPtr;
...@@ -742,6 +742,11 @@ void doNothingWithClient(rfbClientPtr cl); ...@@ -742,6 +742,11 @@ void doNothingWithClient(rfbClientPtr cl);
extern rfbScreenInfoPtr rfbGetScreen(int argc,char** argv, extern rfbScreenInfoPtr rfbGetScreen(int argc,char** argv,
int width,int height,int bitsPerSample,int samplesPerPixel, int width,int height,int bitsPerSample,int samplesPerPixel,
int bytesPerPixel); int bytesPerPixel);
#ifdef HAVE_PTHREADS
#define rfbInitServer rfbInitServerWithPthreads
#else
#define rfbInitServer rfbInitServerWithoutPthreads
#endif
extern void rfbInitServer(rfbScreenInfoPtr rfbScreen); extern void rfbInitServer(rfbScreenInfoPtr rfbScreen);
extern void rfbScreenCleanup(rfbScreenInfoPtr screenInfo); extern void rfbScreenCleanup(rfbScreenInfoPtr screenInfo);
......
...@@ -137,6 +137,7 @@ rfbNewClientConnection(rfbScreen,sock) ...@@ -137,6 +137,7 @@ rfbNewClientConnection(rfbScreen,sock)
if(cl!=NULL) if(cl!=NULL)
newConnection(cl, (KEYBOARD_DEVICE|POINTER_DEVICE),1,1,1); newConnection(cl, (KEYBOARD_DEVICE|POINTER_DEVICE),1,1,1);
#endif #endif
FD_SET(sock,&(rfbScreen->allFds));
} }
......
...@@ -111,16 +111,18 @@ rfbInitSockets(rfbScreenInfoPtr rfbScreen) ...@@ -111,16 +111,18 @@ rfbInitSockets(rfbScreenInfoPtr rfbScreen)
return; return;
} }
rfbLog("Listening for VNC connections on TCP port %d\n", rfbScreen->rfbPort); if(rfbScreen->rfbPort>0) {
rfbLog("Listening for VNC connections on TCP port %d\n", rfbScreen->rfbPort);
if ((rfbScreen->rfbListenSock = ListenOnTCPPort(rfbScreen->rfbPort)) < 0) { if ((rfbScreen->rfbListenSock = ListenOnTCPPort(rfbScreen->rfbPort)) < 0) {
rfbLogPerror("ListenOnTCPPort"); rfbLogPerror("ListenOnTCPPort");
exit(1); exit(1);
} }
FD_ZERO(&(rfbScreen->allFds)); FD_ZERO(&(rfbScreen->allFds));
FD_SET(rfbScreen->rfbListenSock, &(rfbScreen->allFds)); FD_SET(rfbScreen->rfbListenSock, &(rfbScreen->allFds));
rfbScreen->maxFd = rfbScreen->rfbListenSock; rfbScreen->maxFd = rfbScreen->rfbListenSock;
}
if (rfbScreen->udpPort != 0) { if (rfbScreen->udpPort != 0) {
rfbLog("rfbInitSockets: listening for input on UDP port %d\n",rfbScreen->udpPort); rfbLog("rfbInitSockets: listening for input on UDP port %d\n",rfbScreen->udpPort);
...@@ -159,7 +161,6 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec) ...@@ -159,7 +161,6 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
if (!rfbScreen->inetdInitDone && rfbScreen->inetdSock != -1) { if (!rfbScreen->inetdInitDone && rfbScreen->inetdSock != -1) {
rfbNewClientConnection(rfbScreen,rfbScreen->inetdSock); rfbNewClientConnection(rfbScreen,rfbScreen->inetdSock);
rfbScreen->inetdInitDone = TRUE; rfbScreen->inetdInitDone = TRUE;
FD_SET(rfbScreen->inetdSock,&(rfbScreen->allFds));
} }
memcpy((char *)&fds, (char *)&(rfbScreen->allFds), sizeof(fd_set)); memcpy((char *)&fds, (char *)&(rfbScreen->allFds), sizeof(fd_set));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment