mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-12 10:33:52 +01:00
Problem: some context options have no getter
Solution: add one so that class-based bindings can easily use them
This commit is contained in:
parent
92cf6c6451
commit
22c3ecc458
@ -64,6 +64,24 @@ zero if the "block forever on context termination" gambit was disabled by
|
||||
setting ZMQ_BLOCKY to false on all new contexts.
|
||||
|
||||
|
||||
ZMQ_THREAD_SCHED_POLICY: Get scheduling policy for I/O threads
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
The 'ZMQ_THREAD_SCHED_POLICY' argument returns the scheduling policy for
|
||||
internal context's thread pool.
|
||||
|
||||
|
||||
ZMQ_THREAD_PRIORITY: Get scheduling priority for I/O threads
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
The 'ZMQ_THREAD_PRIORITY' argument returns the scheduling priority for
|
||||
internal context's thread pool.
|
||||
|
||||
|
||||
ZMQ_THREAD_NAME_PREFIX: Get name prefix for I/O threads
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
The 'ZMQ_THREAD_NAME_PREFIX' argument gets the numeric prefix of each thread
|
||||
created for the internal context's thread pool.
|
||||
|
||||
|
||||
ZMQ_MSG_T_SIZE: Get the zmq_msg_t size at runtime
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
The 'ZMQ_MSG_T_SIZE' argument returns the size of the zmq_msg_t structure at
|
||||
|
22
src/ctx.cpp
22
src/ctx.cpp
@ -271,8 +271,7 @@ int zmq::ctx_t::get (int option_)
|
||||
else if (option_ == ZMQ_ZERO_COPY_RECV) {
|
||||
rc = _zero_copy;
|
||||
} else {
|
||||
errno = EINVAL;
|
||||
rc = -1;
|
||||
rc = thread_ctx_t::get (option_);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@ -467,6 +466,25 @@ int zmq::thread_ctx_t::set (int option_, int optval_)
|
||||
return rc;
|
||||
}
|
||||
|
||||
int zmq::thread_ctx_t::get (int option_)
|
||||
{
|
||||
int rc = 0;
|
||||
if (option_ == ZMQ_THREAD_PRIORITY) {
|
||||
scoped_lock_t locker (_opt_sync);
|
||||
rc = _thread_priority;
|
||||
} else if (option_ == ZMQ_THREAD_SCHED_POLICY) {
|
||||
scoped_lock_t locker (_opt_sync);
|
||||
rc = _thread_sched_policy;
|
||||
} else if (option_ == ZMQ_THREAD_NAME_PREFIX) {
|
||||
scoped_lock_t locker (_opt_sync);
|
||||
rc = atoi (_thread_name_prefix.c_str ());
|
||||
} else {
|
||||
errno = EINVAL;
|
||||
rc = -1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
void zmq::ctx_t::send_command (uint32_t tid_, const command_t &command_)
|
||||
{
|
||||
_slots[tid_]->send (command_);
|
||||
|
@ -70,6 +70,7 @@ class thread_ctx_t
|
||||
void start_thread (thread_t &thread_, thread_fn *tfn_, void *arg_) const;
|
||||
|
||||
int set (int option_, int optval_);
|
||||
int get (int option_);
|
||||
|
||||
protected:
|
||||
// Synchronisation of access to context options.
|
||||
|
@ -92,6 +92,8 @@ void test_ctx_thread_opts (void *ctx_)
|
||||
// as of ZMQ 4.2.3 this has an effect only on POSIX systems (nothing happens on Windows, but still it should return success):
|
||||
rc = zmq_ctx_set (ctx_, ZMQ_THREAD_SCHED_POLICY, TEST_POLICY);
|
||||
assert (rc == 0);
|
||||
rc = zmq_ctx_get (ctx_, ZMQ_THREAD_SCHED_POLICY);
|
||||
assert (rc == TEST_POLICY);
|
||||
|
||||
|
||||
// test priority:
|
||||
@ -110,6 +112,8 @@ void test_ctx_thread_opts (void *ctx_)
|
||||
ctx_, ZMQ_THREAD_PRIORITY,
|
||||
1 /* any positive value different than the default will be ok */);
|
||||
assert (rc == 0);
|
||||
rc = zmq_ctx_get (ctx_, ZMQ_THREAD_PRIORITY);
|
||||
assert (rc == 1);
|
||||
}
|
||||
|
||||
|
||||
@ -143,6 +147,8 @@ void test_ctx_thread_opts (void *ctx_)
|
||||
|
||||
rc = zmq_ctx_set (ctx_, ZMQ_THREAD_NAME_PREFIX, 1234);
|
||||
assert (rc == 0);
|
||||
rc = zmq_ctx_get (ctx_, ZMQ_THREAD_NAME_PREFIX);
|
||||
assert (rc == 1234);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user