windows.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 namespace Gecode { namespace Support {
00039
00040
00041
00042
00043 forceinline
00044 Mutex::Mutex(void) {
00045 InitializeCriticalSection(&w_cs);
00046 }
00047 forceinline void
00048 Mutex::acquire(void) {
00049 EnterCriticalSection(&w_cs);
00050 }
00051 forceinline bool
00052 Mutex::tryacquire(void) {
00053 return TryEnterCriticalSection(&w_cs) != 0;
00054 }
00055 forceinline void
00056 Mutex::release(void) {
00057 LeaveCriticalSection(&w_cs);
00058 }
00059 forceinline
00060 Mutex::~Mutex(void) {
00061 DeleteCriticalSection(&w_cs);
00062 }
00063
00064
00065
00066
00067
00068 forceinline
00069 Event::Event(void)
00070 : w_h(CreateEvent(NULL, FALSE, FALSE, NULL)) {
00071 if (w_h == NULL)
00072 throw OperatingSystemError("Event::Event[Windows::CreateEvent]");
00073 }
00074 forceinline void
00075 Event::signal(void) {
00076 if (SetEvent(w_h) == 0)
00077 throw OperatingSystemError("Event::signal[Windows::SetEvent]");
00078 }
00079 forceinline void
00080 Event::wait(void) {
00081 if (WaitForSingleObject(w_h,INFINITE) != 0)
00082 throw OperatingSystemError("Event::wait[Windows::WaitForSingleObject]");
00083 }
00084 forceinline
00085 Event::~Event(void) {
00086 if (CloseHandle(w_h) == 0) {
00087 std::cerr << "Operating system error: "
00088 << "Event::~Event[Windows::CloseHandle]";
00089 std::terminate();
00090 }
00091 }
00092
00093
00094
00095
00096
00097 forceinline void
00098 Thread::sleep(unsigned int ms) {
00099 Sleep(static_cast<DWORD>(ms));
00100 }
00101
00102 forceinline unsigned int
00103 Thread::npu(void) {
00104 SYSTEM_INFO si;
00105 GetSystemInfo(&si);
00106 return static_cast<unsigned int>(si.dwNumberOfProcessors);
00107 }
00108
00109 }}
00110
00111