src/thread/os2/SDL_sysmutex.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
    35     HMTX hmtxID;
    35     HMTX hmtxID;
    36 };
    36 };
    37 
    37 
    38 /* Create a mutex */
    38 /* Create a mutex */
    39 DECLSPEC SDL_mutex *SDLCALL
    39 DECLSPEC SDL_mutex *SDLCALL
    40 SDL_CreateMutex (void)
    40 SDL_CreateMutex(void)
    41 {
    41 {
    42     SDL_mutex *mutex;
    42     SDL_mutex *mutex;
    43     APIRET ulrc;
    43     APIRET ulrc;
    44 
    44 
    45     /* Allocate mutex memory */
    45     /* Allocate mutex memory */
    46     mutex = (SDL_mutex *) SDL_malloc (sizeof (*mutex));
    46     mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex));
    47     if (mutex) {
    47     if (mutex) {
    48         /* Create the mutex, with initial value signaled */
    48         /* Create the mutex, with initial value signaled */
    49         ulrc = DosCreateMutexSem (NULL, // Create unnamed semaphore
    49         ulrc = DosCreateMutexSem(NULL,  // Create unnamed semaphore
    50                                   &(mutex->hmtxID),     // Pointer to handle
    50                                  &(mutex->hmtxID),      // Pointer to handle
    51                                   0L,   // Flags: create it private (not shared)
    51                                  0L,    // Flags: create it private (not shared)
    52                                   FALSE);       // Initial value: unowned
    52                                  FALSE);        // Initial value: unowned
    53         if (ulrc != NO_ERROR) {
    53         if (ulrc != NO_ERROR) {
    54             SDL_SetError ("Couldn't create mutex");
    54             SDL_SetError("Couldn't create mutex");
    55             SDL_free (mutex);
    55             SDL_free(mutex);
    56             mutex = NULL;
    56             mutex = NULL;
    57         }
    57         }
    58     } else {
    58     } else {
    59         SDL_OutOfMemory ();
    59         SDL_OutOfMemory();
    60     }
    60     }
    61     return (mutex);
    61     return (mutex);
    62 }
    62 }
    63 
    63 
    64 /* Free the mutex */
    64 /* Free the mutex */
    65 DECLSPEC void SDLCALL
    65 DECLSPEC void SDLCALL
    66 SDL_DestroyMutex (SDL_mutex * mutex)
    66 SDL_DestroyMutex(SDL_mutex * mutex)
    67 {
    67 {
    68     if (mutex) {
    68     if (mutex) {
    69         if (mutex->hmtxID) {
    69         if (mutex->hmtxID) {
    70             DosCloseMutexSem (mutex->hmtxID);
    70             DosCloseMutexSem(mutex->hmtxID);
    71             mutex->hmtxID = 0;
    71             mutex->hmtxID = 0;
    72         }
    72         }
    73         SDL_free (mutex);
    73         SDL_free(mutex);
    74     }
    74     }
    75 }
    75 }
    76 
    76 
    77 /* Lock the mutex */
    77 /* Lock the mutex */
    78 DECLSPEC int SDLCALL
    78 DECLSPEC int SDLCALL
    79 SDL_mutexP (SDL_mutex * mutex)
    79 SDL_mutexP(SDL_mutex * mutex)
    80 {
    80 {
    81     if (mutex == NULL) {
    81     if (mutex == NULL) {
    82         SDL_SetError ("Passed a NULL mutex");
    82         SDL_SetError("Passed a NULL mutex");
    83         return -1;
    83         return -1;
    84     }
    84     }
    85     if (DosRequestMutexSem (mutex->hmtxID, SEM_INDEFINITE_WAIT) != NO_ERROR) {
    85     if (DosRequestMutexSem(mutex->hmtxID, SEM_INDEFINITE_WAIT) != NO_ERROR) {
    86         SDL_SetError ("Couldn't wait on mutex");
    86         SDL_SetError("Couldn't wait on mutex");
    87         return -1;
    87         return -1;
    88     }
    88     }
    89     return (0);
    89     return (0);
    90 }
    90 }
    91 
    91 
    92 /* Unlock the mutex */
    92 /* Unlock the mutex */
    93 DECLSPEC int SDLCALL
    93 DECLSPEC int SDLCALL
    94 SDL_mutexV (SDL_mutex * mutex)
    94 SDL_mutexV(SDL_mutex * mutex)
    95 {
    95 {
    96     if (mutex == NULL) {
    96     if (mutex == NULL) {
    97         SDL_SetError ("Passed a NULL mutex");
    97         SDL_SetError("Passed a NULL mutex");
    98         return -1;
    98         return -1;
    99     }
    99     }
   100     if (DosReleaseMutexSem (mutex->hmtxID) != NO_ERROR) {
   100     if (DosReleaseMutexSem(mutex->hmtxID) != NO_ERROR) {
   101         SDL_SetError ("Couldn't release mutex");
   101         SDL_SetError("Couldn't release mutex");
   102         return -1;
   102         return -1;
   103     }
   103     }
   104     return (0);
   104     return (0);
   105 }
   105 }
   106 
   106