Back to home page

OSCL-LXR

 
 

    


0001 #ifndef IOU_REQ_REF_H
0002 #define IOU_REQ_REF_H
0003 
0004 #include <linux/atomic.h>
0005 #include <linux/io_uring_types.h>
0006 
0007 /*
0008  * Shamelessly stolen from the mm implementation of page reference checking,
0009  * see commit f958d7b528b1 for details.
0010  */
0011 #define req_ref_zero_or_close_to_overflow(req)  \
0012     ((unsigned int) atomic_read(&(req->refs)) + 127u <= 127u)
0013 
0014 static inline bool req_ref_inc_not_zero(struct io_kiocb *req)
0015 {
0016     WARN_ON_ONCE(!(req->flags & REQ_F_REFCOUNT));
0017     return atomic_inc_not_zero(&req->refs);
0018 }
0019 
0020 static inline bool req_ref_put_and_test(struct io_kiocb *req)
0021 {
0022     if (likely(!(req->flags & REQ_F_REFCOUNT)))
0023         return true;
0024 
0025     WARN_ON_ONCE(req_ref_zero_or_close_to_overflow(req));
0026     return atomic_dec_and_test(&req->refs);
0027 }
0028 
0029 static inline void req_ref_get(struct io_kiocb *req)
0030 {
0031     WARN_ON_ONCE(!(req->flags & REQ_F_REFCOUNT));
0032     WARN_ON_ONCE(req_ref_zero_or_close_to_overflow(req));
0033     atomic_inc(&req->refs);
0034 }
0035 
0036 static inline void __io_req_set_refcount(struct io_kiocb *req, int nr)
0037 {
0038     if (!(req->flags & REQ_F_REFCOUNT)) {
0039         req->flags |= REQ_F_REFCOUNT;
0040         atomic_set(&req->refs, nr);
0041     }
0042 }
0043 
0044 static inline void io_req_set_refcount(struct io_kiocb *req)
0045 {
0046     __io_req_set_refcount(req, 1);
0047 }
0048 #endif