1 /** @file 2 3 A brief file description 4 5 @section license License 6 7 Licensed to the Apache Software Foundation (ASF) under one 8 or more contributor license agreements. See the NOTICE file 9 distributed with this work for additional information 10 regarding copyright ownership. The ASF licenses this file 11 to you under the Apache License, Version 2.0 (the 12 "License"); you may not use this file except in compliance 13 with the License. You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 */ 23 24 /**************************************************************************** 25 26 ContFlags.h 27 28 Thread local storage for a set of flags that are updated based the continuation 29 currently running in the thread. These flags are handy if the data is needed 30 as a "global" in parts of the code where the original net VC is not available. 31 Storing the flags in the void * of the thread key directly. I assume we are on 32 at least a 32 bit architecture, so the rawflags size is 32 bits. 33 ****************************************************************************/ 34 35 #pragma once 36 37 #include "ink_thread.h" 38 39 class ContFlags 40 { 41 public: 42 enum flags { DEBUG_OVERRIDE = 0, DISABLE_PLUGINS = 1, LAST_FLAG }; 43 ContFlags()44 ContFlags() {} 45 ContFlags(ContFlags const &that) = default; ContFlags(uint32_t in_flags)46 ContFlags(uint32_t in_flags) : raw_flags(in_flags) {} 47 void set_flags(uint32_t new_flags)48 set_flags(uint32_t new_flags) 49 { 50 raw_flags = new_flags; 51 } 52 ContFlags & 53 operator=(ContFlags const &other) 54 { 55 this->set_flags(other.get_flags()); 56 return *this; 57 } 58 59 uint32_t get_flags()60 get_flags() const 61 { 62 return raw_flags; 63 } 64 void set_flag(enum flags flag_bit,bool value)65 set_flag(enum flags flag_bit, bool value) 66 { 67 if (flag_bit >= 0 && flag_bit < LAST_FLAG) { 68 if (value) 69 raw_flags |= (1 << flag_bit); 70 else 71 raw_flags &= ~(1 << flag_bit); 72 } 73 } 74 bool get_flag(enum flags flag_bit)75 get_flag(enum flags flag_bit) const 76 { 77 if (flag_bit >= 0 && flag_bit < LAST_FLAG) { 78 return (raw_flags & (1 << flag_bit)) != 0; 79 } else { 80 return false; 81 } 82 } 83 bool is_set()84 is_set() const 85 { 86 return raw_flags != 0; 87 } 88 89 private: 90 uint32_t raw_flags = 0; 91 }; 92 93 void set_cont_flags(const ContFlags &flags); 94 void set_cont_flag(ContFlags::flags flag_bit, bool value); 95 ContFlags get_cont_flags(); 96 bool get_cont_flag(ContFlags::flags flag_bit); 97