Changeset 5027


Ignore:
Timestamp:
09/19/12 07:58:33 (5 years ago)
Author:
quintiliani
Message:

Changed syntax for the following functions: CreateSpecificSemaphore_ew(), DestroySpecificSemaphore_ew(), PostSpecificSemaphore_ew(), WaitSpecificSemaphore_ew().
Since Mac OS X does not support unnamed semaphores, declared CreateSpecificNamedSemaphore_ew() and DestroySpecificNamedSemaphore_ew(), in place of the unnamed ones.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/earthworm_complex_funcs.h

    r4990 r5027  
    5757void WaitSemPost     ( void );              /* sema_ew.c    system-dependent */ 
    5858void DestroySemaphore( void );              /* sema_ew.c    system-dependent */ 
    59 void CreateSpecificSemaphore_ew( sema_t *, unsigned int count  ); /* sema_ew.c    system-dependent */ 
    60 void PostSpecificSemaphore     ( sema_t * );              /* sema_ew.c    system-dependent */ 
    61 void WaitSpecificSemPost       ( sema_t * );              /* sema_ew.c    system-dependent */ 
    62 void DestroySpecificSemaphore  ( sema_t * );              /* sema_ew.c    system-dependent */ 
     59#ifndef _MACOSX 
     60sema_t *CreateSpecificSemaphore_ew( unsigned int count ); /* sema_ew.c    system-dependent */ 
     61void   DestroySpecificSemaphore_ew  ( sema_t * );           /* sema_ew.c    system-dependent */ 
     62#else 
     63sema_t *CreateSpecificNamedSemaphore_ew( char *sem_name, 
     64                      unsigned int count ); /* sema_ew.c    system-dependent */ 
     65void   DestroySpecificNamedSemaphore_ew( char *sem_name,  sema_t *ms ); 
     66                                            /* sema_ew.c    system-dependent */ 
     67#endif 
     68void PostSpecificSemaphore_ew  ( sema_t * );              /* sema_ew.c    system-dependent */ 
     69void WaitSpecificSemaphore_ew  ( sema_t * );              /* sema_ew.c    system-dependent */ 
     70 
    6371void CreateMutex_ew  ( void );              /* sema_ew.c    system-dependent */ 
    6472void RequestMutex( void );                  /* sema_ew.c    system-dependent */ 
  • trunk/release_notes.working

    r5010 r5027  
    239239**************** 
    240240sema_ew.c 
    241         Added the following functions: CreateSpecificSemaphore_ew(), 
    242         PostSpecificSemaphore(), WaitSpecificSemPost(), DestroySpecificSemaphore(). 
    243 Matteo Quintiliani 08/23/2012 
    244  
     241        Added the following functions: 
     242        CreateSpecificSemaphore_ew(), DestroySpecificSemaphore_ew(), 
     243        PostSpecificSemaphore_ew(), WaitSpecificSemaphore_ew(). 
     244        Since Mac OS X does not support unnamed semaphores, declared 
     245        CreateSpecificNamedSemaphore_ew() and DestroySpecificNamedSemaphore_ew(), 
     246        in place of the unnamed ones. 
     247Matteo Quintiliani 09/19/2012 
     248 
  • trunk/src/libsrc/solaris/sema_ew.c

    r4990 r5027  
    102102    Create a semaphore which is posted when some event is complete. 
    103103*********************************************************************/ 
    104 void CreateSpecificSemaphore_ew( sema_t *ms, unsigned int count ) 
     104sema_t *CreateSpecificSemaphore_ew( unsigned int count ) 
    105105{ 
    106106   void *dummy = NULL; 
    107107   int   rc; 
    108108 
     109   sema_t *ms = NULL; 
     110 
     111   /* Allocate ms */ 
     112   ms = (sema_t *) malloc(sizeof(sema_t)); 
     113   if(ms == NULL) { 
     114     fprintf( stderr, 
     115         "CreateSpecificSemaphore_ew: Error allocating sema_t; Exiting.\n"); 
     116     exit( -1 ); 
     117   } 
     118 
    109119   rc = sema_init( ms, count, USYNC_THREAD, dummy ); 
    110120   if ( rc != 0 ) 
     
    114124      exit( -1 ); 
    115125   } 
    116    return; 
    117 } 
    118  
    119 /**************************** PostSpecificSemaphore ******************** 
     126 
     127   return ms; 
     128} 
     129 
     130/**************************** PostSpecificSemaphore_ew ******************** 
    120131             Let another thread know that a message is ready. 
    121132************************************************************************/ 
    122 void PostSpecificSemaphore( sema_t *ms ) 
     133void PostSpecificSemaphore_ew( sema_t *ms ) 
    123134{ 
    124135   int rc; 
     
    127138   if ( rc != 0 ) 
    128139      fprintf( stderr, 
    129               "PostSpecificSemaphore: Error from sema_post: %d\n", rc ); 
    130    return; 
    131 } 
    132  
    133 /**************************** WaitSpecificSemPost ******************* 
     140              "PostSpecificSemaphore_ew: Error from sema_post: %d\n", rc ); 
     141   return; 
     142} 
     143 
     144/**************************** WaitSpecificSemaphore_ew ******************* 
    134145      Wait for the event semaphore to be posted by another thread. 
    135146*********************************************************************/ 
    136 void WaitSpecificSemPost( sema_t *ms ) 
     147void WaitSpecificSemaphore_ew( sema_t *ms ) 
    137148{ 
    138149   int rc; 
     
    142153   { 
    143154      fprintf( stderr, 
    144               "WaitSpecificSemPost: Error from sema_wait: %d; Exiting.\n", rc ); 
    145       exit( -1 ); 
    146    } 
    147    return; 
    148 } 
    149  
    150 /**************************** DestroySpecificSemaphore ***************** 
     155              "WaitSpecificSemaphore_ew: Error from sema_wait: %d; Exiting.\n", rc ); 
     156      exit( -1 ); 
     157   } 
     158   return; 
     159} 
     160 
     161/**************************** DestroySpecificSemaphore_ew ***************** 
    151162                         Kill the event semaphore. 
    152163************************************************************************/ 
    153 void DestroySpecificSemaphore( sema_t *ms ) 
    154 { 
    155    sema_destroy( ms ); 
    156    return; 
     164void DestroySpecificSemaphore_ew( sema_t *ms ) 
     165{ 
     166  if(ms) { 
     167 
     168    sema_destroy( ms ); 
     169 
     170    /* Deallocate ms */ 
     171    free(ms); 
     172  } 
    157173} 
    158174 
  • trunk/src/libsrc/unix/sema_ew.c

    r4990 r5027  
    105105} 
    106106 
     107#ifndef _MACOSX 
    107108/************************ CreateSpecificSemaphore_ew **************** 
    108109    Create a specific semaphore which is posted when some event is complete. 
    109110*********************************************************************/ 
    110 void CreateSpecificSemaphore_ew( sem_t *ms, unsigned int count ) 
    111 { 
    112    int   rc; 
     111sem_t *CreateSpecificSemaphore_ew( unsigned int count ) 
     112{ 
     113   int   rc; 
     114   sem_t *ms = NULL; 
    113115    
     116   /* Allocate ms */ 
     117   ms = (sem_t *) malloc(sizeof(sem_t)); 
     118   if(ms == NULL) { 
     119     fprintf( stderr, 
     120         "CreateSpecificSemaphore_ew: Error allocating sem_t; Exiting.\n"); 
     121     exit( -1 ); 
     122   } 
     123 
    114124   /* semaphore to be shared only among threads in this process */ 
    115125 
     
    122132   rc = sema_init( ms, count, USYNC_THREAD, dummy ); 
    123133#endif 
    124   
    125    if ( rc != 0 ) 
    126    { 
    127       fprintf( stderr, 
    128               "CreateSpecificMutex: Error from sem_init: %d: %s; Exiting.\n", rc, strerror(errno) ); 
    129       exit( -1 ); 
    130    } 
    131    return; 
    132 } 
    133  
    134 /**************************** PostSpecificSemaphore ******************** 
     134 
     135   if ( rc != 0 ) 
     136   { 
     137      fprintf( stderr, 
     138              "CreateSpecificSemaphore_ew: Error from sem_init: %d: %s; Exiting.\n", rc, strerror(errno) ); 
     139      exit( -1 ); 
     140   } 
     141 
     142   return ms; 
     143} 
     144 
     145/**************************** DestroySpecificSemaphore_ew ***************** 
     146                         Kill the event semaphore. 
     147************************************************************************/ 
     148void DestroySpecificSemaphore_ew( sem_t *ms ) 
     149{ 
     150    int rc; 
     151 
     152    if(ms) 
     153    { 
     154        rc = sem_destroy( ms ); 
     155        if ( rc != 0 ) 
     156        { 
     157            fprintf( stderr, 
     158                    "DestroySpecificSemaphore_ew: Error from sem_destroy: %d: %s\n", rc, strerror(errno) ); 
     159 
     160        } else { 
     161            free(ms); 
     162        } 
     163    } 
     164 
     165} 
     166 
     167#else 
     168 
     169/************************ CreateSpecificNamedSemaphore_ew ************ 
     170    Create a specific semaphore which is posted when some event is complete. 
     171    N.B. OSX does not support unnamed semaphores. To use named semaphores 
     172    instead of unnamed semaphores, use sem_open instead of sem_init, and use 
     173    sem_close and sem_unlink instead of sem_destroy. 
     174*********************************************************************/ 
     175sem_t *CreateSpecificNamedSemaphore_ew( char *sem_name, unsigned int count ) 
     176{ 
     177   int rc; 
     178   sem_t *ms = NULL; 
     179 
     180   int mode = 0644; 
     181 
     182   /* delete if it already exists */ 
     183   rc = sem_unlink( sem_name ); 
     184   /* 
     185   if ( rc != 0 && errno != ENOENT) { 
     186     fprintf( stderr, 
     187         "CreateSpecificNamedSemaphore_ew: Error from sem_unlink: %d: %s (%d)\n", rc, strerror(errno), errno ); 
     188   } 
     189   */ 
     190 
     191   ms = sem_open(sem_name, O_CREAT, mode, count); 
     192 
     193   if(ms == (sem_t *) SEM_FAILED || ms == NULL) { 
     194     fprintf( stderr, 
     195         "CreateSpecificNamedSemaphore_ew: Error from sem_open: %s; Exiting.\n", strerror(errno)); 
     196     exit( -1 ); 
     197   }; 
     198 
     199   return ms; 
     200} 
     201 
     202/**************************** DestroySpecificNamedSemaphore_ew ************ 
     203                         Kill the event semaphore. 
     204************************************************************************/ 
     205void DestroySpecificNamedSemaphore_ew( char *sem_name,  sem_t *ms ) 
     206{ 
     207   int rc; 
     208 
     209   rc = sem_close( ms ); 
     210   if ( rc != 0 ) 
     211      fprintf( stderr, 
     212              "DestroySpecificNamedSemaphore_ew: Error from sem_close: %d: %s\n", rc, strerror(errno) ); 
     213   rc = sem_unlink( sem_name ); 
     214   if ( rc != 0 ) 
     215      fprintf( stderr, 
     216              "DestroySpecificNamedSemaphore_ew: Error from sem_unlink: %d: %s\n", rc, strerror(errno) ); 
     217 
     218} 
     219 
     220 
     221#endif 
     222 
     223/**************************** PostSpecificSemaphore_ew ******************** 
    135224             Let another thread know that a message is ready. 
    136225************************************************************************/ 
    137 void PostSpecificSemaphore( sem_t *ms ) 
     226void PostSpecificSemaphore_ew( sem_t *ms ) 
    138227{ 
    139228   int rc; 
     
    142231   if ( rc != 0 ) 
    143232      fprintf( stderr, 
    144               "PostSpecificSemaphore: Error from sem_post: %d: %s\n", rc, strerror(errno) ); 
    145    return; 
    146 } 
    147  
    148 /**************************** WaitSpecificSemPost ******************* 
     233              "PostSpecificSemaphore_ew: Error from sem_post: %d: %s\n", rc, strerror(errno) ); 
     234   return; 
     235} 
     236 
     237/**************************** WaitSpecificSemaphore_ew ******************* 
    149238      Wait for the event semaphore to be posted by another thread. 
    150239*********************************************************************/ 
    151 void WaitSpecificSemPost( sem_t *ms ) 
     240void WaitSpecificSemaphore_ew( sem_t *ms ) 
    152241{ 
    153242   int rc; 
     
    157246   { 
    158247      fprintf( stderr, 
    159               "WaitSpecificSemPost: Error from sem_wait: %d: %s; Exiting.\n", rc, strerror(errno) ); 
    160       exit( -1 ); 
    161    } 
    162    return; 
    163 } 
    164  
    165 /**************************** DestroySpecificSemaphore ***************** 
    166                          Kill the event semaphore. 
    167 ************************************************************************/ 
    168 void DestroySpecificSemaphore( sem_t *ms ) 
    169 { 
    170    int rc; 
    171  
    172    rc = sem_destroy( ms ); 
    173    if ( rc != 0 ) 
    174       fprintf( stderr, 
    175               "DestroySpecificSemaphore: Error from sem_destroy: %d: %s\n", rc, strerror(errno) ); 
     248              "WaitSpecificSemaphore_ew: Error from sem_wait: %d: %s; Exiting.\n", rc, strerror(errno) ); 
     249      exit( -1 ); 
     250   } 
    176251   return; 
    177252} 
     
    352427   { 
    353428      fprintf( stderr, 
    354               "RequestSpecificMutex: Error from pthread_mutex_lock: %d:%x %s; Exiting.\n", 
     429              "RequestSpecificMutex: Error from pthread_mutex_lock: %d:%p %s; Exiting.\n", 
    355430               rc,mp, strerror(errno) ); 
    356431      exit( -1 ); 
  • trunk/src/libsrc/winnt/sema_ew.c

    r4990 r5027  
    186186 *******************************************************************/ 
    187187 
    188 void CreateSpecificSemaphore_ew( HANDLE *ms, unsigned int count ) 
     188HANDLE *CreateSpecificSemaphore_ew( unsigned int count ) 
    189189{ 
    190190   LONG InitialCount = count;                  /* Initially set */ 
    191191   const LONG MaxCount     = 1000000000;       /* One billion */ 
    192  
    193    *ms = CreateSemaphore( NULL, count, MaxCount, NULL ); 
    194    if ( *ms == NULL ) 
     192   HANDLE ms; 
     193 
     194   ms = CreateSemaphore( NULL, count, MaxCount, NULL ); 
     195   if ( ms == NULL ) 
    195196   { 
    196197      logit( "et", "CreateSpecificSemaphore_ew() error: %d  Exiting.\n", 
     
    198199      exit( -1 ); 
    199200   } 
    200    return; 
    201 } 
    202  
    203  
    204 /*************************** PostSpecificSemaphore ***************** 
     201 
     202   return ms; 
     203} 
     204 
     205 
     206/*************************** PostSpecificSemaphore_ew ***************** 
    205207 *                        Post the semaphore.                      * 
    206208 *  The semaphore counter is incremented.                          * 
    207209 *******************************************************************/ 
    208210 
    209 void PostSpecificSemaphore( HANDLE *ms ) 
     211void PostSpecificSemaphore_ew( HANDLE *ms ) 
    210212{ 
    211213   if ( ReleaseSemaphore( *ms, 1, NULL ) == FALSE ) 
    212       logit( "et", "PostSpecificSemaphore() error: %d\n", GetLastError() ); 
     214      logit( "et", "PostSpecificSemaphore_ew() error: %d\n", GetLastError() ); 
    213215   return; 
    214216} 
     
    219221 ****************************************************************/ 
    220222 
    221 void WaitSpecificSemPost( HANDLE *ms ) 
     223void WaitSpecificSemaphore_ew( HANDLE *ms ) 
    222224{ 
    223225   if ( WaitForSingleObject( *ms, INFINITE ) == WAIT_FAILED ) 
    224       logit( "et", "WaitSpecificSemPost() error: %d\n", GetLastError() ); 
    225    return; 
    226 } 
    227  
    228  
    229 /************************* DestroySpecificSemaphore ************* 
     226      logit( "et", "WaitSpecificSemaphore_ew() error: %d\n", GetLastError() ); 
     227   return; 
     228} 
     229 
     230 
     231/************************* DestroySpecificSemaphore_ew ************* 
    230232 *                        Kill the semaphore.                   * 
    231233 ****************************************************************/ 
    232234 
    233 void DestroySpecificSemaphore( HANDLE *ms ) 
     235void DestroySpecificSemaphore_ew( HANDLE *ms ) 
    234236{ 
    235237   CloseHandle( *ms ); 
Note: See TracChangeset for help on using the changeset viewer.