1 /** @file
2 
3   Public declaration of Processor class
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 #pragma once
26 
27 #include "tscore/ink_platform.h"
28 
29 #define PROCESSOR_RECONFIGURE 0x01
30 #define PROCESSOR_CHECK 0x02
31 #define PROCESSOR_FIX 0x04
32 #define PROCESSOR_IGNORE_ERRORS 0x08
33 
34 class Processor;
35 class Thread;
36 
37 /**
38    Base class for all of the IO Core processors.
39 
40    The Processor class defines a common interface for all the
41    processors in the IO Core. A processor is multithreaded subsystem
42    specialized in some type of task or application. For example,
43    the Event System module includes the EventProcessor which provides
44    scheduling services, the Net module includes the NetProcessor
45    which provides networking services, etc.
46 
47    You cannot create objects of the Processor class and its methods
48    have no implementation. Therefore, you are expected to use objects
49    of a derived type.
50 
51    Most of such derived classes, provide a singleton object and is
52    common case to have a single instance in that application scope.
53 
54 */
55 class Processor
56 {
57 public:
58   virtual ~Processor();
59 
60   /**
61     Returns a Thread appropriate for the processor.
62 
63     Returns a new instance of a Thread or Thread derived class of
64     a thread which is the thread class for the processor.
65 
66     @param thread_index reserved for future use.
67 
68   */
69   virtual Thread *create_thread(int thread_index);
70 
71   /**
72     Returns the number of threads required for this processor. If
73     the number is not defined or not used, it is equal to 0.
74 
75   */
76   virtual int get_thread_count();
77 
78   /**
79     This function attempts to stop the processor. Please refer to
80     the documentation on each processor to determine if it is
81     supported.
82 
83   */
84   virtual void
shutdown()85   shutdown()
86   {
87   }
88 
89   /**
90     Starts execution of the processor.
91 
92     Attempts to start the number of threads specified for the
93     processor, initializes their states and sets them running. On
94     failure it returns a negative value.
95 
96     @param number_of_threads Positive value indicating the number of
97         threads to spawn for the processor.
98     @param stacksize The thread stack size to use for this processor.
99 
100   */
101   virtual int
start(int number_of_threads,size_t stacksize=DEFAULT_STACKSIZE)102   start(int number_of_threads, size_t stacksize = DEFAULT_STACKSIZE)
103   {
104     (void)number_of_threads;
105     (void)stacksize;
106     return 0;
107   }
108 
109   // noncopyable, prevent unauthorized copies (Not implemented)
110   Processor(const Processor &) = delete;
111   Processor &operator=(const Processor &) = delete;
112 
113 protected:
114   Processor();
115 };
116