-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better signals interface #10401
Merged
Merged
Better signals interface #10401
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#pragma once | ||
///@file | ||
|
||
#include "types.hh" | ||
#include "error.hh" | ||
#include "logging.hh" | ||
|
||
#include <functional> | ||
|
||
namespace nix { | ||
|
||
/* User interruption. */ | ||
|
||
/** | ||
* @note Does nothing on Windows | ||
*/ | ||
static inline void setInterrupted(bool isInterrupted); | ||
|
||
/** | ||
* @note Does nothing on Windows | ||
*/ | ||
static inline bool getInterrupted(); | ||
|
||
/** | ||
* @note Does nothing on Windows | ||
*/ | ||
static inline void setInterruptCheck(std::function<bool()> interruptCheck); | ||
|
||
/** | ||
* @note Does nothing on Windows | ||
*/ | ||
void setInterruptThrown(); | ||
|
||
/** | ||
* @note Does nothing on Windows | ||
*/ | ||
inline void checkInterrupt(); | ||
|
||
/** | ||
* @note Never will happen on Windows | ||
*/ | ||
MakeError(Interrupted, BaseError); | ||
|
||
|
||
struct InterruptCallback | ||
{ | ||
virtual ~InterruptCallback() { }; | ||
}; | ||
|
||
/** | ||
* Register a function that gets called on SIGINT (in a non-signal | ||
* context). | ||
* | ||
* @note Does nothing on Windows | ||
*/ | ||
std::unique_ptr<InterruptCallback> createInterruptCallback( | ||
std::function<void()> callback); | ||
|
||
/** | ||
* A RAII class that causes the current thread to receive SIGUSR1 when | ||
* the signal handler thread receives SIGINT. That is, this allows | ||
* SIGINT to be multiplexed to multiple threads. | ||
* | ||
* @note Does nothing on Windows | ||
*/ | ||
struct ReceiveInterrupts; | ||
|
||
} | ||
|
||
#include "signals-impl.hh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
#pragma once | ||
///@file | ||
/** | ||
* @file | ||
* | ||
* Implementation of some inline definitions for Unix signals, and also | ||
* some extra Unix-only interfaces. | ||
* | ||
* (The only reason everything about signals isn't Unix-only is some | ||
* no-op definitions are provided on Windows to avoid excess CPP in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not present in this PR, that's coming later? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
* downstream code.) | ||
*/ | ||
|
||
#include "types.hh" | ||
#include "error.hh" | ||
|
@@ -24,22 +33,20 @@ namespace nix { | |
|
||
/* User interruption. */ | ||
|
||
namespace unix { | ||
|
||
extern std::atomic<bool> _isInterrupted; | ||
|
||
extern thread_local std::function<bool()> interruptCheck; | ||
|
||
void setInterruptThrown(); | ||
|
||
void _interrupted(); | ||
|
||
void inline checkInterrupt() | ||
{ | ||
if (_isInterrupted || (interruptCheck && interruptCheck())) | ||
_interrupted(); | ||
} | ||
|
||
MakeError(Interrupted, BaseError); | ||
|
||
/** | ||
* Sets the signal mask. Like saveSignalMask() but for a signal set that doesn't | ||
* necessarily match the current thread's mask. | ||
* See saveSignalMask() to set the saved mask to the current mask. | ||
*/ | ||
void setChildSignalMask(sigset_t *sigs); | ||
|
||
/** | ||
* Start a thread that handles various signals. Also block those signals | ||
|
@@ -63,26 +70,26 @@ void saveSignalMask(); | |
*/ | ||
void restoreSignals(); | ||
|
||
/** | ||
* Sets the signal mask. Like saveSignalMask() but for a signal set that doesn't | ||
* necessarily match the current thread's mask. | ||
* See saveSignalMask() to set the saved mask to the current mask. | ||
*/ | ||
void setChildSignalMask(sigset_t *sigs); | ||
void triggerInterrupt(); | ||
|
||
struct InterruptCallback | ||
} | ||
|
||
static inline void setInterrupted(bool isInterrupted) | ||
{ | ||
virtual ~InterruptCallback() { }; | ||
}; | ||
unix::_isInterrupted = isInterrupted; | ||
} | ||
|
||
/** | ||
* Register a function that gets called on SIGINT (in a non-signal | ||
* context). | ||
*/ | ||
std::unique_ptr<InterruptCallback> createInterruptCallback( | ||
std::function<void()> callback); | ||
static inline bool getInterrupted() | ||
{ | ||
return unix::_isInterrupted; | ||
} | ||
|
||
void triggerInterrupt(); | ||
void inline checkInterrupt() | ||
{ | ||
using namespace unix; | ||
if (_isInterrupted || (interruptCheck && interruptCheck())) | ||
_interrupted(); | ||
} | ||
|
||
/** | ||
* A RAII class that causes the current thread to receive SIGUSR1 when | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GCC says
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in #10411.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, sorry about that!