• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

P_ProtectedQueue.h

Go to the documentation of this file.
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   Protected Queue
00027 
00028 
00029  ****************************************************************************/
00030 #ifndef _P_ProtectedQueue_h_
00031 #define _P_ProtectedQueue_h_
00032 
00033 #include "I_EventSystem.h"
00034 
00035 
00036 TS_INLINE
00037 ProtectedQueue::ProtectedQueue()
00038 {
00039   Event e;
00040   ink_mutex_init(&lock, "ProtectedQueue");
00041   ink_atomiclist_init(&al, "ProtectedQueue", (char *) &e.link.next - (char *) &e);
00042   ink_cond_init(&might_have_data);
00043 }
00044 
00045 TS_INLINE void
00046 ProtectedQueue::signal()
00047 {
00048   // Need to get the lock before you can signal the thread
00049   ink_mutex_acquire(&lock);
00050   ink_cond_signal(&might_have_data);
00051   ink_mutex_release(&lock);
00052 }
00053 
00054 TS_INLINE int
00055 ProtectedQueue::try_signal()
00056 {
00057   // Need to get the lock before you can signal the thread
00058   if (ink_mutex_try_acquire(&lock)) {
00059     ink_cond_signal(&might_have_data);
00060     ink_mutex_release(&lock);
00061     return 1;
00062   } else {
00063     return 0;
00064   }
00065 }
00066 
00067 // Called from the same thread (don't need to signal)
00068 TS_INLINE void
00069 ProtectedQueue::enqueue_local(Event * e)
00070 {
00071   ink_assert(!e->in_the_prot_queue && !e->in_the_priority_queue);
00072   e->in_the_prot_queue = 1;
00073   localQueue.enqueue(e);
00074 }
00075 
00076 TS_INLINE void
00077 ProtectedQueue::remove(Event * e)
00078 {
00079   ink_assert(e->in_the_prot_queue);
00080   if (!ink_atomiclist_remove(&al, e))
00081     localQueue.remove(e);
00082   e->in_the_prot_queue = 0;
00083 }
00084 
00085 TS_INLINE Event *
00086 ProtectedQueue::dequeue_local()
00087 {
00088   Event *e = localQueue.dequeue();
00089   if (e) {
00090     ink_assert(e->in_the_prot_queue);
00091     e->in_the_prot_queue = 0;
00092   }
00093   return e;
00094 }
00095 
00096 #endif

Generated by  doxygen 1.7.1