Browse Source

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

master
Georg Hopp 17 years ago
parent
commit
9f9d937905
  1. 2
      configure.ac
  2. 4
      include/scot/posix/thread.h
  3. 2
      include/scot/stream.h
  4. 2
      include/scot/win32/scot_types.h
  5. 6
      include/scot/win32/thread.h
  6. 9
      src/Makefile.am
  7. 2
      src/event_listener.c
  8. 2
      src/exception.c
  9. 14
      src/posix/thread.c
  10. 4
      src/stream.c
  11. 10
      src/stream_pool_base.c
  12. 4
      src/win32/stream_ctl.c
  13. 34
      src/win32/thread.c
  14. 10
      test/Makefile.am

2
configure.ac

@ -54,6 +54,8 @@ AC_SUBST(SOCK_LIB)
AC_SUBST(THREAD_LIB)
AC_SUBST(THREAD_CFLAGS)
AM_PROG_CC_C_O
AM_CONDITIONAL(USE_THREADS, test "x$thread" != "x")
AM_CONDITIONAL(PTHREAD, test "x$thread" == "xPTHREAD")
AM_CONDITIONAL(WTHREAD, test "x$thread" == "xWTHREAD")

4
include/scot/posix/thread.h

@ -47,7 +47,7 @@
#define THREAD_ID pthread_self ()
#define SELF_THREAD pthread_self ()
#define THREAD_EQUAL pthread_equal
#define NEW_THREAD(th,f, a) thread_new ((th), (f), (a))
#define NEW_THREAD(f, a) thread_new ((f), (a))
#define END_THREAD thread_end
#define DETACH_THREAD(thread) pthread_detach ((thread))
#define CANCEL_THREAD(thread) pthread_cancel ((thread))
@ -89,7 +89,7 @@
typedef T_PROC_RET (*scot_thread_entry_fptr) (void *);
void thread_new (THREAD_T *, T_PROC_RET (*)(void *), void*);
THREAD_T thread_new (T_PROC_RET (*)(void *), void*);
int thread_join (THREAD_T, uint32_t);
void thread_end (THREAD_T, uint32_t);
void thread_mutex_new (THREAD_MUTEX_T *);

2
include/scot/stream.h

@ -42,7 +42,7 @@
#define SCOT_STREAM_TYPE_INOTIFY 4
#ifdef WIN32
# include <Windows.h>
# include <windows.h>
# include <scot/stream_win.h>
# define SCOT_FILE_READ win_file_read
#else

2
include/scot/win32/scot_types.h

@ -1,6 +1,6 @@
#ifndef SCOT_TYPES_H
#define SCOT_TYPES_H
#include <Windows.h>
#include <windows.h>
#endif /* SCOT_TYPES_H */

6
include/scot/win32/thread.h

@ -40,7 +40,9 @@
#define THREAD_ID_T DWORD
#define THREAD_ID GetCurrentThreadId ()
#define SELF_THREAD GetCurrentThread ()
#define NEW_THREAD thread_new
#define THREAD_EQUAL(a, b) thread_equal ((a), (b))
#define NEW_THREAD(f, a) thread_new ((f), (a))
#define END_THREAD thread_end
#define CANCEL_THREAD(thread) (! TerminateThread ((thread), -1))
#define EXIT_THREAD(retval) _endthreadex ((DWORD) (retval))
#define JOIN_THREAD thread_join
@ -73,6 +75,8 @@ typedef T_PROC_RET (*scot_thread_entry_fptr) (void *);
THREAD_T thread_new (T_PROC_RET (*)(void *), void*);
int thread_join (THREAD_T, unsigned int);
void thread_end (THREAD_T, unsigned int);
int thread_equal (THREAD_T, THREAD_T);
THREAD_MUTEX_T thread_mutex_new (void);
int thread_mutex_lock (THREAD_MUTEX_T *);

9
src/Makefile.am

@ -6,12 +6,19 @@ LIBS += @THREAD_LIB@ @SOCK_LIB@
INCLUDES = -I../include @INOTIFY_INCLUDES@
#libscot_source = scot_common.c cmdla.c \
# list.c stack.c queue.c \
# thread.c dir.c \
# exception.c scot_exceptions.c \
# stream.c stream_ctl.c socket.c socket_in.c \
# event.c event_listener.c
libscot_source = scot_common.c cmdla.c \
list.c stack.c queue.c \
thread.c dir.c \
exception.c scot_exceptions.c \
stream.c stream_ctl.c socket.c socket_in.c \
event.c event_listener.c \
event.c event_listener.c \
stream_pool_base.c stream_pool_management.c \
stream_pool_fraction.c spf_thread_impl.c

2
src/event_listener.c

@ -62,7 +62,7 @@ scot_event_listener_fini (
void
scot_event_listener_start (struct scot_event_listener * l)
{
NEW_THREAD (&l->thread_handle, l->el_entry_func, l);
l->thread_handle = NEW_THREAD (l->el_entry_func, l);
}
void

2
src/exception.c

@ -138,7 +138,7 @@ static
int
compare_thread_excenv_t (const thread_excenv_t *a , const thread_excenv_t *b)
{
return ! THREAD_EQUAL (*(THREAD_T *) a, *(THREAD_T *) b);
return ! THREAD_EQUAL (a->thread_handle, b->thread_handle);
}
/**

14
src/posix/thread.c

@ -36,13 +36,17 @@ join_thread (void * arg)
return NULL;
}
void
thread_new (THREAD_T * handle, T_PROC_RET (*t_proc)(void *), void* arg)
THREAD_T
thread_new (T_PROC_RET (*t_proc)(void *), void* arg)
{
if (pthread_create (handle, NULL, t_proc, arg) != 0)
THREAD_T handle;
if (pthread_create (&handle, NULL, t_proc, arg) != 0)
{
SCOT_MEM_ZERO (handle, sizeof (THREAD_T));
SCOT_MEM_ZERO (&handle, sizeof (THREAD_T));
}
return handle;
}
void
@ -103,7 +107,7 @@ thread_join (THREAD_T thread, uint32_t timeout)
perror ("problem achiving mutex within join");
}
NEW_THREAD (&join_thr, join_thread, (void *) &join_cond);
join_thr = NEW_THREAD (join_thread, (void *) &join_cond);
status = pthread_cond_timedwait (
&(join_cond.join_alarm_cond),

4
src/stream.c

@ -5,8 +5,8 @@
#ifndef WIN32
# include <sys/ioctl.h>
#else
# include <Windows.h>
# include <Winsock2.h>
# include <windows.h>
# include <winsock2.h>
#endif
#include <scot/stream.h>

10
src/stream_pool_base.c

@ -124,7 +124,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp)
f_node = list_scot_sp_fraction_next (f_node);
f = list_scot_sp_fraction_retrive (f_node);
NEW_THREAD (&f->thread_handle, f->spf_entry_func, f);
f->thread_handle = NEW_THREAD (f->spf_entry_func, f);
f->thread_run_flg = 1;
}
@ -150,7 +150,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp)
END_THREAD (f->thread_handle, INFINITE);
thread_exc_end (f->thread_handle);
}
NEW_THREAD (&f->thread_handle, f->spf_entry_func, f);
f->thread_handle = NEW_THREAD (f->spf_entry_func, f);
f->thread_run_flg = 1;
}
break;
@ -164,7 +164,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp)
if (f->thread_run_flg == 0)
{
NEW_THREAD (&f->thread_handle, f->spf_entry_func, f);
f->thread_handle = NEW_THREAD (f->spf_entry_func, f);
f->thread_run_flg = 1;
}
}
@ -193,7 +193,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp)
END_THREAD (f->thread_handle, INFINITE);
thread_exc_end (f->thread_handle);
}
NEW_THREAD (&f->thread_handle, f->spf_entry_func, f);
f->thread_handle = NEW_THREAD (f->spf_entry_func, f);
f->thread_run_flg = 1;
break;
@ -201,7 +201,7 @@ scot_stream_pool_main_loop (struct scot_stream_pool * sp)
f = (struct scot_sp_fraction *) sp->cmd_arg;
if (f->thread_run_flg == 0)
{
NEW_THREAD (&f->thread_handle, f->spf_entry_func, f);
f->thread_handle = NEW_THREAD (f->spf_entry_func, f);
f->thread_run_flg = 1;
}
break;

4
src/win32/stream_ctl.c

@ -1,5 +1,5 @@
#include <Windows.h>
#include <Winsock2.h>
#include <windows.h>
#include <winsock2.h>
#include <scot/stream.h>
#include <scot/exception.h>

34
src/win32/thread.c

@ -1,9 +1,39 @@
#include <scot/thread.h>
#include <scot/exception.h>
THREAD_T
int
thread_equal (THREAD_T a, THREAD_T b)
{
return (a == b);
}
void
thread_end (THREAD_T thread, unsigned int timeout)
{
int err;
err = CANCEL_THREAD (thread);
if (err != 0)
THROW (EXC (EXC_ERROR,
err,
"[EVENT_SOURCE_THREAD]cancel request failed"));
err = JOIN_THREAD (thread, timeout);
if (err == JOIN_TIMEOUT)
THROW (EXC (EXC_ERROR,
err,
"[EVENT_SOURCE_THREAD]timeout exceeded while waiting "
"for threads end"));
if (err == JOIN_ERROR)
THROW (EXC (EXC_ERROR,
err,
"[EVENT_SOURCE_THREAD]failure on waiting for threads end"));
}
THREAD_T
thread_new (T_PROC_RET (*t_proc)(void *), void* arg)
{
return (_beginthreadex (NULL, 0, t_proc, arg, 0, NULL));
return _beginthreadex (NULL, 0, t_proc, arg, 0, NULL);
}
int

10
test/Makefile.am

@ -1,9 +1,9 @@
LTLIBS = $(INTLLIBS) @SOCK_LIB@
LIBS = $(INTLLIBS) @SOCK_LIB@
PROGS = scot_test list_test exc_test \
tcp_socket_serv tcp_socket_clie \
multiserv
PROGS = scot_test list_test exc_test
#PROGS = scot_test list_test exc_test
INCLUDES = -I../include @INOTIFY_INCLUDES@
@ -12,7 +12,9 @@ PROGS += exc_thr_test
endif
if !WIN32
PROGS += unx_socket_serv unx_socket_clie fs_events
PROGS += unx_socket_serv unx_socket_clie fs_events \
tcp_socket_serv tcp_socket_clie \
multiserv
endif
bin_PROGRAMS = $(PROGS)

Loading…
Cancel
Save