thread.hpp /usr/include/gecode/support.hh Gecode Gecode::Support /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2009 * *Lastmodified: *$Date:2013-07-0106:38:48+0200(Mon,01Jul2013)$by$Author:tack$ *$Revision:13740$ * *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{ /* *Runnableobjects */ forceinlinevoid Runnable::operatordelete(void*p){ heap.rfree(p); } forceinlinevoid* Runnable::operatornew(size_ts){ returnheap.ralloc(s); } /* *Mutexes * */ forceinlinevoid* Mutex::operatornew(size_ts){ returnGecode::heap.ralloc(s); } forceinlinevoid Mutex::operatordelete(void*p){ Gecode::heap.rfree(p); } #ifdefined(GECODE_THREADS_OSX)||defined(GECODE_THREADS_PTHREADS_SPINLOCK) /* *Fastmutexes * */ forceinlinevoid* FastMutex::operatornew(size_ts){ returnGecode::heap.ralloc(s); } forceinlinevoid FastMutex::operatordelete(void*p){ Gecode::heap.rfree(p); } #endif /* *Locks */ forceinline Lock::Lock(Mutex&m0):m(m0){ m.acquire(); } forceinline Lock::~Lock(void){ m.release(); } /* *Threads */ inlinevoid Thread::Run::run(Runnable*r0){ m.acquire(); r=r0; m.release(); e.signal(); } inlinevoid Thread::run(Runnable*r){ m()->acquire(); if(idle!=NULL){ Run*i=idle; idle=idle->n; m()->release(); i->run(r); }else{ m()->release(); (void)newRun(r); } } forceinlinevoid Thread::Run::operatordelete(void*p){ heap.rfree(p); } forceinlinevoid* Thread::Run::operatornew(size_ts){ returnheap.ralloc(s); } }} //STATISTICS:support-any