kill_thread.h 2.5 KB
Newer Older
羽飞's avatar
羽飞 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 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 57
/* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved.
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
//

#ifndef __COMMON_SEDA_KILL_THREAD_H__
#define __COMMON_SEDA_KILL_THREAD_H__

#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
   */
58 59
  KillThreadStage(const char *tag) : Stage(tag)
  {}
羽飞's avatar
羽飞 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72

  /**
   * 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.
   */
73 74 75 76
  void callback_event(StageEvent *event, CallbackContext *context)
  {
    return;
  }
羽飞's avatar
羽飞 已提交
77 78 79 80 81 82 83 84

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

  /**
   * 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;
};

101 102
}  // namespace common
#endif  // __COMMON_SEDA_KILL_THREAD_H__