00001 /** @file 00002 00003 A brief file description 00004 00005 @section license License 00006 00007 Licensed to the Apache Software Foundation (ASF) under one 00008 or more contributor license agreements. See the NOTICE file 00009 distributed with this work for additional information 00010 regarding copyright ownership. The ASF licenses this file 00011 to you under the Apache License, Version 2.0 (the 00012 "License"); you may not use this file except in compliance 00013 with the License. You may obtain a copy of the License at 00014 00015 http://www.apache.org/licenses/LICENSE-2.0 00016 00017 Unless required by applicable law or agreed to in writing, software 00018 distributed under the License is distributed on an "AS IS" BASIS, 00019 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00020 See the License for the specific language governing permissions and 00021 limitations under the License. 00022 */ 00023 00024 /**************************************************************************** 00025 00026 Event.cc 00027 00028 00029 *****************************************************************************/ 00030 #include "P_EventSystem.h" 00031 00032 ClassAllocator<Event> eventAllocator("eventAllocator", 256); 00033 00034 void 00035 Event::schedule_imm(int acallback_event) 00036 { 00037 callback_event = acallback_event; 00038 ink_assert(ethread == this_ethread()); 00039 if (in_the_priority_queue) 00040 ethread->EventQueue.remove(this); 00041 timeout_at = 0; 00042 period = 0; 00043 immediate = true; 00044 mutex = continuation->mutex; 00045 if (!in_the_prot_queue) 00046 ethread->EventQueueExternal.enqueue_local(this); 00047 } 00048 00049 void 00050 Event::schedule_at(ink_hrtime atimeout_at, int acallback_event) 00051 { 00052 callback_event = acallback_event; 00053 ink_assert(ethread == this_ethread()); 00054 ink_assert(atimeout_at > 0); 00055 if (in_the_priority_queue) 00056 ethread->EventQueue.remove(this); 00057 timeout_at = atimeout_at; 00058 period = 0; 00059 immediate = false; 00060 mutex = continuation->mutex; 00061 if (!in_the_prot_queue) 00062 ethread->EventQueueExternal.enqueue_local(this); 00063 } 00064 00065 void 00066 Event::schedule_in(ink_hrtime atimeout_in, int acallback_event) 00067 { 00068 callback_event = acallback_event; 00069 ink_assert(ethread == this_ethread()); 00070 if (in_the_priority_queue) 00071 ethread->EventQueue.remove(this); 00072 timeout_at = ink_get_based_hrtime() + atimeout_in; 00073 period = 0; 00074 immediate = false; 00075 mutex = continuation->mutex; 00076 if (!in_the_prot_queue) 00077 ethread->EventQueueExternal.enqueue_local(this); 00078 } 00079 00080 void 00081 Event::schedule_every(ink_hrtime aperiod, int acallback_event) 00082 { 00083 callback_event = acallback_event; 00084 ink_assert(ethread == this_ethread()); 00085 ink_assert(aperiod != 0); 00086 if (in_the_priority_queue) 00087 ethread->EventQueue.remove(this); 00088 if (aperiod < 0) { 00089 timeout_at = aperiod; 00090 } else { 00091 timeout_at = ink_get_based_hrtime() + aperiod; 00092 } 00093 period = aperiod; 00094 immediate = false; 00095 mutex = continuation->mutex; 00096 if (!in_the_prot_queue) 00097 ethread->EventQueueExternal.enqueue_local(this); 00098 }