1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 19:01:16 +02:00

add isInterrupted() call and replace some checkInterrupt() occurrences

This commit is contained in:
Philipp Otterbein 2025-04-11 22:34:15 +02:00 committed by Jörg Thalheim
parent db297d3dda
commit 49f757c24a
4 changed files with 24 additions and 18 deletions

View file

@ -187,11 +187,7 @@ S3Helper::FileTransferResult S3Helper::getObject(
}); });
request.SetContinueRequestHandler([](const Aws::Http::HttpRequest*) { request.SetContinueRequestHandler([](const Aws::Http::HttpRequest*) {
try { return !isInterrupted();
checkInterrupt();
return true;
} catch(...) {}
return false;
}); });
FileTransferResult res; FileTransferResult res;
@ -420,10 +416,9 @@ struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStoreConfig, public virtual
TransferStatus status = transferHandle->GetStatus(); TransferStatus status = transferHandle->GetStatus();
while (status == TransferStatus::IN_PROGRESS || status == TransferStatus::NOT_STARTED) { while (status == TransferStatus::IN_PROGRESS || status == TransferStatus::NOT_STARTED) {
try { if (!isInterrupted()) {
checkInterrupt();
context->wait(); context->wait();
} catch (...) { } else {
transferHandle->Cancel(); transferHandle->Cancel();
transferHandle->WaitUntilFinished(); transferHandle->WaitUntilFinished();
} }
@ -454,11 +449,7 @@ struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStoreConfig, public virtual
}); });
request.SetContinueRequestHandler([](const Aws::Http::HttpRequest*) { request.SetContinueRequestHandler([](const Aws::Http::HttpRequest*) {
try { return !isInterrupted();
checkInterrupt();
return true;
} catch(...) {}
return false;
}); });
request.SetContentType(mimeType); request.SetContentType(mimeType);

View file

@ -26,6 +26,11 @@ static inline bool getInterrupted();
*/ */
void setInterruptThrown(); void setInterruptThrown();
/**
* @note Does nothing on Windows
*/
static inline bool isInterrupted();
/** /**
* @note Does nothing on Windows * @note Does nothing on Windows
*/ */

View file

@ -85,17 +85,22 @@ static inline bool getInterrupted()
return unix::_isInterrupted; return unix::_isInterrupted;
} }
static inline bool isInterrupted()
{
using namespace unix;
return _isInterrupted || (interruptCheck && interruptCheck());
}
/** /**
* Throw `Interrupted` exception if the process has been interrupted. * Throw `Interrupted` exception if the process has been interrupted.
* *
* Call this in long-running loops and between slow operations to terminate * Call this in long-running loops and between slow operations to terminate
* them as needed. * them as needed.
*/ */
void inline checkInterrupt() inline void checkInterrupt()
{ {
using namespace unix; if (isInterrupted())
if (_isInterrupted || (interruptCheck && interruptCheck())) unix::_interrupted();
_interrupted();
} }
/** /**

View file

@ -22,7 +22,12 @@ inline void setInterruptThrown()
/* Do nothing for now */ /* Do nothing for now */
} }
void inline checkInterrupt() static inline bool isInterrupted()
{
/* Do nothing for now */
}
inline void checkInterrupt()
{ {
/* Do nothing for now */ /* Do nothing for now */
} }