Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
folly
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
folly
Commits
ce80e19d
Commit
ce80e19d
authored
Feb 05, 2013
by
Tudor Bosman
Committed by
Jordan DeLong
Mar 18, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AsyncIO: CHECK preconditions
Test Plan: async_io_test Reviewed By: delong.j@fb.com FB internal diff: D698919
parent
8f45b8d5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
28 deletions
+9
-28
folly/experimental/io/AsyncIO.cpp
folly/experimental/io/AsyncIO.cpp
+9
-28
No files found.
folly/experimental/io/AsyncIO.cpp
View file @
ce80e19d
...
@@ -32,9 +32,7 @@ AsyncIO::AsyncIO(size_t capacity, PollMode pollMode)
...
@@ -32,9 +32,7 @@ AsyncIO::AsyncIO(size_t capacity, PollMode pollMode)
pending_
(
0
),
pending_
(
0
),
capacity_
(
capacity
),
capacity_
(
capacity
),
pollFd_
(
-
1
)
{
pollFd_
(
-
1
)
{
if
(
UNLIKELY
(
capacity_
==
0
))
{
CHECK_GT
(
capacity_
,
0
);
throw
std
::
out_of_range
(
"AsyncIO: capacity must not be 0"
);
}
completed_
.
reserve
(
capacity_
);
completed_
.
reserve
(
capacity_
);
if
(
pollMode
==
POLLABLE
)
{
if
(
pollMode
==
POLLABLE
)
{
pollFd_
=
eventfd
(
0
,
EFD_NONBLOCK
);
pollFd_
=
eventfd
(
0
,
EFD_NONBLOCK
);
...
@@ -100,12 +98,8 @@ void AsyncIO::initializeContext() {
...
@@ -100,12 +98,8 @@ void AsyncIO::initializeContext() {
}
}
void
AsyncIO
::
submit
(
Op
*
op
,
iocb
*
cb
)
{
void
AsyncIO
::
submit
(
Op
*
op
,
iocb
*
cb
)
{
if
(
UNLIKELY
(
pending_
>=
capacity_
))
{
CHECK_EQ
(
op
->
state
(),
Op
::
UNINITIALIZED
);
throw
std
::
out_of_range
(
"AsyncIO: too many pending requests"
);
CHECK_LT
(
pending_
,
capacity_
)
<<
"too many pending requests"
;
}
if
(
UNLIKELY
(
op
->
state
()
!=
Op
::
UNINITIALIZED
))
{
throw
std
::
logic_error
(
"AsyncIO: Invalid Op state in submit"
);
}
initializeContext
();
// on demand
initializeContext
();
// on demand
cb
->
data
=
op
;
cb
->
data
=
op
;
if
(
pollFd_
!=
-
1
)
{
if
(
pollFd_
!=
-
1
)
{
...
@@ -119,23 +113,14 @@ void AsyncIO::submit(Op* op, iocb* cb) {
...
@@ -119,23 +113,14 @@ void AsyncIO::submit(Op* op, iocb* cb) {
}
}
Range
<
AsyncIO
::
Op
**>
AsyncIO
::
wait
(
size_t
minRequests
)
{
Range
<
AsyncIO
::
Op
**>
AsyncIO
::
wait
(
size_t
minRequests
)
{
if
(
UNLIKELY
(
!
ctx_
))
{
CHECK
(
ctx_
);
throw
std
::
logic_error
(
"AsyncIO: wait called with no requests"
);
CHECK_EQ
(
pollFd_
,
-
1
)
<<
"wait() only allowed on non-pollable object"
;
}
if
(
UNLIKELY
(
pollFd_
!=
-
1
))
{
throw
std
::
logic_error
(
"AsyncIO: wait not allowed on pollable object"
);
}
return
doWait
(
minRequests
,
pending_
);
return
doWait
(
minRequests
,
pending_
);
}
}
Range
<
AsyncIO
::
Op
**>
AsyncIO
::
pollCompleted
()
{
Range
<
AsyncIO
::
Op
**>
AsyncIO
::
pollCompleted
()
{
if
(
UNLIKELY
(
!
ctx_
))
{
CHECK
(
ctx_
);
throw
std
::
logic_error
(
"AsyncIO: pollCompleted called with no requests"
);
CHECK_NE
(
pollFd_
,
-
1
)
<<
"pollCompleted() only allowed on pollable object"
;
}
if
(
UNLIKELY
(
pollFd_
==
-
1
))
{
throw
std
::
logic_error
(
"AsyncIO: pollCompleted not allowed on non-pollable object"
);
}
uint64_t
numEvents
;
uint64_t
numEvents
;
// This sets the eventFd counter to 0, see
// This sets the eventFd counter to 0, see
// http://www.kernel.org/doc/man-pages/online/pages/man2/eventfd.2.html
// http://www.kernel.org/doc/man-pages/online/pages/man2/eventfd.2.html
...
@@ -189,9 +174,7 @@ AsyncIO::Op::Op()
...
@@ -189,9 +174,7 @@ AsyncIO::Op::Op()
}
}
void
AsyncIO
::
Op
::
reset
()
{
void
AsyncIO
::
Op
::
reset
()
{
if
(
UNLIKELY
(
state_
==
PENDING
))
{
CHECK_NE
(
state_
,
PENDING
);
throw
std
::
logic_error
(
"AsyncIO: invalid state for reset"
);
}
state_
=
UNINITIALIZED
;
state_
=
UNINITIALIZED
;
result_
=
-
EINVAL
;
result_
=
-
EINVAL
;
}
}
...
@@ -215,9 +198,7 @@ void AsyncIO::Op::complete(ssize_t result) {
...
@@ -215,9 +198,7 @@ void AsyncIO::Op::complete(ssize_t result) {
void
AsyncIO
::
Op
::
onCompleted
()
{
}
// default: do nothing
void
AsyncIO
::
Op
::
onCompleted
()
{
}
// default: do nothing
ssize_t
AsyncIO
::
Op
::
result
()
const
{
ssize_t
AsyncIO
::
Op
::
result
()
const
{
if
(
UNLIKELY
(
state_
!=
COMPLETED
))
{
CHECK_EQ
(
state_
,
COMPLETED
);
throw
std
::
logic_error
(
"AsyncIO: Invalid Op state in result"
);
}
return
result_
;
return
result_
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment