<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>Sounds good. Lets get started by nailing down the C API and semantics for this first.</div><div><br></div><div>I mirrored the C API for the LLVM context diagnostic handler and used Andy’s suggested name for the callback.</div><div>The opaque handle was suggested by Duncan and can provide optional user specified information that is</div><div>provided back during the callback (i.e. barrier, etc).</div><div><br></div><div>Cheers,</div><div>Juergen </div><div><br></div><div><div><font face="Menlo">Core.h:</font></div><font face="Menlo">typedef void (*LLVMMaySuspendCallback)(LLVMContextRef, void *);</font><div><font face="Menlo"><br></font></div><div><font face="Menlo">/**</font></div><div><font face="Menlo"> * Set the may-suspend callback function for this context.<br> *<br> * @see LLVMContext::setMaySuspendCallback()<br> */<br>void LLVMContextSetMaySuspendCallback(LLVMContextRef C,<br> LLVMMaySuspendCallback Callback,<br> void *OpaqueHandle);</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">LLVMContext.h:</font></div><div><font face="Menlo">/// \brief Registers a may-suspend callback with the context.<br>///<br>/// The may-suspend callback function may be called by LLVM to transfer<br>/// control back to the client that invoked the LLVM compilation. The client<br>/// is not garantueed to ever receive this callback. It is at the sole<br>/// discretion of LLVM to do so and only if it can guarantee that suspending<br>/// the thread won't block any forward progress in other LLVM contexts.<br>void setMaySuspendCallback(MaySuspendCallbackTy Callback, void *OpaqueHandle);<br><br>/// \brief Calls the may-suspend callback (if applicable).<br>///<br>/// This transfers control back to the client, which may suspend the current<br>/// thread. Only call this method when LLVM doesn't hold any global mutex or<br>/// cannot block the execution in another LLVM context.<br>void callMaySuspendCallback();</font></div></div><div><div><br><div><div>On May 12, 2014, at 5:26 PM, Nick Lewycky <<a href="mailto:nlewycky@google.com">nlewycky@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><blockquote class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto;"><div style="word-wrap: break-word;">Would you (or anyone) oppose a simple maySuspendContext() callback API? It would mean nothing more than the thread(s) for a given LLVM context can be suspended independent from other contexts.</div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">I think this is the right approach. So a given thread hits a safe point, it optionally calls a "suspend check" or "i an safe to suspend right now" callback if set. It doesn't stop other threads, it doesn't continue until the function returns.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">If you want to stop all threads then the user callback may contain a barrier and count down how many threads have stopped until it sees all of them.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Nick</div></blockquote></div><br></div></div></body></html>