~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to iocore/aio/P_AIO.h

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
  Async Disk IO operations.
 
27
 
 
28
 
 
29
 
 
30
 ****************************************************************************/
 
31
#ifndef _P_AIO_h_
 
32
#define _P_AIO_h_
 
33
 
 
34
#ifndef INLINE_CC
 
35
#undef  TS_INLINE
 
36
#define TS_INLINE inline
 
37
#endif
 
38
 
 
39
#include "P_EventSystem.h"
 
40
#include "I_AIO.h"
 
41
 
 
42
// for debugging
 
43
// #define AIO_STATS 1
 
44
 
 
45
#undef  AIO_MODULE_VERSION
 
46
#define AIO_MODULE_VERSION        makeModuleVersion(AIO_MODULE_MAJOR_VERSION,\
 
47
                                                    AIO_MODULE_MINOR_VERSION,\
 
48
                                                    PRIVATE_MODULE_HEADER)
 
49
struct AIO_Reqs;
 
50
 
 
51
struct AIOCallbackInternal: public AIOCallback
 
52
{
 
53
  AIOCallback *first;
 
54
  AIO_Reqs *aio_req;
 
55
  ink_hrtime sleep_time;
 
56
  int io_complete(int event, void *data);
 
57
  AIOCallbackInternal()
 
58
  {
 
59
    const size_t to_zero = sizeof(AIOCallbackInternal)
 
60
      - (size_t) & (((AIOCallbackInternal *) 0)->aiocb);
 
61
    memset((char *) &(this->aiocb), 0, to_zero);
 
62
    SET_HANDLER(&AIOCallbackInternal::io_complete);
 
63
    // we do a memset() on AIOCallback and AIOCallbackInternal, so it sets all the members to 0
 
64
    // coverity[uninit_member]
 
65
  }
 
66
};
 
67
 
 
68
TS_INLINE int
 
69
AIOCallback::ok()
 
70
{
 
71
  return (off_t) aiocb.aio_nbytes == (off_t) aio_result;
 
72
}
 
73
 
 
74
TS_INLINE int
 
75
AIOCallbackInternal::io_complete(int event, void *data)
 
76
{
 
77
  (void) event;
 
78
  (void) data;
 
79
  if (!action.cancelled)
 
80
    action.continuation->handleEvent(AIO_EVENT_DONE, this);
 
81
  return EVENT_DONE;
 
82
}
 
83
 
 
84
struct AIO_Reqs
 
85
{
 
86
  Que(AIOCallback, link) aio_todo;       /* queue for holding non-http requests */
 
87
  Que(AIOCallback, link) http_aio_todo;  /* queue for http requests */
 
88
  /* Atomic list to temporarily hold the request if the
 
89
     lock for a particular queue cannot be acquired */
 
90
  InkAtomicList aio_temp_list;
 
91
  ink_mutex aio_mutex;
 
92
  ink_cond aio_cond;
 
93
  int index;                    /* position of this struct in the aio_reqs array */
 
94
  volatile int pending;         /* number of outstanding requests on the disk */
 
95
  volatile int queued;          /* total number of aio_todo and http_todo requests */
 
96
  volatile int filedes;         /* the file descriptor for the requests */
 
97
  volatile int requests_queued;
 
98
};
 
99
 
 
100
#ifdef AIO_STATS
 
101
class AIOTestData:public Continuation
 
102
{
 
103
public:
 
104
  int num_req;
 
105
  int num_temp;
 
106
  int num_queue;
 
107
  ink_hrtime start;
 
108
 
 
109
  int ink_aio_stats(int event, void *data);
 
110
 
 
111
  AIOTestData():Continuation(new_ProxyMutex()), num_req(0), num_temp(0), num_queue(0)
 
112
  {
 
113
    start = ink_get_hrtime();
 
114
    SET_HANDLER(&AIOTestData::ink_aio_stats);
 
115
  }
 
116
};
 
117
#endif
 
118
 
 
119
enum aio_stat_enum
 
120
{
 
121
  AIO_STAT_READ_PER_SEC,
 
122
  AIO_STAT_KB_READ_PER_SEC,
 
123
  AIO_STAT_WRITE_PER_SEC,
 
124
  AIO_STAT_KB_WRITE_PER_SEC,
 
125
  AIO_STAT_COUNT
 
126
};
 
127
extern RecRawStatBlock *aio_rsb;
 
128
 
 
129
#ifdef _WIN32
 
130
extern NTIOCompletionPort aio_completion_port;
 
131
#endif
 
132
 
 
133
#endif