Commit 9f9d937905ae906858dfa47ed60535b411895efd

Authored by Georg Hopp
1 parent e35a763a

now all compiles under linux...need replacement for CONDITION_VARIABLE for win32

... ... @@ -54,6 +54,8 @@ AC_SUBST(SOCK_LIB)
54 54 AC_SUBST(THREAD_LIB)
55 55 AC_SUBST(THREAD_CFLAGS)
56 56
  57 +AM_PROG_CC_C_O
  58 +
57 59 AM_CONDITIONAL(USE_THREADS, test "x$thread" != "x")
58 60 AM_CONDITIONAL(PTHREAD, test "x$thread" == "xPTHREAD")
59 61 AM_CONDITIONAL(WTHREAD, test "x$thread" == "xWTHREAD")
... ...
... ... @@ -47,7 +47,7 @@
47 47 #define THREAD_ID pthread_self ()
48 48 #define SELF_THREAD pthread_self ()
49 49 #define THREAD_EQUAL pthread_equal
50   -#define NEW_THREAD(th,f, a) thread_new ((th), (f), (a))
  50 +#define NEW_THREAD(f, a) thread_new ((f), (a))
51 51 #define END_THREAD thread_end
52 52 #define DETACH_THREAD(thread) pthread_detach ((thread))
53 53 #define CANCEL_THREAD(thread) pthread_cancel ((thread))
... ... @@ -89,7 +89,7 @@
89 89
90 90 typedef T_PROC_RET (*scot_thread_entry_fptr) (void *);
91 91
92   -void thread_new (THREAD_T *, T_PROC_RET (*)(void *), void*);
  92 +THREAD_T thread_new (T_PROC_RET (*)(void *), void*);
93 93 int thread_join (THREAD_T, uint32_t);
94 94 void thread_end (THREAD_T, uint32_t);
95 95 void thread_mutex_new (THREAD_MUTEX_T *);
... ...
... ... @@ -42,7 +42,7 @@
42 42 #define SCOT_STREAM_TYPE_INOTIFY 4
43 43
44 44 #ifdef WIN32
45   -# include <Windows.h>
  45 +# include <windows.h>
46 46 # include <scot/stream_win.h>
47 47 # define SCOT_FILE_READ win_file_read
48 48 #else
... ...
1 1 #ifndef SCOT_TYPES_H
2 2 #define SCOT_TYPES_H
3 3
4   -#include <Windows.h>
  4 +#include <windows.h>
5 5
6 6 #endif /* SCOT_TYPES_H */
... ...
... ... @@ -40,7 +40,9 @@
40 40 #define THREAD_ID_T DWORD
41 41 #define THREAD_ID GetCurrentThreadId ()
42 42 #define SELF_THREAD GetCurrentThread ()
43   -#define NEW_THREAD thread_new
  43 +#define THREAD_EQUAL(a, b) thread_equal ((a), (b))
  44 +#define NEW_THREAD(f, a) thread_new ((f), (a))
  45 +#define END_THREAD thread_end
44 46 #define CANCEL_THREAD(thread) (! TerminateThread ((thread), -1))
45 47 #define EXIT_THREAD(retval) _endthreadex ((DWORD) (retval))
46 48 #define JOIN_THREAD thread_join
... ... @@ -73,6 +75,8 @@ typedef T_PROC_RET (*scot_thread_entry_fptr) (void *);
73 75
74 76 THREAD_T thread_new (T_PROC_RET (*)(void *), void*);
75 77 int thread_join (THREAD_T, unsigned int);
  78 +void thread_end (THREAD_T, unsigned int);
  79 +int thread_equal (THREAD_T, THREAD_T);
76 80 THREAD_MUTEX_T thread_mutex_new (void);
77 81 int thread_mutex_lock (THREAD_MUTEX_T *);
78 82
... ...
... ... @@ -6,12 +6,19 @@ LIBS += @THREAD_LIB@ @SOCK_LIB@
6 6
7 7 INCLUDES = -I../include @INOTIFY_INCLUDES@
8 8
  9 +#libscot_source = scot_common.c cmdla.c \
  10 +# list.c stack.c queue.c \
  11 +# thread.c dir.c \
  12 +# exception.c scot_exceptions.c \
  13 +# stream.c stream_ctl.c socket.c socket_in.c \
  14 +# event.c event_listener.c
  15 +
9 16 libscot_source = scot_common.c cmdla.c \
10 17 list.c stack.c queue.c \
11 18 thread.c dir.c \
12 19 exception.c scot_exceptions.c \
13 20 stream.c stream_ctl.c socket.c socket_in.c \
14   - event.c event_listener.c \
  21 + event.c event_listener.c \
15 22 stream_pool_base.c stream_pool_management.c \
16 23 stream_pool_fraction.c spf_thread_impl.c
17 24
... ...
... ... @@ -62,7 +62,7 @@ scot_event_listener_fini (
62 62 void
63 63 scot_event_listener_start (struct scot_event_listener * l)
64 64 {
65   - NEW_THREAD (&l->thread_handle, l->el_entry_func, l);
  65 + l->thread_handle = NEW_THREAD (l->el_entry_func, l);
66 66 }
67 67
68 68 void
... ...
... ... @@ -138,7 +138,7 @@ static
138 138 int
139 139 compare_thread_excenv_t (const thread_excenv_t *a , const thread_excenv_t *b)
140 140 {
141   - return ! THREAD_EQUAL (*(THREAD_T *) a, *(THREAD_T *) b);
  141 + return ! THREAD_EQUAL (a->thread_handle, b->thread_handle);
142 142 }
143 143
144 144 /**
... ...
... ... @@ -36,13 +36,17 @@ join_thread (void * arg)
36 36 return NULL;
37 37 }
38 38
39   -void
40   -thread_new (THREAD_T * handle, T_PROC_RET (*t_proc)(void *), void* arg)
  39 +THREAD_T
  40 +thread_new (T_PROC_RET (*t_proc)(void *), void* arg)
41 41 {
42   - if (pthread_create (handle, NULL, t_proc, arg) != 0)
  42 + THREAD_T handle;
  43 +
  44 + if (pthread_create (&handle, NULL, t_proc, arg) != 0)
43 45 {
44   - SCOT_MEM_ZERO (handle, sizeof (THREAD_T));
  46 + SCOT_MEM_ZERO (&handle, sizeof (THREAD_T));
45 47 }
  48 +
  49 + return handle;
46 50 }
47 51
48 52 void
... ... @@ -103,7 +107,7 @@ thread_join (THREAD_T thread, uint32_t timeout)
103 107 perror ("problem achiving mutex within join");
104 108 }
105 109
106   - NEW_THREAD (&join_thr, join_thread, (void *) &join_cond);
  110 + join_thr = NEW_THREAD (join_thread, (void *) &join_cond);
107 111
108 112 status = pthread_cond_timedwait (
109 113 &(join_cond.join_alarm_cond),
... ...
... ... @@ -5,8 +5,8 @@
5 5 #ifndef WIN32
6 6 # include <sys/ioctl.h>
7 7 #else
8   -# include <Windows.h>
9   -# include <Winsock2.h>
  8 +# include <windows.h>
  9 +# include <winsock2.h>
10 10 #endif
11 11
12 12 #include <scot/stream.h>
... ...
... ... @@ -124,7 +124,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp)
124 124 f_node = list_scot_sp_fraction_next (f_node);
125 125 f = list_scot_sp_fraction_retrive (f_node);
126 126
127   - NEW_THREAD (&f->thread_handle, f->spf_entry_func, f);
  127 + f->thread_handle = NEW_THREAD (f->spf_entry_func, f);
128 128 f->thread_run_flg = 1;
129 129 }
130 130
... ... @@ -150,7 +150,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp)
150 150 END_THREAD (f->thread_handle, INFINITE);
151 151 thread_exc_end (f->thread_handle);
152 152 }
153   - NEW_THREAD (&f->thread_handle, f->spf_entry_func, f);
  153 + f->thread_handle = NEW_THREAD (f->spf_entry_func, f);
154 154 f->thread_run_flg = 1;
155 155 }
156 156 break;
... ... @@ -164,7 +164,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp)
164 164
165 165 if (f->thread_run_flg == 0)
166 166 {
167   - NEW_THREAD (&f->thread_handle, f->spf_entry_func, f);
  167 + f->thread_handle = NEW_THREAD (f->spf_entry_func, f);
168 168 f->thread_run_flg = 1;
169 169 }
170 170 }
... ... @@ -193,7 +193,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp)
193 193 END_THREAD (f->thread_handle, INFINITE);
194 194 thread_exc_end (f->thread_handle);
195 195 }
196   - NEW_THREAD (&f->thread_handle, f->spf_entry_func, f);
  196 + f->thread_handle = NEW_THREAD (f->spf_entry_func, f);
197 197 f->thread_run_flg = 1;
198 198 break;
199 199
... ... @@ -201,7 +201,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp)
201 201 f = (struct scot_sp_fraction *) sp->cmd_arg;
202 202 if (f->thread_run_flg == 0)
203 203 {
204   - NEW_THREAD (&f->thread_handle, f->spf_entry_func, f);
  204 + f->thread_handle = NEW_THREAD (f->spf_entry_func, f);
205 205 f->thread_run_flg = 1;
206 206 }
207 207 break;
... ...
1   -#include <Windows.h>
2   -#include <Winsock2.h>
  1 +#include <windows.h>
  2 +#include <winsock2.h>
3 3
4 4 #include <scot/stream.h>
5 5 #include <scot/exception.h>
... ...
1 1 #include <scot/thread.h>
  2 +#include <scot/exception.h>
2 3
3   -THREAD_T
  4 +int
  5 +thread_equal (THREAD_T a, THREAD_T b)
  6 +{
  7 + return (a == b);
  8 +}
  9 +
  10 +void
  11 +thread_end (THREAD_T thread, unsigned int timeout)
  12 +{
  13 + int err;
  14 +
  15 + err = CANCEL_THREAD (thread);
  16 + if (err != 0)
  17 + THROW (EXC (EXC_ERROR,
  18 + err,
  19 + "[EVENT_SOURCE_THREAD]cancel request failed"));
  20 +
  21 + err = JOIN_THREAD (thread, timeout);
  22 + if (err == JOIN_TIMEOUT)
  23 + THROW (EXC (EXC_ERROR,
  24 + err,
  25 + "[EVENT_SOURCE_THREAD]timeout exceeded while waiting "
  26 + "for threads end"));
  27 + if (err == JOIN_ERROR)
  28 + THROW (EXC (EXC_ERROR,
  29 + err,
  30 + "[EVENT_SOURCE_THREAD]failure on waiting for threads end"));
  31 +}
  32 +
  33 +THREAD_T
4 34 thread_new (T_PROC_RET (*t_proc)(void *), void* arg)
5 35 {
6   - return (_beginthreadex (NULL, 0, t_proc, arg, 0, NULL));
  36 + return _beginthreadex (NULL, 0, t_proc, arg, 0, NULL);
7 37 }
8 38
9 39 int
... ...
1 1 LTLIBS = $(INTLLIBS) @SOCK_LIB@
2 2 LIBS = $(INTLLIBS) @SOCK_LIB@
3 3
4   -PROGS = scot_test list_test exc_test \
5   - tcp_socket_serv tcp_socket_clie \
6   - multiserv
  4 +PROGS = scot_test list_test exc_test
  5 +
  6 +#PROGS = scot_test list_test exc_test
7 7
8 8 INCLUDES = -I../include @INOTIFY_INCLUDES@
9 9
... ... @@ -12,7 +12,9 @@ PROGS += exc_thr_test
12 12 endif
13 13
14 14 if !WIN32
15   -PROGS += unx_socket_serv unx_socket_clie fs_events
  15 +PROGS += unx_socket_serv unx_socket_clie fs_events \
  16 + tcp_socket_serv tcp_socket_clie \
  17 + multiserv
16 18 endif
17 19
18 20 bin_PROGRAMS = $(PROGS)
... ...
Please register or login to post a comment