0
0
mirror of https://github.com/zeromq/libzmq.git synced 2025-01-15 10:18:01 +08: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:
Luca Boccassi 2018-11-18 12:13:19 +00:00
parent 92cf6c6451
commit 22c3ecc458
4 changed files with 45 additions and 2 deletions

View File

@ -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. 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 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 The 'ZMQ_MSG_T_SIZE' argument returns the size of the zmq_msg_t structure at

View File

@ -271,8 +271,7 @@ int zmq::ctx_t::get (int option_)
else if (option_ == ZMQ_ZERO_COPY_RECV) { else if (option_ == ZMQ_ZERO_COPY_RECV) {
rc = _zero_copy; rc = _zero_copy;
} else { } else {
errno = EINVAL; rc = thread_ctx_t::get (option_);
rc = -1;
} }
return rc; return rc;
} }
@ -467,6 +466,25 @@ int zmq::thread_ctx_t::set (int option_, int optval_)
return rc; 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_) void zmq::ctx_t::send_command (uint32_t tid_, const command_t &command_)
{ {
_slots[tid_]->send (command_); _slots[tid_]->send (command_);

View File

@ -70,6 +70,7 @@ class thread_ctx_t
void start_thread (thread_t &thread_, thread_fn *tfn_, void *arg_) const; void start_thread (thread_t &thread_, thread_fn *tfn_, void *arg_) const;
int set (int option_, int optval_); int set (int option_, int optval_);
int get (int option_);
protected: protected:
// Synchronisation of access to context options. // Synchronisation of access to context options.

View File

@ -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): // 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); rc = zmq_ctx_set (ctx_, ZMQ_THREAD_SCHED_POLICY, TEST_POLICY);
assert (rc == 0); assert (rc == 0);
rc = zmq_ctx_get (ctx_, ZMQ_THREAD_SCHED_POLICY);
assert (rc == TEST_POLICY);
// test priority: // test priority:
@ -110,6 +112,8 @@ void test_ctx_thread_opts (void *ctx_)
ctx_, ZMQ_THREAD_PRIORITY, ctx_, ZMQ_THREAD_PRIORITY,
1 /* any positive value different than the default will be ok */); 1 /* any positive value different than the default will be ok */);
assert (rc == 0); 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); rc = zmq_ctx_set (ctx_, ZMQ_THREAD_NAME_PREFIX, 1234);
assert (rc == 0); assert (rc == 0);
rc = zmq_ctx_get (ctx_, ZMQ_THREAD_NAME_PREFIX);
assert (rc == 1234);
#endif #endif
} }