mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-19 18:03:50 +00:00
O(1) socket removal
This commit is contained in:
parent
f92de9b2a9
commit
4914e5c9d1
@ -138,16 +138,16 @@ zmq::socket_base_t *zmq::app_thread_t::create_socket (int type_)
|
|||||||
// TODO: type is ignored for the time being.
|
// TODO: type is ignored for the time being.
|
||||||
socket_base_t *s = new socket_base_t (this);
|
socket_base_t *s = new socket_base_t (this);
|
||||||
zmq_assert (s);
|
zmq_assert (s);
|
||||||
|
s->set_index (sockets.size ());
|
||||||
sockets.push_back (s);
|
sockets.push_back (s);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void zmq::app_thread_t::remove_socket (socket_base_t *socket_)
|
void zmq::app_thread_t::remove_socket (socket_base_t *socket_)
|
||||||
{
|
{
|
||||||
// TODO: To speed this up we can possibly use the system where each socket
|
int i = socket_->get_index ();
|
||||||
// holds its index (see I/O scheduler implementation).
|
socket_->set_index (-1);
|
||||||
sockets_t::iterator it = std::find (sockets.begin (), sockets.end (),
|
sockets [i] = sockets.back ();
|
||||||
socket_);
|
sockets [i]->set_index (i);
|
||||||
zmq_assert (it != sockets.end ());
|
sockets.pop_back ();
|
||||||
sockets.erase (it);
|
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,8 @@ zmq::socket_base_t::socket_base_t (app_thread_t *parent_) :
|
|||||||
pending_term_acks (0),
|
pending_term_acks (0),
|
||||||
ticks (0),
|
ticks (0),
|
||||||
app_thread (parent_),
|
app_thread (parent_),
|
||||||
shutting_down (false)
|
shutting_down (false),
|
||||||
|
index (-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,6 +380,17 @@ void zmq::socket_base_t::detach_outpipe (class writer_t *pipe_)
|
|||||||
out_pipes.pop_back ();
|
out_pipes.pop_back ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void zmq::socket_base_t::set_index (int index_)
|
||||||
|
{
|
||||||
|
index = index_;
|
||||||
|
}
|
||||||
|
|
||||||
|
int zmq::socket_base_t::get_index ()
|
||||||
|
{
|
||||||
|
zmq_assert (index != -1);
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
void zmq::socket_base_t::process_own (owned_t *object_)
|
void zmq::socket_base_t::process_own (owned_t *object_)
|
||||||
{
|
{
|
||||||
io_objects.insert (object_);
|
io_objects.insert (object_);
|
||||||
|
@ -66,6 +66,10 @@ namespace zmq
|
|||||||
void detach_inpipe (class reader_t *pipe_);
|
void detach_inpipe (class reader_t *pipe_);
|
||||||
void detach_outpipe (class writer_t *pipe_);
|
void detach_outpipe (class writer_t *pipe_);
|
||||||
|
|
||||||
|
// Manipulating index in the app_thread's list of sockets.
|
||||||
|
void set_index (int index);
|
||||||
|
int get_index ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Handlers for incoming commands.
|
// Handlers for incoming commands.
|
||||||
@ -131,6 +135,9 @@ namespace zmq
|
|||||||
sessions_t sessions;
|
sessions_t sessions;
|
||||||
mutex_t sessions_sync;
|
mutex_t sessions_sync;
|
||||||
|
|
||||||
|
// Index of the socket in the app_thread's list of sockets.
|
||||||
|
int index;
|
||||||
|
|
||||||
socket_base_t (const socket_base_t&);
|
socket_base_t (const socket_base_t&);
|
||||||
void operator = (const socket_base_t&);
|
void operator = (const socket_base_t&);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user