windows.hpp Gecode Gecode::Support /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2009 * *Lastmodified: *$Date:2009-10-1220:40:58+0200(Mon,12Oct2009)$by$Author:schulte$ *$Revision:9882$ * *ThisfileispartofGecode,thegenericconstraint *developmentenvironment: *http://www.gecode.org * *Permissionisherebygranted,freeofcharge,toanypersonobtaining *acopyofthissoftwareandassociateddocumentationfiles(the *"Software"),todealintheSoftwarewithoutrestriction,including *withoutlimitationtherightstouse,copy,modify,merge,publish, *distribute,sublicense,and/orsellcopiesoftheSoftware,andto *permitpersonstowhomtheSoftwareisfurnishedtodoso,subjectto *thefollowingconditions: * *Theabovecopyrightnoticeandthispermissionnoticeshallbe *includedinallcopiesorsubstantialportionsoftheSoftware. * *THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND, *EXPRESSORIMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOF *MERCHANTABILITY,FITNESSFORAPARTICULARPURPOSEAND *NONINFRINGEMENT.INNOEVENTSHALLTHEAUTHORSORCOPYRIGHTHOLDERSBE *LIABLEFORANYCLAIM,DAMAGESOROTHERLIABILITY,WHETHERINANACTION *OFCONTRACT,TORTOROTHERWISE,ARISINGFROM,OUTOFORINCONNECTION *WITHTHESOFTWAREORTHEUSEOROTHERDEALINGSINTHESOFTWARE. * */ namespaceGecode{namespaceSupport{ /* *Mutex */ forceinline Mutex::Mutex(void){ InitializeCriticalSection(&w_cs); } forceinlinevoid Mutex::acquire(void){ EnterCriticalSection(&w_cs); } forceinlinebool Mutex::tryacquire(void){ returnTryEnterCriticalSection(&w_cs)!=0; } forceinlinevoid Mutex::release(void){ LeaveCriticalSection(&w_cs); } forceinline Mutex::~Mutex(void){ DeleteCriticalSection(&w_cs); } /* *Event */ forceinline Event::Event(void) :w_h(CreateEvent(NULL,FALSE,FALSE,NULL)){ if(w_h==NULL) throwOperatingSystemError("Event::Event[Windows::CreateEvent]"); } forceinlinevoid Event::signal(void){ if(SetEvent(w_h)==0) throwOperatingSystemError("Event::signal[Windows::SetEvent]"); } forceinlinevoid Event::wait(void){ if(WaitForSingleObject(w_h,INFINITE)!=0) throwOperatingSystemError("Event::wait[Windows::WaitForSingleObject]"); } forceinline Event::~Event(void){ if(CloseHandle(w_h)==0) throwOperatingSystemError("Event::~Event[Windows::CloseHandle]"); } /* *Thread */ forceinlinevoid Thread::sleep(unsignedintms){ Sleep(static_cast<DWORD>(ms)); } forceinlineunsignedint Thread::npu(void){ SYSTEM_INFOsi; GetSystemInfo(&si); returnstatic_cast<unsignedint>(si.dwNumberOfProcessors); } }} //STATISTICS:support-any