172cbf62fSWill Gardner/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
272cbf62fSWill Gardner/*
372cbf62fSWill Gardner *     Copyright 2018 Couchbase, Inc
472cbf62fSWill Gardner *
572cbf62fSWill Gardner *   Licensed under the Apache License, Version 2.0 (the "License");
672cbf62fSWill Gardner *   you may not use this file except in compliance with the License.
772cbf62fSWill Gardner *   You may obtain a copy of the License at
872cbf62fSWill Gardner *
972cbf62fSWill Gardner *       http://www.apache.org/licenses/LICENSE-2.0
1072cbf62fSWill Gardner *
1172cbf62fSWill Gardner *   Unless required by applicable law or agreed to in writing, software
1272cbf62fSWill Gardner *   distributed under the License is distributed on an "AS IS" BASIS,
1372cbf62fSWill Gardner *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1472cbf62fSWill Gardner *   See the License for the specific language governing permissions and
1572cbf62fSWill Gardner *   limitations under the License.
1672cbf62fSWill Gardner */
1772cbf62fSWill Gardner
1872cbf62fSWill Gardner/**
1972cbf62fSWill Gardner * This program/test is designed to block waiting for a ctrl+c signal. If the
2072cbf62fSWill Gardner * signal handler has been setup properly then program should return 0 when
2172cbf62fSWill Gardner * SIGINT is triggered. If it has not been setup properly then the program
2272cbf62fSWill Gardner * will be forced to exit and will return 1 instead.
2372cbf62fSWill Gardner */
2472cbf62fSWill Gardner
2572cbf62fSWill Gardner#include <atomic>
2672cbf62fSWill Gardner#include <iostream>
2772cbf62fSWill Gardner#include <thread>
2872cbf62fSWill Gardner
2972cbf62fSWill Gardner#include <platform/interrupt.h>
3072cbf62fSWill Gardner
3172cbf62fSWill Gardnerstatic std::atomic<bool> go{false};
3272cbf62fSWill Gardner
3372cbf62fSWill Gardnervoid handler() {
3472cbf62fSWill Gardner    go = true;
3572cbf62fSWill Gardner}
3672cbf62fSWill Gardner
3772cbf62fSWill Gardnerint main(int argc, char** argv) {
3872cbf62fSWill Gardner    std::cerr << "Registering SIGINT handler\n";
3972cbf62fSWill Gardner    cb::console::set_sigint_handler(handler);
4072cbf62fSWill Gardner
4172cbf62fSWill Gardner    std::cerr << "Busy waiting for signal\n";
4272cbf62fSWill Gardner    while (!go) {
4372cbf62fSWill Gardner        std::this_thread::sleep_for(std::chrono::milliseconds(50));
4472cbf62fSWill Gardner    }
4572cbf62fSWill Gardner    std::cerr << "SIGINT detected!\n";
4672cbf62fSWill Gardner    return 0;
4772cbf62fSWill Gardner}