comparison gtk/dw.c @ 1107:884951ef2e7f

Fixed some warnings on recent versions of Linux/gcc regarding return values. Also switched to using the DW_ERROR_ constants instead of raw values.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 26 Jul 2011 09:39:36 +0000
parents 84473658ce37
children 36773e04245c
comparison
equal deleted inserted replaced
1106:eb6b27d17fe7 1107:884951ef2e7f
8642 8642
8643 while(1) 8643 while(1)
8644 { 8644 {
8645 FD_ZERO(&rd); 8645 FD_ZERO(&rd);
8646 FD_SET(listenfd, &rd); 8646 FD_SET(listenfd, &rd);
8647 int result;
8647 8648
8648 maxfd = listenfd; 8649 maxfd = listenfd;
8649 8650
8650 /* Added any connections to the named event semaphore */ 8651 /* Added any connections to the named event semaphore */
8651 for(z=0;z<connectcount;z++) 8652 for(z=0;z<connectcount;z++)
8729 /* The semaphore has been posted so 8730 /* The semaphore has been posted so
8730 * we tell all the waiting threads to 8731 * we tell all the waiting threads to
8731 * continue. 8732 * continue.
8732 */ 8733 */
8733 if(array[s].waiting) 8734 if(array[s].waiting)
8734 write(array[s].fd, &tmp, 1); 8735 result = write(array[s].fd, &tmp, 1);
8735 } 8736 }
8736 } 8737 }
8737 break; 8738 break;
8738 case 2: 8739 case 2:
8739 /* Wait */ 8740 /* Wait */
8742 8743
8743 array[z].waiting = 1; 8744 array[z].waiting = 1;
8744 8745
8745 /* If we are posted exit immeditately */ 8746 /* If we are posted exit immeditately */
8746 if(posted) 8747 if(posted)
8747 write(array[z].fd, &tmp, 1); 8748 result = write(array[z].fd, &tmp, 1);
8748 } 8749 }
8749 break; 8750 break;
8750 case 3: 8751 case 3:
8751 { 8752 {
8752 /* Done Waiting */ 8753 /* Done Waiting */
8845 { 8846 {
8846 /* signal reset */ 8847 /* signal reset */
8847 char tmp = (char)0; 8848 char tmp = (char)0;
8848 8849
8849 if(GPOINTER_TO_INT(eve) < 0) 8850 if(GPOINTER_TO_INT(eve) < 0)
8850 return 0; 8851 return DW_ERROR_NONE;
8851 8852
8852 if(write(GPOINTER_TO_INT(eve), &tmp, 1) == 1) 8853 if(write(GPOINTER_TO_INT(eve), &tmp, 1) == 1)
8853 return 0; 8854 return DW_ERROR_NONE;
8854 return 1; 8855 return DW_ERROR_GENERAL;
8855 } 8856 }
8856 8857
8857 /* Sets the posted state of an event semaphore, any threads 8858 /* Sets the posted state of an event semaphore, any threads
8858 * waiting on the semaphore will no longer block. 8859 * waiting on the semaphore will no longer block.
8859 * Parameters: 8860 * Parameters:
8865 8866
8866 /* signal post */ 8867 /* signal post */
8867 char tmp = (char)1; 8868 char tmp = (char)1;
8868 8869
8869 if(GPOINTER_TO_INT(eve) < 0) 8870 if(GPOINTER_TO_INT(eve) < 0)
8870 return 0; 8871 return DW_ERROR_NONE;
8871 8872
8872 if(write(GPOINTER_TO_INT(eve), &tmp, 1) == 1) 8873 if(write(GPOINTER_TO_INT(eve), &tmp, 1) == 1)
8873 return 0; 8874 return DW_ERROR_NONE;
8874 return 1; 8875 return DW_ERROR_GENERAL;
8875 } 8876 }
8876 8877
8877 /* Waits on the specified semaphore until it becomes 8878 /* Waits on the specified semaphore until it becomes
8878 * posted, or returns immediately if it already is posted. 8879 * posted, or returns immediately if it already is posted.
8879 * Parameters: 8880 * Parameters:
8906 FD_ZERO(&rd); 8907 FD_ZERO(&rd);
8907 FD_SET(GPOINTER_TO_INT(eve), &rd); 8908 FD_SET(GPOINTER_TO_INT(eve), &rd);
8908 8909
8909 /* Signal wait */ 8910 /* Signal wait */
8910 tmp = (char)2; 8911 tmp = (char)2;
8911 write(GPOINTER_TO_INT(eve), &tmp, 1); 8912 retval = write(GPOINTER_TO_INT(eve), &tmp, 1);
8912 8913
8913 retval = select(GPOINTER_TO_INT(eve)+1, &rd, NULL, NULL, useme); 8914 if(retval == 1)
8915 retval = select(GPOINTER_TO_INT(eve)+1, &rd, NULL, NULL, useme);
8914 8916
8915 /* Signal done waiting. */ 8917 /* Signal done waiting. */
8916 tmp = (char)3; 8918 tmp = (char)3;
8917 write(GPOINTER_TO_INT(eve), &tmp, 1); 8919 if(retval == 1)
8920 retval = write(GPOINTER_TO_INT(eve), &tmp, 1);
8918 8921
8919 if(retval == 0) 8922 if(retval == 0)
8920 return DW_ERROR_TIMEOUT; 8923 return DW_ERROR_TIMEOUT;
8921 else if(retval == -1) 8924 else if(retval == -1)
8922 return DW_ERROR_INTERRUPT; 8925 return DW_ERROR_INTERRUPT;
8923 8926
8924 /* Clear the entry from the pipe so 8927 /* Clear the entry from the pipe so
8925 * we don't loop endlessly. :) 8928 * we don't loop endlessly. :)
8926 */ 8929 */
8927 read(GPOINTER_TO_INT(eve), &tmp, 1); 8930 if(read(GPOINTER_TO_INT(eve), &tmp, 1) == 1)
8928 return 0; 8931 return DW_ERROR_NONE;
8932 return DW_ERROR_GENERAL;
8929 } 8933 }
8930 8934
8931 /* Release this semaphore, if there are no more open 8935 /* Release this semaphore, if there are no more open
8932 * handles on this semaphore the semaphore will be destroyed. 8936 * handles on this semaphore the semaphore will be destroyed.
8933 * Parameters: 8937 * Parameters:
8938 { 8942 {
8939 /* Finally close the domain socket, 8943 /* Finally close the domain socket,
8940 * cleanup will continue in _handle_sem. 8944 * cleanup will continue in _handle_sem.
8941 */ 8945 */
8942 close(GPOINTER_TO_INT(eve)); 8946 close(GPOINTER_TO_INT(eve));
8943 return 0; 8947 return DW_ERROR_NONE;
8944 } 8948 }
8945 8949
8946 /* 8950 /*
8947 * Setup thread independent color sets. 8951 * Setup thread independent color sets.
8948 */ 8952 */
8987 { 8991 {
8988 free(handle); 8992 free(handle);
8989 return NULL; 8993 return NULL;
8990 } 8994 }
8991 8995
8992 ftruncate(handle->fd, size); 8996 if(ftruncate(handle->fd, size))
8997 {
8998 close(handle->fd);
8999 free(handle);
9000 return NULL;
9001 }
8993 9002
8994 /* attach the shared memory segment to our process's address space. */ 9003 /* attach the shared memory segment to our process's address space. */
8995 *dest = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, handle->fd, 0); 9004 *dest = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, handle->fd, 0);
8996 9005
8997 if(*dest == MAP_FAILED) 9006 if(*dest == MAP_FAILED)