mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: adi hodos <thefatredguy@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: Suggested addition to epoll interface - epoll_post_notification()
Date: Tue, 15 Sep 2009 15:59:00 +0300	[thread overview]
Message-ID: <2517f1930909150559p505b583fpf3501a1c7dad6634@mail.gmail.com> (raw)

Hello everyone. Thank you for your time in reading this.
I have been playing with epoll lately and I would like to make a suggestion
regarding the epoll interface.
It would be nice to have a function to wake up a thread/process that is blocked
on an epoll_wait() call and sent it some
user defined data in the form of a struct epoll_event parameter ( something
similar with PostQueuedCompletionStatus() from Windows ).
My suggestion is for a function like this : int epoll_post_notification( int
epoll_descriptor , struct epoll_event* event );
It could be of much help in scenarios like these :

int e_accept;
int e_clients;

typedef enum {
 keycode_client_connection ,
 keycode_signal ,
 keycode_socketio ,
 keycode_fileio ,
 keycode_event ,
 keycode_timer
 ....
} event_key_type;

struct event_key {
  event_key_type keycode;
};

struct eventfd_wrapper {
 struct eventkey ek;
 int fd_event;
};

struct signalfd_wrapper {
 struct eventkey ek;
 int fd_signal;
};

struct client {
 struct event_key ek;
 int sock;
 ....
};

struct user_posted_event {
 struct event_key ek;
 union {
  void*    ptr_data;
  int      i_data;
  uint32_t u32;
  uint32_t u64;
 } u;
};


// thread A - waits for client connections using an epoll interface
for ( ; ; ) {
 epoll_wait( e_accept , ... );

 int s = accept();
 struct client* new_client = allocate_newclient();
 new_client->sock = s;
 struct user_posted_event* ue = allocate_newuserevent();
 ue->ek.keycode = keycode_client_connection;
 ue->u.ptr_data = new_client;

 struct epoll_event e;
 e.data.ptr = ue;
 epoll_post_notification( e_clients , &e );
}

// thread b - serves clients
for( ; ; ) {
 struct epoll_event[..] e;
 epoll_wait( e_clients , e , ... );

 struct event_key* key = ( struct event_key* )( e.data.ptr );
 if( key->keycode == keycode_client_connection ) {
   // handle new client connection
 } else if( key->keycode == keycode_signal ) {
   // handle signal
 } else if( .... ) {
  ...
 }

Again , thank you for your time in reviewing this.

             reply	other threads:[~2009-09-15 12:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-15 12:59 adi hodos [this message]
2009-09-15 18:16 ` Roland Dreier
2009-09-15 18:48 ` Davide Libenzi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2517f1930909150559p505b583fpf3501a1c7dad6634@mail.gmail.com \
    --to=thefatredguy@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®