kill_thread.h 2.4 KB
Newer Older
羽飞's avatar
羽飞 已提交
1
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
羽飞's avatar
羽飞 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

//
// Created by Longda on 2010
//

羽飞's avatar
羽飞 已提交
15
#pragma once
羽飞's avatar
羽飞 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

#include <list>

#include "common/defs.h"
#include "common/seda/stage.h"
namespace common {

/**
 *  @file
 *  @author Longda
 *  @date   3/16/07
 */

class Threadpool;

/**
 * A Stage to kill threads in a thread pool
 * The KillThreadStage is scheduled on a thread pool whenever threads
 * need to be killed.  Each event handled by the stage results in the
 * death of the thread.
 */
class KillThreadStage : public Stage {

public:
  /**
   * parse properties, instantiate a summation stage object
   * @pre class members are uninitialized
   * @post initializing the class members
   * @return Stage instantiated object
   */
  static Stage *make_stage(const std::string &tag);

protected:
  /**
   * Constructor
   * @param[in] tag     The label that identifies this stage.
   *
   * @pre  tag is non-null and points to null-terminated string
   * @post event queue is empty
   * @post stage is not connected
   */
57 58
  KillThreadStage(const char *tag) : Stage(tag)
  {}
羽飞's avatar
羽飞 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71

  /**
   * Notify the pool and kill the thread
   * @param[in] event Pointer to event that must be handled.
   *
   * @post  Call never returns.  Thread is killed.  Pool is notified.
   */
  void handle_event(StageEvent *event);

  /**
   * Handle the callback
   * Nothing special for callbacks in this stage.
   */
72 73 74 75
  void callback_event(StageEvent *event, CallbackContext *context)
  {
    return;
  }
羽飞's avatar
羽飞 已提交
76 77 78 79 80 81 82 83

  /**
   * Initialize stage params
   * Ignores next_stage_list_---there are no outputs for this stage.
   *
   * @pre  Stage not connected
   * @return true
   */
84 85 86 87
  bool initialize()
  {
    return true;
  }
羽飞's avatar
羽飞 已提交
88 89 90 91 92 93 94 95 96 97 98 99

  /**
   * set properties for this object
   * @pre class members are uninitialized
   * @post initializing the class members
   * @return Stage instantiated object
   */
  bool set_properties();

  friend class Threadpool;
};

100
}  // namespace common