00001 // -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; indent-tabs-mode: nil; -*- 00002 //////////////////////////////////////////////////////////////////// 00003 // 00004 // Filename : IOQueue.h (io) 00005 // 00006 // Priority queue for IO requests and IO request definition. 00007 // 00008 // This file is a part of the UPPAAL toolkit. 00009 // Copyright (c) 1995 - 2003, Uppsala University and Aalborg University. 00010 // All right reserved. 00011 // 00012 // $Id: IOQueue.h,v 1.2 2004/02/11 11:17:08 adavid Exp $ 00013 // 00014 /////////////////////////////////////////////////////////////////// 00015 00016 #ifndef INCLUDE_IO_IOQUEUE_H 00017 #define INCLUDE_IO_IOQUEUE_H 00018 00019 #include "base/PriorityQueue.h" 00020 #include "base/bitptr.h" 00021 00022 namespace io 00023 { 00024 /** Base request struct to define requests. 00025 */ 00026 struct requestdata_t 00027 { 00028 uint64_t offset; 00029 }; 00030 00031 00032 /** Abstract io request: 00033 * pointer to the offset of the operation 00034 * (on a file) with some bit information 00035 * (meaning unknown here). 00036 * 00037 * NOTE: do not inherit from iorequest_t 00038 * because it is copied in the IOQueue. 00039 */ 00040 struct iorequest_t : public base::bitptr_t<requestdata_t> 00041 { 00042 /** Constructors = wrappers. 00043 */ 00044 iorequest_t(requestdata_t *ptr) 00045 : base::bitptr_t<requestdata_t>(ptr) {} 00046 iorequest_t(requestdata_t *ptr, uint32_t bits) 00047 : base::bitptr_t<requestdata_t>(ptr, bits) {} 00048 00049 00050 /** Wrapper: @return offset of the io request 00051 */ 00052 uint64_t getOffset() const 00053 { 00054 assert(getPtr()); 00055 return getPtr()->offset; 00056 } 00057 00058 /* Comparison operators are used only 00059 * to order requests in the priority queue. 00060 */ 00061 00062 /** Operator < defined on the offset 00063 */ 00064 bool operator < (const iorequest_t& req) const 00065 { 00066 return getOffset() < req.getOffset(); 00067 } 00068 00069 }; 00070 00071 00072 /** An IO queue is a priority queue 00073 * where the ordering is defined by the 00074 * offsets of the operations to perform. 00075 */ 00076 class IOQueue : public base::PriorityQueue<iorequest_t> 00077 { 00078 public: 00079 00080 /** Pop a request from the priority queue 00081 * @param req: pointer to the request to write 00082 * @return true if successful, false otherwise 00083 */ 00084 bool tryPop(iorequest_t *req) 00085 { 00086 assert(req); 00087 if (empty()) return false; 00088 *req = top(); 00089 pop(); 00090 return true; 00091 } 00092 00093 }; 00094 00095 } // namespace io 00096 00097 #endif // INCLUDE_IO_IOQUEUE_H