Skip to content

Commit

Permalink
Use flagfd
Browse files Browse the repository at this point in the history
  • Loading branch information
rescrv committed Apr 24, 2015
1 parent 0510d1c commit 6ba834b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
29 changes: 6 additions & 23 deletions busybee.cc
Expand Up @@ -424,9 +424,7 @@ busybee_st :: busybee_st(busybee_mapper* mapper,
, m_recv_queue(NULL)
, m_recv_end(&m_recv_queue)
, m_sigmask()
, m_eventfdread()
, m_eventfdwrite()
, m_event_in_fd(false)
, m_flagfd()
{
assert(m_server_id == 0 || m_server_id >= (1ULL << 32ULL));
m_gc.register_thread(&m_gc_ts);
Expand All @@ -438,17 +436,12 @@ busybee_st :: busybee_st(busybee_mapper* mapper,

add_signals();

int eventfd[2];

if (pipe(eventfd) < 0)
if (!m_flagfd.valid())
{
throw po6::error(errno);
throw po6::error(m_flagfd.error());
}

m_eventfdread = eventfd[0];
m_eventfdwrite = eventfd[1];

if (add_event(m_eventfdread.get(),EPOLLIN) < 0)
if (add_event(m_flagfd.poll_fd(), EPOLLIN) < 0)
{
throw po6::error(errno);
}
Expand Down Expand Up @@ -831,12 +824,7 @@ CLASSNAME :: recv(
m_recv_queue = NULL;
m_recv_end = &m_recv_queue;
#ifdef BUSYBEE_SINGLETHREADED
char buf[32];

while (m_eventfdread.read(buf, 32) == 32)
;

m_event_in_fd = false;
m_flagfd.unset();
#endif // BUSYBEE_SINGLETHREADED
}

Expand Down Expand Up @@ -1468,12 +1456,7 @@ CLASSNAME :: work_recv(channel* chan, busybee_returncode* rc)
m_recv_end = recv_end;

#ifdef BUSYBEE_SINGLETHREADED
if (!m_event_in_fd)
{
char c;
m_eventfdwrite.xwrite(&c, 1);
m_event_in_fd = true;
}
m_flagfd.set();
#endif // BUSYBEE_SINGLETHREADED
}

Expand Down
5 changes: 2 additions & 3 deletions busybee_st.h
Expand Up @@ -38,6 +38,7 @@
// e
#include <e/array_ptr.h>
#include <e/buffer.h>
#include <e/flagfd.h>
#include <e/garbage_collector.h>
#include <e/nwf_hash_map.h>

Expand Down Expand Up @@ -116,9 +117,7 @@ class busybee_st
recv_message* m_recv_queue;
recv_message** m_recv_end;
sigset_t m_sigmask;
po6::io::fd m_eventfdread;
po6::io::fd m_eventfdwrite;
bool m_event_in_fd;
e::flagfd m_flagfd;

private:
busybee_st(const busybee_st&);
Expand Down

0 comments on commit 6ba834b

Please sign in to comment.