diff options
Diffstat (limited to 'cpp/src/qpid')
| -rw-r--r-- | cpp/src/qpid/broker/Broker.cpp | 3 | ||||
| -rw-r--r-- | cpp/src/qpid/sys/SystemInfo.cpp | 35 | ||||
| -rw-r--r-- | cpp/src/qpid/sys/SystemInfo.h | 44 |
3 files changed, 82 insertions, 0 deletions
diff --git a/cpp/src/qpid/broker/Broker.cpp b/cpp/src/qpid/broker/Broker.cpp index a02ec432f6..68590d3331 100644 --- a/cpp/src/qpid/broker/Broker.cpp +++ b/cpp/src/qpid/broker/Broker.cpp @@ -39,6 +39,7 @@ #include "qpid/sys/ConnectionInputHandler.h" #include "qpid/sys/ConnectionInputHandlerFactory.h" #include "qpid/sys/TimeoutHandler.h" +#include "qpid/sys/SystemInfo.h" #include <boost/bind.hpp> @@ -68,6 +69,8 @@ Broker::Options::Options(const std::string& name) : mgmtPubInterval(10), ack(100) { + int c = sys::SystemInfo::concurrency(); + if (c > 0) workerThreads=c; addOptions() ("port,p", optValue(port,"PORT"), "Tells the broker to listen on PORT") diff --git a/cpp/src/qpid/sys/SystemInfo.cpp b/cpp/src/qpid/sys/SystemInfo.cpp new file mode 100644 index 0000000000..dcc7ad9985 --- /dev/null +++ b/cpp/src/qpid/sys/SystemInfo.cpp @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "SystemInfo.h" +#include <unistd.h> + +namespace qpid { +namespace sys { + +long SystemInfo::concurrency() { +#ifdef _SC_NPROCESSORS_ONLN // Linux specific. + return sysconf(_SC_NPROCESSORS_ONLN); +#else + return -1; +#endif +} + +}} // namespace qpid::sys diff --git a/cpp/src/qpid/sys/SystemInfo.h b/cpp/src/qpid/sys/SystemInfo.h new file mode 100644 index 0000000000..73c3ca3c17 --- /dev/null +++ b/cpp/src/qpid/sys/SystemInfo.h @@ -0,0 +1,44 @@ +#ifndef QPID_SYS_SYSTEMINFO_H +#define QPID_SYS_SYSTEMINFO_H + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +namespace qpid { +namespace sys { + +/** + * Retrieve information about the system we are running on. + * Results may be dependent on OS/hardware. + */ +class SystemInfo +{ + public: + /** Estimate available concurrency, e.g. number of CPU cores. + * -1 means estimate not available on this platform. + */ + static long concurrency(); +}; + +}} // namespace qpid::sys + + + +#endif /*!QPID_SYS_SYSTEMINFO_H*/ |
