src/thread/stdcpp/SDL_syscond.cpp
changeset 8484 7258989352eb
parent 8360 7f1bc00e59fc
child 8600 092802455aed
     1.1 --- a/src/thread/stdcpp/SDL_syscond.cpp	Tue Aug 20 21:22:32 2013 -0400
     1.2 +++ b/src/thread/stdcpp/SDL_syscond.cpp	Tue Aug 20 21:54:34 2013 -0400
     1.3 @@ -26,8 +26,8 @@
     1.4  
     1.5  #include <chrono>
     1.6  #include <condition_variable>
     1.7 -#include <exception>
     1.8  #include <ratio>
     1.9 +#include <system_error>
    1.10  
    1.11  #include "SDL_sysmutex_c.h"
    1.12  
    1.13 @@ -45,11 +45,11 @@
    1.14      try {
    1.15          SDL_cond * cond = new SDL_cond;
    1.16          return cond;
    1.17 -    } catch (std::exception & ex) {
    1.18 -        SDL_SetError("unable to create C++ condition variable: %s", ex.what());
    1.19 +    } catch (std::system_error & ex) {
    1.20 +        SDL_SetError("unable to create a C++ condition variable: code=%d; %s", ex.code(), ex.what());
    1.21          return NULL;
    1.22 -    } catch (...) {
    1.23 -        SDL_SetError("unable to create C++ condition variable due to an unknown exception");
    1.24 +    } catch (std::bad_alloc &) {
    1.25 +        SDL_OutOfMemory();
    1.26          return NULL;
    1.27      }
    1.28  }
    1.29 @@ -60,11 +60,7 @@
    1.30  SDL_DestroyCond(SDL_cond * cond)
    1.31  {
    1.32      if (cond) {
    1.33 -        try {
    1.34 -            delete cond;
    1.35 -        } catch (...) {
    1.36 -            // catch any and all exceptions, just in case something happens
    1.37 -        }
    1.38 +        delete cond;
    1.39      }
    1.40  }
    1.41  
    1.42 @@ -78,14 +74,8 @@
    1.43          return -1;
    1.44      }
    1.45  
    1.46 -    try {
    1.47 -        cond->cpp_cond.notify_one();
    1.48 -        return 0;
    1.49 -    } catch (...) {
    1.50 -        // catch any and all exceptions, just in case something happens
    1.51 -        SDL_SetError("unable to signal C++ condition variable due to an unknown exception");
    1.52 -        return -1;
    1.53 -    }
    1.54 +    cond->cpp_cond.notify_one();
    1.55 +    return 0;
    1.56  }
    1.57  
    1.58  /* Restart all threads that are waiting on the condition variable */
    1.59 @@ -98,14 +88,8 @@
    1.60          return -1;
    1.61      }
    1.62  
    1.63 -    try {
    1.64 -        cond->cpp_cond.notify_all();
    1.65 -        return 0;
    1.66 -    } catch (...) {
    1.67 -        // catch any and all exceptions, just in case something happens
    1.68 -        SDL_SetError("unable to broadcast C++ condition variable due to an unknown exception");
    1.69 -        return -1;
    1.70 -    }
    1.71 +    cond->cpp_cond.notify_all();
    1.72 +    return 0;
    1.73  }
    1.74  
    1.75  /* Wait on the condition variable for at most 'ms' milliseconds.
    1.76 @@ -163,11 +147,8 @@
    1.77                  return 0;
    1.78              }
    1.79          }
    1.80 -    } catch (std::exception & ex) {
    1.81 -        SDL_SetError("unable to wait on C++ condition variable: %s", ex.what());
    1.82 -        return -1;
    1.83 -    } catch (...) {
    1.84 -        SDL_SetError("unable to lock wait on C++ condition variable due to an unknown exception");
    1.85 +    } catch (std::system_error & ex) {
    1.86 +        SDL_SetError("unable to wait on a C++ condition variable: code=%d; %s", ex.code(), ex.what());
    1.87          return -1;
    1.88      }
    1.89  }