Msg_Thread constructor now has no_threads which is the number of
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 12 Sep 2005 20:09:14 +0000 (20:09 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 12 Sep 2005 20:09:14 +0000 (20:09 +0000)
worker threads to use (used to be one only).

src/msg-thread.cpp
src/msg-thread.h
src/t-server.cpp
src/tstthreads.cpp
src/yaz-proxy.cpp

index 0b6d91c..e277584 100644 (file)
@@ -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; i<m_no_threads; i++)
+        pthread_create(&m_thread_id[i], 0, tfunc, this);
 }
 
 Msg_Thread::~Msg_Thread()
@@ -94,7 +99,10 @@ Msg_Thread::~Msg_Thread()
     pthread_cond_signal(&m_cond_input_data);
     pthread_mutex_unlock(&m_mutex_input_data);
     
-    pthread_join(m_thread_id, 0);
+    int i;
+    for (i = 0; i<m_no_threads; i++)
+        pthread_join(m_thread_id[i], 0);
+    delete [] m_thread_id;
 
     m_SocketObservable->deleteObserver(this);
 
index 56722d6..47316d0 100644 (file)
@@ -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;
index ca63da7..ad88d02 100644 (file)
@@ -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 <stdlib.h>
@@ -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)
index b562d65..97ef2c8 100644 (file)
@@ -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)
index 93aab1c..9915853 100644 (file)
@@ -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;
 }