Revision 758

branches/threaded2/tests/nst/adthread.h (revision 758)
1
#if !defined(__ADPTHREAD__)
2
#define __ADPTHREAD__ 
3
#include <unistd.h>     /* Symbolic Constants */
4
#include <sys/types.h>  /* Primitive System Data Types */ 
5
#include <errno.h>      /* Errors */
6
#include <stdio.h>      /* Input/Output */
7
#include <stdlib.h>     /* General Utilities */
8
#include <pthread.h>    /* POSIX Threads */
9
#include <string.h>     /* String handling */
10

  
11
/* struct to hold data to be passed to a thread
12
 *    this shows how multiple data items can be passed to a thread */
13
  union a_union 
14
  {
15
    char * p;
16
    double d;
17
  };
18
 //     //
19
 // /* prototype for thread routine */
20
 void admb_thread(void * ptr);
21
 // 
22
  class thread_data
23
  {
24
  public:
25
    static __thread int id;
26
    int thread_no;
27
    int bufsize;
28
    pthread_mutex_t *inlock;
29
    pthread_mutex_t *outlock;
30
    void * transfer_buffer;
31
    char message[100];
32
  };
33
 // 
34
 extern const int NSLAVES;
35
 // 
36
 typedef char * pchar;
37
 // 
38
  class adpthread_manager
39
  {
40
  public:
41
    char ** transfer_buffer;
42
    char ** buffend;
43
    int nslaves;
44
    int bs;
45
    int * mflag;
46
    int * sflag;
47
    pthread_mutex_t * smutex;
48
    pthread_cond_t * scondition;
49
    pthread_cond_t *mcondition;
50
    pthread_t * thread1;  /* thread variables */
51
    adpthread_manager(int ns,int bs)
52
    {
53
      int i;
54
      nslaves=ns;
55
      transfer_buffer=new pchar[ns];
56
      buffend=new pchar[ns];
57
      transfer_buffer--;
58
      buffend--;
59
      for (i=1;i<=ns;i++)
60
      {
61
        transfer_buffer[i]=new char[bs];
62
        buffend[i]=transfer_buffer[i]+bs-1;
63
      }
64
      mflag=new int[ns];
65
      mflag--;
66
      sflag=new int[ns];
67
      sflag--;
68
      smutex=new pthread_mutex_t[ns];
69
      smutex--;
70
      for (i=1;i<=ns;i++)
71
      {
72
        pthread_mutex_init(smutex+i,NULL);
73
      }
74
      scondition=new pthread_cond_t[ns];
75
      scondition--;
76
      mcondition=new pthread_cond_t[ns];
77
      mcondition--;
78
      thread1=new pthread_t[ns];
79
      thread1--;
80
    }
81
    void send_double_to_slave(const double &x,int sno);
82
    void send_double_to_master(double &x,int sno);
83
    double get_double_from_slave(int sno);
84
    double get_double_from_master(int sno);
85
    void send_dvariable_to_slave(const prevariable &x,int sno);
86
    void send_dvariable_to_master(const prevariable &x,int sno);
87
    dvariable get_dvariable_from_slave(int sno);
88
    dvariable get_dvariable_from_master(int sno);
89
    void send_dvector_to_slave(const dvector &x,int sno);
90
    void send_dvector_to_master(const dvector &x,int sno);
91
    dvector get_dvector_from_slave(int sno);
92
    dvector get_dvector_from_master(int sno);
93
    dvar_vector get_dvar_vector_from_slave(int sno);
94
    dvar_vector get_dvar_vector_from_master(int sno);
95
    void send_dvar_vector_to_slave(const dvar_vector &x,int sno);
96
    void send_dvar_vector_to_master(const dvar_vector &x,int sno);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff