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,6 +54,8 @@ AC_SUBST(SOCK_LIB)
54 AC_SUBST(THREAD_LIB) 54 AC_SUBST(THREAD_LIB)
55 AC_SUBST(THREAD_CFLAGS) 55 AC_SUBST(THREAD_CFLAGS)
56 56
  57 +AM_PROG_CC_C_O
  58 +
57 AM_CONDITIONAL(USE_THREADS, test "x$thread" != "x") 59 AM_CONDITIONAL(USE_THREADS, test "x$thread" != "x")
58 AM_CONDITIONAL(PTHREAD, test "x$thread" == "xPTHREAD") 60 AM_CONDITIONAL(PTHREAD, test "x$thread" == "xPTHREAD")
59 AM_CONDITIONAL(WTHREAD, test "x$thread" == "xWTHREAD") 61 AM_CONDITIONAL(WTHREAD, test "x$thread" == "xWTHREAD")
@@ -47,7 +47,7 @@ @@ -47,7 +47,7 @@
47 #define THREAD_ID pthread_self () 47 #define THREAD_ID pthread_self ()
48 #define SELF_THREAD pthread_self () 48 #define SELF_THREAD pthread_self ()
49 #define THREAD_EQUAL pthread_equal 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 #define END_THREAD thread_end 51 #define END_THREAD thread_end
52 #define DETACH_THREAD(thread) pthread_detach ((thread)) 52 #define DETACH_THREAD(thread) pthread_detach ((thread))
53 #define CANCEL_THREAD(thread) pthread_cancel ((thread)) 53 #define CANCEL_THREAD(thread) pthread_cancel ((thread))
@@ -89,7 +89,7 @@ @@ -89,7 +89,7 @@
89 89
90 typedef T_PROC_RET (*scot_thread_entry_fptr) (void *); 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 int thread_join (THREAD_T, uint32_t); 93 int thread_join (THREAD_T, uint32_t);
94 void thread_end (THREAD_T, uint32_t); 94 void thread_end (THREAD_T, uint32_t);
95 void thread_mutex_new (THREAD_MUTEX_T *); 95 void thread_mutex_new (THREAD_MUTEX_T *);
@@ -42,7 +42,7 @@ @@ -42,7 +42,7 @@
42 #define SCOT_STREAM_TYPE_INOTIFY 4 42 #define SCOT_STREAM_TYPE_INOTIFY 4
43 43
44 #ifdef WIN32 44 #ifdef WIN32
45 -# include <Windows.h> 45 +# include <windows.h>
46 # include <scot/stream_win.h> 46 # include <scot/stream_win.h>
47 # define SCOT_FILE_READ win_file_read 47 # define SCOT_FILE_READ win_file_read
48 #else 48 #else
1 #ifndef SCOT_TYPES_H 1 #ifndef SCOT_TYPES_H
2 #define SCOT_TYPES_H 2 #define SCOT_TYPES_H
3 3
4 -#include <Windows.h> 4 +#include <windows.h>
5 5
6 #endif /* SCOT_TYPES_H */ 6 #endif /* SCOT_TYPES_H */
@@ -40,7 +40,9 @@ @@ -40,7 +40,9 @@
40 #define THREAD_ID_T DWORD 40 #define THREAD_ID_T DWORD
41 #define THREAD_ID GetCurrentThreadId () 41 #define THREAD_ID GetCurrentThreadId ()
42 #define SELF_THREAD GetCurrentThread () 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 #define CANCEL_THREAD(thread) (! TerminateThread ((thread), -1)) 46 #define CANCEL_THREAD(thread) (! TerminateThread ((thread), -1))
45 #define EXIT_THREAD(retval) _endthreadex ((DWORD) (retval)) 47 #define EXIT_THREAD(retval) _endthreadex ((DWORD) (retval))
46 #define JOIN_THREAD thread_join 48 #define JOIN_THREAD thread_join
@@ -73,6 +75,8 @@ typedef T_PROC_RET (*scot_thread_entry_fptr) (void *); @@ -73,6 +75,8 @@ typedef T_PROC_RET (*scot_thread_entry_fptr) (void *);
73 75
74 THREAD_T thread_new (T_PROC_RET (*)(void *), void*); 76 THREAD_T thread_new (T_PROC_RET (*)(void *), void*);
75 int thread_join (THREAD_T, unsigned int); 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 THREAD_MUTEX_T thread_mutex_new (void); 80 THREAD_MUTEX_T thread_mutex_new (void);
77 int thread_mutex_lock (THREAD_MUTEX_T *); 81 int thread_mutex_lock (THREAD_MUTEX_T *);
78 82
@@ -6,12 +6,19 @@ LIBS += @THREAD_LIB@ @SOCK_LIB@ @@ -6,12 +6,19 @@ LIBS += @THREAD_LIB@ @SOCK_LIB@
6 6
7 INCLUDES = -I../include @INOTIFY_INCLUDES@ 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 libscot_source = scot_common.c cmdla.c \ 16 libscot_source = scot_common.c cmdla.c \
10 list.c stack.c queue.c \ 17 list.c stack.c queue.c \
11 thread.c dir.c \ 18 thread.c dir.c \
12 exception.c scot_exceptions.c \ 19 exception.c scot_exceptions.c \
13 stream.c stream_ctl.c socket.c socket_in.c \ 20 stream.c stream_ctl.c socket.c socket_in.c \
14 - event.c event_listener.c \ 21 + event.c event_listener.c \
15 stream_pool_base.c stream_pool_management.c \ 22 stream_pool_base.c stream_pool_management.c \
16 stream_pool_fraction.c spf_thread_impl.c 23 stream_pool_fraction.c spf_thread_impl.c
17 24
@@ -62,7 +62,7 @@ scot_event_listener_fini ( @@ -62,7 +62,7 @@ scot_event_listener_fini (
62 void 62 void
63 scot_event_listener_start (struct scot_event_listener * l) 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 void 68 void
@@ -138,7 +138,7 @@ static @@ -138,7 +138,7 @@ static
138 int 138 int
139 compare_thread_excenv_t (const thread_excenv_t *a , const thread_excenv_t *b) 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,13 +36,17 @@ join_thread (void * arg)
36 return NULL; 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 void 52 void
@@ -103,7 +107,7 @@ thread_join (THREAD_T thread, uint32_t timeout) @@ -103,7 +107,7 @@ thread_join (THREAD_T thread, uint32_t timeout)
103 perror ("problem achiving mutex within join"); 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 status = pthread_cond_timedwait ( 112 status = pthread_cond_timedwait (
109 &(join_cond.join_alarm_cond), 113 &(join_cond.join_alarm_cond),
@@ -5,8 +5,8 @@ @@ -5,8 +5,8 @@
5 #ifndef WIN32 5 #ifndef WIN32
6 # include <sys/ioctl.h> 6 # include <sys/ioctl.h>
7 #else 7 #else
8 -# include <Windows.h>  
9 -# include <Winsock2.h> 8 +# include <windows.h>
  9 +# include <winsock2.h>
10 #endif 10 #endif
11 11
12 #include <scot/stream.h> 12 #include <scot/stream.h>
@@ -124,7 +124,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp) @@ -124,7 +124,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp)
124 f_node = list_scot_sp_fraction_next (f_node); 124 f_node = list_scot_sp_fraction_next (f_node);
125 f = list_scot_sp_fraction_retrive (f_node); 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 f->thread_run_flg = 1; 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,7 +150,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp)
150 END_THREAD (f->thread_handle, INFINITE); 150 END_THREAD (f->thread_handle, INFINITE);
151 thread_exc_end (f->thread_handle); 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 f->thread_run_flg = 1; 154 f->thread_run_flg = 1;
155 } 155 }
156 break; 156 break;
@@ -164,7 +164,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp) @@ -164,7 +164,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp)
164 164
165 if (f->thread_run_flg == 0) 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 f->thread_run_flg = 1; 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,7 +193,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp)
193 END_THREAD (f->thread_handle, INFINITE); 193 END_THREAD (f->thread_handle, INFINITE);
194 thread_exc_end (f->thread_handle); 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 f->thread_run_flg = 1; 197 f->thread_run_flg = 1;
198 break; 198 break;
199 199
@@ -201,7 +201,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp) @@ -201,7 +201,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp)
201 f = (struct scot_sp_fraction *) sp->cmd_arg; 201 f = (struct scot_sp_fraction *) sp->cmd_arg;
202 if (f->thread_run_flg == 0) 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 f->thread_run_flg = 1; 205 f->thread_run_flg = 1;
206 } 206 }
207 break; 207 break;
1 -#include <Windows.h>  
2 -#include <Winsock2.h> 1 +#include <windows.h>
  2 +#include <winsock2.h>
3 3
4 #include <scot/stream.h> 4 #include <scot/stream.h>
5 #include <scot/exception.h> 5 #include <scot/exception.h>
1 #include <scot/thread.h> 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 thread_new (T_PROC_RET (*t_proc)(void *), void* arg) 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 int 39 int
1 LTLIBS = $(INTLLIBS) @SOCK_LIB@ 1 LTLIBS = $(INTLLIBS) @SOCK_LIB@
2 LIBS = $(INTLLIBS) @SOCK_LIB@ 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 INCLUDES = -I../include @INOTIFY_INCLUDES@ 8 INCLUDES = -I../include @INOTIFY_INCLUDES@
9 9
@@ -12,7 +12,9 @@ PROGS += exc_thr_test @@ -12,7 +12,9 @@ PROGS += exc_thr_test
12 endif 12 endif
13 13
14 if !WIN32 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 endif 18 endif
17 19
18 bin_PROGRAMS = $(PROGS) 20 bin_PROGRAMS = $(PROGS)
Please register or login to post a comment