diff --git a/doc/zmq_ctx_get.txt b/doc/zmq_ctx_get.txt index 1ff6871f..e69ff9fa 100644 --- a/doc/zmq_ctx_get.txt +++ b/doc/zmq_ctx_get.txt @@ -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 diff --git a/src/ctx.cpp b/src/ctx.cpp index 30aa443e..67acf03f 100644 --- a/src/ctx.cpp +++ b/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_); diff --git a/src/ctx.hpp b/src/ctx.hpp index 5146ce76..dd17b666 100644 --- a/src/ctx.hpp +++ b/src/ctx.hpp @@ -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. diff --git a/tests/test_ctx_options.cpp b/tests/test_ctx_options.cpp index e7505159..794c1724 100644 --- a/tests/test_ctx_options.cpp +++ b/tests/test_ctx_options.cpp @@ -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 }