From: Adam Dickmeiss Date: Mon, 12 Sep 2005 20:09:14 +0000 (+0000) Subject: Msg_Thread constructor now has no_threads which is the number of X-Git-Tag: YAZPROXY.1.1.0.2~52 X-Git-Url: http://git.indexdata.com/?p=yazproxy-moved-to-github.git;a=commitdiff_plain;h=32e20aac80d955f4eaa2b78dfd99788bbc02edb2 Msg_Thread constructor now has no_threads which is the number of worker threads to use (used to be one only). --- diff --git a/src/msg-thread.cpp b/src/msg-thread.cpp index 0b6d91c..e277584 100644 --- a/src/msg-thread.cpp +++ b/src/msg-thread.cpp @@ -1,4 +1,4 @@ -/* $Id: msg-thread.cpp,v 1.7 2005-08-15 12:51:57 adam Exp $ +/* $Id: msg-thread.cpp,v 1.8 2005-09-12 20:09:14 adam Exp $ Copyright (c) 1998-2005, Index Data. This file is part of the yaz-proxy. @@ -73,7 +73,7 @@ static void *tfunc(void *p) } -Msg_Thread::Msg_Thread(ISocketObservable *obs) +Msg_Thread::Msg_Thread(ISocketObservable *obs, int no_threads) : m_SocketObservable(obs) { pipe(m_fd); @@ -84,7 +84,12 @@ Msg_Thread::Msg_Thread(ISocketObservable *obs) pthread_mutex_init(&m_mutex_input_data, 0); pthread_cond_init(&m_cond_input_data, 0); pthread_mutex_init(&m_mutex_output_data, 0); - pthread_create(&m_thread_id, 0, tfunc, this); + + m_no_threads = no_threads; + m_thread_id = new pthread_t[no_threads]; + int i; + for (i = 0; ideleteObserver(this); diff --git a/src/msg-thread.h b/src/msg-thread.h index 56722d6..47316d0 100644 --- a/src/msg-thread.h +++ b/src/msg-thread.h @@ -1,4 +1,4 @@ -/* $Id: msg-thread.h,v 1.5 2005-08-15 12:51:57 adam Exp $ +/* $Id: msg-thread.h,v 1.6 2005-09-12 20:09:14 adam Exp $ Copyright (c) 1998-2005, Index Data. This file is part of the yaz-proxy. @@ -55,7 +55,7 @@ class Msg_Thread_Queue { class Msg_Thread : public yazpp_1::ISocketObserver { public: - Msg_Thread(yazpp_1::ISocketObservable *obs); + Msg_Thread(yazpp_1::ISocketObservable *obs, int no_threads); virtual ~Msg_Thread(); void socketNotify(int event); void put(IMsg_Thread *m); @@ -64,7 +64,8 @@ class Msg_Thread : public yazpp_1::ISocketObserver { int m_fd[2]; private: yazpp_1::ISocketObservable *m_SocketObservable; - pthread_t m_thread_id; + int m_no_threads; + pthread_t *m_thread_id; Msg_Thread_Queue m_input; Msg_Thread_Queue m_output; pthread_mutex_t m_mutex_input_data; diff --git a/src/t-server.cpp b/src/t-server.cpp index ca63da7..ad88d02 100644 --- a/src/t-server.cpp +++ b/src/t-server.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2005, Index Data. * See the file LICENSE for details. * - * $Id: t-server.cpp,v 1.3 2005-09-11 20:06:54 adam Exp $ + * $Id: t-server.cpp,v 1.4 2005-09-12 20:09:14 adam Exp $ */ #include @@ -184,14 +184,18 @@ int main(int argc, char **argv) int ret; const char *addr = "tcp:@:9999"; char *apdu_log = 0; + int no_threads = 1; - while ((ret = options("a:v:T", argv, argc, &arg)) != -2) + while ((ret = options("n:a:v:T", argv, argc, &arg)) != -2) { switch (ret) { case 0: addr = xstrdup(arg); break; + case 'n': + no_threads = atoi(arg); + break; case 'a': apdu_log = xstrdup(arg); break; @@ -213,7 +217,7 @@ int main(int argc, char **argv) MyServer *z = 0; - Msg_Thread *my_thread = new Msg_Thread(&mySocketManager); + Msg_Thread *my_thread = new Msg_Thread(&mySocketManager, no_threads); #if YAZ_POSIX_THREADS if (thread_flag) diff --git a/src/tstthreads.cpp b/src/tstthreads.cpp index b562d65..97ef2c8 100644 --- a/src/tstthreads.cpp +++ b/src/tstthreads.cpp @@ -1,4 +1,4 @@ -/* $Id: tstthreads.cpp,v 1.6 2005-06-25 15:58:33 adam Exp $ +/* $Id: tstthreads.cpp,v 1.7 2005-09-12 20:09:14 adam Exp $ Copyright (c) 1998-2005, Index Data. This file is part of the yaz-proxy. @@ -85,7 +85,7 @@ int main(int argc, char **argv) { SocketManager mySocketManager; - Msg_Thread m(&mySocketManager); + Msg_Thread m(&mySocketManager, 1); My_Timer_Thread t(&mySocketManager, &m) ; int i = 0; while (++i < 5 && mySocketManager.processEvent() > 0) diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index 93aab1c..9915853 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -1,4 +1,4 @@ -/* $Id: yaz-proxy.cpp,v 1.35 2005-08-15 12:53:08 adam Exp $ +/* $Id: yaz-proxy.cpp,v 1.36 2005-09-12 20:09:14 adam Exp $ Copyright (c) 1998-2005, Index Data. This file is part of the yaz-proxy. @@ -421,7 +421,7 @@ IPDU_Observer *Yaz_Proxy::sessionNotify(IPDU_Observable m_proxy_negotiation_lang); // create thread object the first time we get an incoming connection if (!m_my_thread) - m_my_thread = new Msg_Thread(m_socket_observable); + m_my_thread = new Msg_Thread(m_socket_observable, 1); new_proxy->m_my_thread = m_my_thread; return new_proxy; }