Changeset d48b174 for libcfa/src


Ignore:
Timestamp:
Jan 12, 2021, 12:57:59 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
35285fd
Parents:
58f99b3
Message:

clean-up handling of epoll so it's limited to one file

Location:
libcfa/src/concurrency
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/io.cfa

    r58f99b3 rd48b174  
    3131
    3232        extern "C" {
    33                 #include <sys/epoll.h>
    34                 #include <sys/eventfd.h>
    3533                #include <sys/syscall.h>
    3634
     
    266264
    267265        void main( $io_ctx_thread & this ) {
    268                 epoll_event ev;
    269                 __ioctx_register( this, ev );
     266                __ioctx_register( this );
    270267
    271268                __cfadbg_print_safe(io_core, "Kernel I/O : IO poller %d (%p) ready\n", this.ring->fd, &this);
     
    303300                                // we need to retry one last time in case
    304301                                // something completed *just now*
    305                                 __ioctx_prepare_block( this, ev );
     302                                __ioctx_prepare_block( this );
    306303                                continue LOOP;
    307304                        }
     
    314311                                // block this thread
    315312                                wait( this.sem );
    316 
    317                                 eventfd_t v;
    318                                 eventfd_read(this.ring->efd, &v);
    319313
    320314                        // restore counter
  • libcfa/src/concurrency/io/setup.cfa

    r58f99b3 rd48b174  
    190190                                        __cfaabi_tls.this_stats = io_ctx->self.curr_cluster->stats;
    191191                                #endif
     192
     193                                eventfd_t v;
     194                                eventfd_read(io_ctx->ring->efd, &v);
     195
    192196                                post( io_ctx->sem );
    193197                        }
     
    494498// I/O Context Sleep
    495499//=============================================================================================
    496 
    497         void __ioctx_register($io_ctx_thread & ctx, struct epoll_event & ev) {
    498                 ev.events = EPOLLIN | EPOLLET | EPOLLONESHOT;
     500        #define IOEVENTS EPOLLIN | EPOLLONESHOT
     501
     502        static inline void __ioctx_epoll_ctl($io_ctx_thread & ctx, int op, const char * error) {
     503                struct epoll_event ev;
     504                ev.events = IOEVENTS;
    499505                ev.data.u64 = (__u64)&ctx;
    500                 int ret = epoll_ctl(iopoll.epollfd, EPOLL_CTL_ADD, ctx.ring->efd, &ev);
     506                int ret = epoll_ctl(iopoll.epollfd, op, ctx.ring->efd, &ev);
    501507                if (ret < 0) {
    502                         abort( "KERNEL ERROR: EPOLL ADD - (%d) %s\n", (int)errno, strerror(errno) );
    503                 }
    504         }
    505 
    506         void __ioctx_prepare_block($io_ctx_thread & ctx, struct epoll_event & ev) {
     508                        abort( "KERNEL ERROR: EPOLL %s - (%d) %s\n", error, (int)errno, strerror(errno) );
     509                }
     510        }
     511
     512        void __ioctx_register($io_ctx_thread & ctx) {
     513                __ioctx_epoll_ctl(ctx, EPOLL_CTL_ADD, "ADD");
     514        }
     515
     516        void __ioctx_prepare_block($io_ctx_thread & ctx) {
    507517                __cfadbg_print_safe(io_core, "Kernel I/O - epoll : Re-arming io poller %d (%p)\n", ctx.ring->fd, &ctx);
    508                 int ret = epoll_ctl(iopoll.epollfd, EPOLL_CTL_MOD, ctx.ring->efd, &ev);
    509                 if (ret < 0) {
    510                         abort( "KERNEL ERROR: EPOLL REARM - (%d) %s\n", (int)errno, strerror(errno) );
    511                 }
     518                __ioctx_epoll_ctl(ctx, EPOLL_CTL_MOD, "REARM");
    512519        }
    513520
  • libcfa/src/concurrency/io/types.hfa

    r58f99b3 rd48b174  
    131131        #endif
    132132
    133         struct epoll_event;
    134133        struct $io_ctx_thread;
    135         void __ioctx_register($io_ctx_thread & ctx, struct epoll_event & ev);
    136         void __ioctx_prepare_block($io_ctx_thread & ctx, struct epoll_event & ev);
     134        void __ioctx_register($io_ctx_thread & ctx);
     135        void __ioctx_prepare_block($io_ctx_thread & ctx);
    137136#endif
    138137
Note: See TracChangeset for help on using the changeset viewer.