Added suppor /and fix things for SunOS port
git-svn-id: https://svn.pjsip.org/repos/pjproject/main@2 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
parent
0a749f11c7
commit
dd859a62f4
14
Makefile
14
Makefile
|
@ -1,9 +1,7 @@
|
|||
DIRS = pjlib pjsdp pjmedia pjsip
|
||||
|
||||
MAKE_FLAGS := TARGET=$(TARGET)
|
||||
|
||||
ifdef MINSIZE
|
||||
MAKE_FLAGS := $(MAKE_FLAGS) MINSIZE=1
|
||||
MAKE_FLAGS := MINSIZE=1
|
||||
endif
|
||||
|
||||
all clean dep depend distclean doc print realclean:
|
||||
|
@ -21,10 +19,7 @@ LIBS = pjlib/lib/libpj.a pjsdp/lib/libpjsdp.a pjmedia/lib/libpjmedia.a \
|
|||
pjsip/lib/libpjsip_core.a pjsip/lib/libpjsip_ua.a
|
||||
BINS = pjsip/bin/pjsua$(EXE)
|
||||
|
||||
include pjlib/build/make-$(TARGET).inc
|
||||
|
||||
size:
|
||||
@echo 'TARGET=$(TARGET)'
|
||||
@echo -n 'Date: '
|
||||
@date
|
||||
@echo
|
||||
|
@ -41,3 +36,10 @@ size:
|
|||
size $$bin; \
|
||||
done
|
||||
|
||||
dos2unix:
|
||||
for f in `find . | egrep '(mak|h|c|S|s|Makefile)$$'`; do \
|
||||
dos2unix "$$f" > dos2unix.tmp; \
|
||||
cp dos2unix.tmp "$$f"; \
|
||||
done
|
||||
rm -f dos2unix.tmp
|
||||
|
||||
|
|
|
@ -53,3 +53,11 @@ export HOST_NAME := unix
|
|||
#export KERNEL_DIR = /usr/src/uml/linux
|
||||
#export KERNEL_ARCH = ARCH=um
|
||||
|
||||
#
|
||||
# SunOS, sparc, gcc
|
||||
#
|
||||
export MACHINE_NAME := sparc
|
||||
export OS_NAME := sunos
|
||||
export CC_NAME := gcc
|
||||
export HOST_NAME := unix
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
export M_CFLAGS := $(CC_DEF)PJ_M_SPARC=1
|
||||
export M_CXXFLAGS :=
|
||||
export M_LDFLAGS :=
|
||||
export M_SOURCES :=
|
|
@ -0,0 +1,12 @@
|
|||
export OS_CFLAGS := $(CC_DEF)PJ_SUNOS=1
|
||||
|
||||
export OS_CXXFLAGS :=
|
||||
|
||||
export OS_LDFLAGS := $(CC_LIB)pthread$(LIBEXT2) \
|
||||
$(CC_LIB)socket$(LIBEXT2) \
|
||||
$(CC_LIB)rt$(LIBEXT2) \
|
||||
$(CC_LIB)nsl$(LIBEXT2)
|
||||
|
||||
export OS_SOURCES :=
|
||||
|
||||
|
|
@ -148,15 +148,16 @@ depend:
|
|||
$(subst @@,$(DEP_FILE),$(HOST_RM))
|
||||
for F in $(FULL_SRCS); do \
|
||||
if test -f $$F; then \
|
||||
echo -n $(OBJDIR)/ >> $(DEP_FILE); \
|
||||
bash -c "echo -n $(OBJDIR)/" >> $(DEP_FILE); \
|
||||
if gcc -MM $(DEPFLAGS) $$F | sed '/^#/d' >> $(DEP_FILE); then \
|
||||
true; \
|
||||
else \
|
||||
echo 'err:' >> $(DEP_FILE); \
|
||||
rm -f $(DEP_FILE); \
|
||||
exit 1; \
|
||||
fi; \
|
||||
fi; \
|
||||
done
|
||||
done;
|
||||
|
||||
dep: depend
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ export PJLIB_LIB := ../lib/libpj-$(MACHINE_NAME)-$(OS_NAME)-$(CC_NAME)$(LIBEXT)
|
|||
###############################################################################
|
||||
# Gather all flags.
|
||||
#
|
||||
export _CFLAGS := $(CC_CFLAGS) $(OS_CFLAGS) $(HOST_CFLAGS) $(M_CFLAGS) \
|
||||
export _CFLAGS := -O2 $(CC_CFLAGS) $(OS_CFLAGS) $(HOST_CFLAGS) $(M_CFLAGS) \
|
||||
$(CFLAGS) $(CC_INC)../include
|
||||
export _CXXFLAGS:= $(_CFLAGS) $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
|
||||
$(HOST_CXXFLAGS) $(CXXFLAGS)
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
#
|
||||
# PJLIB OS specific configuration for SunOS target.
|
||||
#
|
||||
|
||||
#
|
||||
# PJLIB_OBJS specified here are object files to be included in PJLIB
|
||||
# (the library) for this specific operating system. Object files common
|
||||
# to all operating systems should go in Makefile instead.
|
||||
#
|
||||
export PJLIB_OBJS += addr_resolv_sock.o guid_simple.o \
|
||||
log_writer_stdout.o os_core_unix.o \
|
||||
os_error_unix.o os_time_ansi.o \
|
||||
os_timestamp_common.o os_timestamp_linux.o \
|
||||
os_time_ansi.o \
|
||||
pool_policy_malloc.o sock_bsd.o sock_select.o
|
||||
|
||||
export PJLIB_OBJS += ioqueue_select.o
|
||||
#export PJLIB_OBJS += ioqueue_epoll.o
|
||||
|
||||
#
|
||||
# TEST_OBJS are operating system specific object files to be included in
|
||||
# the test application.
|
||||
#
|
||||
export TEST_OBJS += main.o
|
||||
|
||||
#
|
||||
# Additional LDFLAGS for pjlib-test
|
||||
#
|
||||
export TEST_LDFLAGS += -lm
|
||||
|
||||
#
|
||||
# TARGETS are make targets in the Makefile, to be executed for this given
|
||||
# operating system.
|
||||
#
|
||||
export TARGETS = pjlib pjlib-test
|
||||
|
|
@ -9,7 +9,8 @@
|
|||
# define pj_get_native_netos_error() WSAGetLastError()
|
||||
|
||||
#elif (defined(PJ_LINUX) && PJ_LINUX != 0) || \
|
||||
(defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0)
|
||||
(defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0) || \
|
||||
(defined(PJ_SUNOS) && PJ_SUNOS != 0)
|
||||
|
||||
typedef int pj_os_err_type;
|
||||
# define pj_get_native_os_error() (errno)
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
typedef pj_int64_t pj_highprec_t;
|
||||
|
||||
#else
|
||||
# warning "High precision math is not available"
|
||||
|
||||
/*
|
||||
* Last, fallback to 32-bit arithmetics.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
/* $Header: $ */
|
||||
/*
|
||||
*$Log: $
|
||||
*
|
||||
*/
|
||||
#ifndef __PJ_COMPAT_M_SPARC_H__
|
||||
#define __PJ_COMPAT_M_SPARC_H__
|
||||
|
||||
/**
|
||||
* @file m_sparc.h
|
||||
* @brief Describes SPARC family processor specifics.
|
||||
*/
|
||||
|
||||
#define PJ_SPARC 1
|
||||
|
||||
#define PJ_HAS_PENTIUM 0
|
||||
#define PJ_IS_LITTLE_ENDIAN 0
|
||||
#define PJ_IS_BIG_ENDIAN 1
|
||||
|
||||
|
||||
#endif /* __PJ_COMPAT_M_SPARC_H__ */
|
|
@ -0,0 +1,56 @@
|
|||
/* $Header: $ */
|
||||
/* $Log: $
|
||||
*
|
||||
*/
|
||||
#ifndef __PJ_COMPAT_OS_SUNOS_H__
|
||||
#define __PJ_COMPAT_OS_SUNOS_H__
|
||||
|
||||
/**
|
||||
* @file os_sunos.h
|
||||
* @brief Describes SunOS/Solaris operating system specifics.
|
||||
*/
|
||||
|
||||
#define PJ_HAS_ARPA_INET_H 1
|
||||
#define PJ_HAS_ASSERT_H 1
|
||||
#define PJ_HAS_CTYPE_H 1
|
||||
#define PJ_HAS_ERRNO_H 1
|
||||
#define PJ_HAS_LINUX_SOCKET_H 0
|
||||
#define PJ_HAS_MALLOC_H 1
|
||||
#define PJ_HAS_NETDB_H 1
|
||||
#define PJ_HAS_NETINET_IN_H 1
|
||||
#define PJ_HAS_SETJMP_H 1
|
||||
#define PJ_HAS_STDARG_H 1
|
||||
#define PJ_HAS_STDDEF_H 1
|
||||
#define PJ_HAS_STDIO_H 1
|
||||
#define PJ_HAS_STDLIB_H 1
|
||||
#define PJ_HAS_STRING_H 1
|
||||
#define PJ_HAS_SYS_IOCTL_H 1
|
||||
#define PJ_HAS_SYS_SELECT_H 1
|
||||
#define PJ_HAS_SYS_SOCKET_H 1
|
||||
#define PJ_HAS_SYS_TIMEB_H 1
|
||||
#define PJ_HAS_SYS_TYPES_H 1
|
||||
#define PJ_HAS_TIME_H 1
|
||||
#define PJ_HAS_UNISTD_H 1
|
||||
|
||||
#define PJ_HAS_MSWSOCK_H 0
|
||||
#define PJ_HAS_WINSOCK_H 0
|
||||
#define PJ_HAS_WINSOCK2_H 0
|
||||
|
||||
#define PJ_SOCK_HAS_INET_ATON 0
|
||||
|
||||
/* Default threading is enabled, unless it's overridden. */
|
||||
#ifndef PJ_HAS_THREADS
|
||||
# define PJ_HAS_THREADS (1)
|
||||
#endif
|
||||
|
||||
#define PJ_HAS_HIGH_RES_TIMER 1
|
||||
#define PJ_HAS_MALLOC 1
|
||||
#define PJ_OS_HAS_CHECK_STACK 0
|
||||
|
||||
#define PJ_ATOMIC_VALUE_TYPE long
|
||||
|
||||
/* Get BSD related identifers in Sun's include files */
|
||||
#define BSD_COMP
|
||||
|
||||
#endif /* __PJ_COMPAT_OS_SUNOS_H__ */
|
||||
|
|
@ -21,16 +21,18 @@
|
|||
|
||||
|
||||
/********************************************************************
|
||||
* Include target specific configuration.
|
||||
* Include target OS specific configuration.
|
||||
*/
|
||||
#if defined(PJ_WIN32)
|
||||
#if defined(PJ_WIN32) && PJ_WIN32!=0
|
||||
# include <pj/compat/os_win32.h>
|
||||
#elif defined(PJ_LINUX)
|
||||
#elif defined(PJ_LINUX) && PJ_LINUX!=0
|
||||
# include <pj/compat/os_linux.h>
|
||||
#elif defined(PJ_LINUX_KERNEL)
|
||||
#elif defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL!=0
|
||||
# include <pj/compat/os_linux_kernel.h>
|
||||
#elif defined(PJ_PALMOS)
|
||||
#elif defined(PJ_PALMOS) && PJ_PALMOS!=0
|
||||
# include <pj/compat/os_palmos.h>
|
||||
#elif defined(PJ_SUNOS) && PJ_SUNOS!=0
|
||||
# include <pj/compat/os_sunos.h>
|
||||
#else
|
||||
# error "Please specify target os."
|
||||
#endif
|
||||
|
@ -45,6 +47,8 @@
|
|||
# include <pj/compat/m_m68k.h>
|
||||
#elif defined (PJ_M_ALPHA) && PJ_M_ALPHA != 0
|
||||
# include <pj/compat/m_alpha.h>
|
||||
#elif defined (PJ_M_SPARC) && PJ_M_SPARC != 0
|
||||
# include <pj/compat/m_sparc.h>
|
||||
#else
|
||||
# error "Please specify target machine."
|
||||
#endif
|
||||
|
|
|
@ -57,14 +57,14 @@ typedef int (PJ_THREAD_FUNC pj_thread_proc)(void*);
|
|||
* Size of thread struct.
|
||||
*/
|
||||
#if !defined(PJ_THREAD_DESC_SIZE)
|
||||
# define PJ_THREAD_DESC_SIZE (PJ_MAX_OBJ_NAME + 10*sizeof(long))
|
||||
# define PJ_THREAD_DESC_SIZE (16)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Thread structure, to thread's state when the thread is created by external
|
||||
* or native API.
|
||||
*/
|
||||
typedef pj_uint8_t pj_thread_desc[PJ_THREAD_DESC_SIZE];
|
||||
typedef long pj_thread_desc[PJ_THREAD_DESC_SIZE];
|
||||
|
||||
/**
|
||||
* Get process ID.
|
||||
|
@ -244,7 +244,7 @@ PJ_DECL(void) pj_thread_local_free(long index);
|
|||
* @param index The index of the variable.
|
||||
* @param value The value.
|
||||
*/
|
||||
PJ_DECL(void) pj_thread_local_set(long index, void *value);
|
||||
PJ_DECL(pj_status_t) pj_thread_local_set(long index, void *value);
|
||||
|
||||
/**
|
||||
* Get the value of thread local variable.
|
||||
|
@ -783,8 +783,13 @@ typedef union pj_timestamp
|
|||
{
|
||||
struct
|
||||
{
|
||||
#if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN!=0
|
||||
pj_uint32_t lo; /**< Low 32-bit value of the 64-bit value. */
|
||||
pj_uint32_t hi; /**< high 32-bit value of the 64-bit value. */
|
||||
#else
|
||||
pj_uint32_t hi; /**< high 32-bit value of the 64-bit value. */
|
||||
pj_uint32_t lo; /**< Low 32-bit value of the 64-bit value. */
|
||||
#endif
|
||||
} u32; /**< The 64-bit value as two 32-bit values. */
|
||||
|
||||
#if PJ_HAS_INT64
|
||||
|
|
|
@ -498,14 +498,15 @@ do_readable_scan:
|
|||
*/
|
||||
# if defined(PJ_WIN32) && PJ_WIN32 != 0
|
||||
rc = pj_sock_recv(h->fd, h->rd_buf, &bytes_read, 0);
|
||||
# elif defined(PJ_LINUX) && PJ_LINUX != 0
|
||||
# elif (defined(PJ_LINUX) && PJ_LINUX != 0) || \
|
||||
(defined(PJ_SUNOS) && PJ_SUNOS != 0)
|
||||
bytes_read = read(h->fd, h->rd_buf, bytes_read);
|
||||
rc = (bytes_read >= 0) ? PJ_SUCCESS : pj_get_os_error();
|
||||
# elif defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0
|
||||
bytes_read = sys_read(h->fd, h->rd_buf, bytes_read);
|
||||
rc = (bytes_read >= 0) ? PJ_SUCCESS : -bytes_read;
|
||||
# else
|
||||
# error "Check this man!"
|
||||
# error "Implement read() for this platform!"
|
||||
# endif
|
||||
}
|
||||
|
||||
|
@ -559,12 +560,13 @@ do_writable_scan:
|
|||
pj_assert(PJ_IOQUEUE_IS_WRITE_OP(h->op) ||
|
||||
PJ_IOQUEUE_IS_CONNECT_OP(h->op));
|
||||
|
||||
#if PJ_HAS_TCP
|
||||
#if defined(PJ_HAS_TCP) && PJ_HAS_TCP!=0
|
||||
if ((h->op & PJ_IOQUEUE_OP_CONNECT)) {
|
||||
/* Completion of connect() operation */
|
||||
pj_ssize_t bytes_transfered;
|
||||
|
||||
#if defined(PJ_LINUX) || defined(PJ_LINUX_KERNEL)
|
||||
#if (defined(PJ_LINUX) && PJ_LINUX!=0) || \
|
||||
(defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL!=0)
|
||||
/* from connect(2):
|
||||
* On Linux, use getsockopt to read the SO_ERROR option at
|
||||
* level SOL_SOCKET to determine whether connect() completed
|
||||
|
@ -584,10 +586,25 @@ do_writable_scan:
|
|||
} else {
|
||||
bytes_transfered = value;
|
||||
}
|
||||
#elif defined(PJ_WIN32)
|
||||
#elif defined(PJ_WIN32) && PJ_WIN32!=0
|
||||
bytes_transfered = 0; /* success */
|
||||
#else
|
||||
# error "Got to check this one!"
|
||||
/* Excellent information in D.J. Bernstein page:
|
||||
* http://cr.yp.to/docs/connect.html
|
||||
*
|
||||
* Seems like the most portable way of detecting connect()
|
||||
* failure is to call getpeername(). If socket is connected,
|
||||
* getpeername() will return 0. If the socket is not connected,
|
||||
* it will return ENOTCONN, and read(fd, &ch, 1) will produce
|
||||
* the right errno through error slippage. This is a combination
|
||||
* of suggestions from Douglas C. Schmidt and Ken Keys.
|
||||
*/
|
||||
int gp_rc;
|
||||
struct sockaddr_in addr;
|
||||
socklen_t addrlen = sizeof(addr);
|
||||
|
||||
gp_rc = getpeername(h->fd, (struct sockaddr*)&addr, &addrlen);
|
||||
bytes_transfered = gp_rc;
|
||||
#endif
|
||||
|
||||
/* Clear operation. */
|
||||
|
|
|
@ -252,7 +252,7 @@ PJ_DEF(pj_status_t) pj_thread_register ( const char *cstr_thread_name,
|
|||
}
|
||||
|
||||
/* Initialize and set the thread entry. */
|
||||
pj_memset(desc, 0, sizeof(pj_thread_desc));
|
||||
pj_memset(desc, 0, sizeof(struct pj_thread_t));
|
||||
|
||||
if(cstr_thread_name && pj_strlen(&thread_name) < sizeof(thread->obj_name)-1)
|
||||
pj_sprintf(thread->obj_name, cstr_thread_name, thread->thread);
|
||||
|
@ -287,7 +287,7 @@ pj_status_t pj_thread_init(void)
|
|||
if (rc != PJ_SUCCESS)
|
||||
return rc;
|
||||
|
||||
return pj_thread_register("pjlib-main", (pj_uint8_t*)&main_thread, &dummy);
|
||||
return pj_thread_register("pjlib-main", (long*)&main_thread, &dummy);
|
||||
}
|
||||
|
||||
PJ_DEF(pj_status_t) pj_thread_create( pj_pool_t *pool, const char *thread_name,
|
||||
|
@ -472,10 +472,11 @@ PJ_DEF(void) pj_thread_local_free(long index)
|
|||
pj_assert(index >= 0 && index < MAX_TLS_ID);
|
||||
}
|
||||
|
||||
PJ_DEF(void) pj_thread_local_set(long index, void *value)
|
||||
PJ_DEF(pj_status_t) pj_thread_local_set(long index, void *value)
|
||||
{
|
||||
pj_assert(index >= 0 && index < MAX_TLS_ID);
|
||||
tls_values[index] = value;
|
||||
return PJ_SUCCESS;
|
||||
}
|
||||
|
||||
PJ_DEF(void*) pj_thread_local_get(long index)
|
||||
|
|
|
@ -174,6 +174,7 @@ PJ_DEF(pj_status_t) pj_thread_register ( const char *cstr_thread_name,
|
|||
{
|
||||
#if PJ_HAS_THREADS
|
||||
char stack_ptr;
|
||||
pj_status_t rc;
|
||||
pj_thread_t *thread = (pj_thread_t *)desc;
|
||||
pj_str_t thread_name = pj_str((char*)cstr_thread_name);
|
||||
|
||||
|
@ -190,7 +191,7 @@ PJ_DEF(pj_status_t) pj_thread_register ( const char *cstr_thread_name,
|
|||
}
|
||||
|
||||
/* Initialize and set the thread entry. */
|
||||
pj_memset(desc, 0, sizeof(pj_thread_desc));
|
||||
pj_memset(desc, 0, sizeof(struct pj_thread_t));
|
||||
thread->thread = pthread_self();
|
||||
|
||||
if(cstr_thread_name && pj_strlen(&thread_name) < sizeof(thread->obj_name)-1)
|
||||
|
@ -198,7 +199,9 @@ PJ_DEF(pj_status_t) pj_thread_register ( const char *cstr_thread_name,
|
|||
else
|
||||
pj_sprintf(thread->obj_name, "thr%p", (void*)thread->thread);
|
||||
|
||||
pj_thread_local_set(thread_tls_id, thread);
|
||||
rc = pj_thread_local_set(thread_tls_id, thread);
|
||||
if (rc != PJ_SUCCESS)
|
||||
return rc;
|
||||
|
||||
#if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0
|
||||
thread->stk_start = &stack_ptr;
|
||||
|
@ -213,7 +216,7 @@ PJ_DEF(pj_status_t) pj_thread_register ( const char *cstr_thread_name,
|
|||
#else
|
||||
pj_thread_t *thread = (pj_thread_t*)desc;
|
||||
*ptr_thread = thread;
|
||||
return SUCCESS;
|
||||
return PJ_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -230,7 +233,7 @@ pj_status_t pj_thread_init(void)
|
|||
if (rc != PJ_SUCCESS) {
|
||||
return rc;
|
||||
}
|
||||
return pj_thread_register("thr%p", (pj_uint8_t*)&main_thread, &dummy);
|
||||
return pj_thread_register("thr%p", (long*)&main_thread, &dummy);
|
||||
#else
|
||||
PJ_LOG(2,(THIS_FILE, "Thread init error. Threading is not enabled!"));
|
||||
return PJ_EINVALIDOP;
|
||||
|
@ -247,13 +250,17 @@ static void *thread_main(void *param)
|
|||
{
|
||||
pj_thread_t *rec = param;
|
||||
void *result;
|
||||
pj_status_t rc;
|
||||
|
||||
#if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0
|
||||
rec->stk_start = (char*)&rec;
|
||||
#endif
|
||||
|
||||
/* Set current thread id. */
|
||||
pj_thread_local_set(thread_tls_id, rec);
|
||||
rc = pj_thread_local_set(thread_tls_id, rec);
|
||||
if (rc != PJ_SUCCESS) {
|
||||
pj_assert(!"Thread TLS ID is not set (pj_init() error?)");
|
||||
}
|
||||
|
||||
/* Check if suspension is required. */
|
||||
if (rec->suspended_mutex)
|
||||
|
@ -659,16 +666,18 @@ PJ_DEF(void) pj_thread_local_free(long index)
|
|||
/*
|
||||
* pj_thread_local_set()
|
||||
*/
|
||||
PJ_DEF(void) pj_thread_local_set(long index, void *value)
|
||||
PJ_DEF(pj_status_t) pj_thread_local_set(long index, void *value)
|
||||
{
|
||||
//Can't check stack because this function is called in the
|
||||
//beginning before main thread is initialized.
|
||||
//PJ_CHECK_STACK();
|
||||
#if PJ_HAS_THREADS
|
||||
pthread_setspecific(index, value);
|
||||
int rc=pthread_setspecific(index, value);
|
||||
return rc==0 ? PJ_SUCCESS : PJ_RETURN_OS_ERROR(rc);
|
||||
#else
|
||||
pj_assert(index >= 0 && index < MAX_THREADS);
|
||||
tls[index] = value;
|
||||
return PJ_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -705,16 +714,34 @@ PJ_DEF(void) pj_leave_critical_section(void)
|
|||
static pj_status_t init_mutex(pj_mutex_t *mutex, const char *name, int type)
|
||||
{
|
||||
#if PJ_HAS_THREADS
|
||||
PJ_UNUSED_ARG(type);
|
||||
pthread_mutexattr_t attr;
|
||||
int rc;
|
||||
|
||||
PJ_CHECK_STACK();
|
||||
|
||||
pthread_mutexattr_init(&attr);
|
||||
|
||||
if (type == PJ_MUTEX_SIMPLE) {
|
||||
pthread_mutex_t the_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
mutex->mutex = the_mutex;
|
||||
#if defined(PJ_LINUX) && PJ_LINUX!=0
|
||||
rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_FAST_NP);
|
||||
#else
|
||||
rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
|
||||
#endif
|
||||
} else {
|
||||
pthread_mutex_t the_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
||||
mutex->mutex = the_mutex;
|
||||
#if defined(PJ_LINUX) && PJ_LINUX!=0
|
||||
rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
|
||||
#else
|
||||
rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
return PJ_RETURN_OS_ERROR(rc);
|
||||
}
|
||||
|
||||
rc = pthread_mutex_init(&mutex->mutex, &attr);
|
||||
if (rc != 0) {
|
||||
return PJ_RETURN_OS_ERROR(rc);
|
||||
}
|
||||
|
||||
#if PJ_DEBUG
|
||||
|
|
|
@ -191,6 +191,7 @@ PJ_DEF(pj_status_t) pj_thread_register ( const char *cstr_thread_name,
|
|||
pj_thread_t **thread_ptr)
|
||||
{
|
||||
char stack_ptr;
|
||||
pj_status_t rc;
|
||||
pj_thread_t *thread = (pj_thread_t *)desc;
|
||||
pj_str_t thread_name = pj_str((char*)cstr_thread_name);
|
||||
|
||||
|
@ -207,7 +208,7 @@ PJ_DEF(pj_status_t) pj_thread_register ( const char *cstr_thread_name,
|
|||
}
|
||||
|
||||
/* Initialize and set the thread entry. */
|
||||
pj_memset(desc, 0, sizeof(pj_thread_desc));
|
||||
pj_memset(desc, 0, sizeof(struct pj_thread_t));
|
||||
thread->hthread = GetCurrentThread();
|
||||
thread->idthread = GetCurrentThreadId();
|
||||
|
||||
|
@ -224,7 +225,9 @@ PJ_DEF(pj_status_t) pj_thread_register ( const char *cstr_thread_name,
|
|||
else
|
||||
pj_sprintf(thread->obj_name, "thr%p", (void*)thread->idthread);
|
||||
|
||||
pj_thread_local_set(thread_tls_id, thread);
|
||||
rc = pj_thread_local_set(thread_tls_id, thread);
|
||||
if (rc != PJ_SUCCESS)
|
||||
return rc;
|
||||
|
||||
*thread_ptr = thread;
|
||||
return PJ_SUCCESS;
|
||||
|
@ -256,7 +259,10 @@ static DWORD WINAPI thread_main(void *param)
|
|||
|
||||
PJ_LOG(6,(rec->obj_name, "Thread started"));
|
||||
|
||||
pj_thread_local_set(thread_tls_id, rec);
|
||||
if (pj_thread_local_set(thread_tls_id, rec) != PJ_SUCCESS) {
|
||||
pj_assert(!"TLS is not set (pj_init() error?)");
|
||||
}
|
||||
|
||||
result = (*rec->proc)(rec->arg);
|
||||
|
||||
PJ_LOG(6,(rec->obj_name, "Thread quitting"));
|
||||
|
@ -585,12 +591,15 @@ PJ_DEF(void) pj_thread_local_free(long index)
|
|||
/*
|
||||
* pj_thread_local_set()
|
||||
*/
|
||||
PJ_DEF(void) pj_thread_local_set(long index, void *value)
|
||||
PJ_DEF(pj_status_t) pj_thread_local_set(long index, void *value)
|
||||
{
|
||||
BOOL rc;
|
||||
|
||||
//Can't check stack because this function is called in the
|
||||
//beginning before main thread is initialized.
|
||||
//PJ_CHECK_STACK();
|
||||
TlsSetValue(index, value);
|
||||
rc = TlsSetValue(index, value);
|
||||
return rc!=0 ? PJ_SUCCESS : PJ_RETURN_OS_ERROR(GetLastError());
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -20,13 +20,17 @@
|
|||
#include <pj/assert.h>
|
||||
#include <pj/errno.h>
|
||||
|
||||
#if defined(PJ_HAS_STRING_H) && PJ_HAS_STRING_H!=0
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(disable: 4018) // Signed/unsigned mismatch in FD_*
|
||||
#endif
|
||||
|
||||
#define PART_FDSET(p_fdsetp) ((fd_set*)&p_fdsetp->data[1])
|
||||
#define PART_COUNT(p_fdsetp) (p_fdsetp->data[0])
|
||||
#define PART_FDSET(ps) ((fd_set*)&ps->data[1])
|
||||
#define PART_FDSET_OR_NULL(ps) (ps ? PART_FDSET(ps) : NULL)
|
||||
#define PART_COUNT(ps) (ps->data[0])
|
||||
|
||||
PJ_DEF(void) PJ_FD_ZERO(pj_fd_set_t *fdsetp)
|
||||
{
|
||||
|
@ -95,7 +99,7 @@ PJ_DEF(int) pj_sock_select( int n,
|
|||
p_os_timeout = NULL;
|
||||
}
|
||||
|
||||
return select(n, PART_FDSET(readfds), PART_FDSET(writefds),
|
||||
PART_FDSET(exceptfds), p_os_timeout);
|
||||
return select(n, PART_FDSET_OR_NULL(readfds), PART_FDSET_OR_NULL(writefds),
|
||||
PART_FDSET_OR_NULL(exceptfds), p_os_timeout);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ static int wait_socket(pj_sock_t sock, unsigned msec_timeout)
|
|||
PJ_FD_ZERO(&fdset);
|
||||
PJ_FD_SET(sock, &fdset);
|
||||
|
||||
return pj_sock_select(1, &fdset, NULL, NULL, &timeout);
|
||||
return pj_sock_select(FD_SETSIZE, &fdset, NULL, NULL, &timeout);
|
||||
}
|
||||
|
||||
static int echo_client_thread(void *arg)
|
||||
|
@ -83,6 +83,10 @@ static int echo_client_thread(void *arg)
|
|||
return -20;
|
||||
}
|
||||
|
||||
PJ_LOG(3,("", "...socket connected to %s:%d",
|
||||
pj_inet_ntoa(addr.sin_addr),
|
||||
pj_ntohs(addr.sin_port)));
|
||||
|
||||
pj_create_random_string(send_buf, BUF_SIZE);
|
||||
thread_total = 0;
|
||||
|
||||
|
@ -115,6 +119,11 @@ static int echo_client_thread(void *arg)
|
|||
rc = wait_socket(sock, 500);
|
||||
if (rc == 0) {
|
||||
PJ_LOG(3,("", "...timeout"));
|
||||
bytes = 0;
|
||||
} else if (rc < 0) {
|
||||
rc = pj_get_netos_error();
|
||||
app_perror("...select() error", rc);
|
||||
break;
|
||||
} else {
|
||||
/* Receive back the original packet. */
|
||||
bytes = 0;
|
||||
|
@ -129,10 +138,11 @@ static int echo_client_thread(void *arg)
|
|||
pj_thread_sleep(100);
|
||||
}
|
||||
bytes = 0;
|
||||
received = 0;
|
||||
break;
|
||||
}
|
||||
bytes += received;
|
||||
} while (bytes != BUF_SIZE);
|
||||
} while (bytes != BUF_SIZE && bytes != 0);
|
||||
}
|
||||
|
||||
/* Accumulate total received. */
|
||||
|
@ -177,7 +187,7 @@ static int echo_client_thread(void *arg)
|
|||
continue;
|
||||
|
||||
if (pj_memcmp(send_buf, recv_buf, BUF_SIZE) != 0) {
|
||||
PJ_LOG(3,("", "...error: buffer has changed!"));
|
||||
//PJ_LOG(3,("", "...error: buffer has changed!"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,11 +35,28 @@ static void boost(void)
|
|||
#define boost()
|
||||
#endif
|
||||
|
||||
#if defined(PJ_SUNOS) && PJ_SUNOS!=0
|
||||
#include <signal.h>
|
||||
static void init_signals()
|
||||
{
|
||||
struct sigaction act;
|
||||
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_handler = SIG_IGN;
|
||||
|
||||
sigaction(SIGALRM, &act, NULL);
|
||||
}
|
||||
|
||||
#else
|
||||
#define init_signals()
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int rc;
|
||||
|
||||
boost();
|
||||
init_signals();
|
||||
|
||||
while (argc > 1) {
|
||||
char *arg = argv[--argc];
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
#include <pj/types.h>
|
||||
|
||||
#define GROUP_LIBC 1
|
||||
#define GROUP_OS 1
|
||||
#define GROUP_DATA_STRUCTURE 1
|
||||
#define GROUP_NETWORK 1
|
||||
#define GROUP_EXTRA 1
|
||||
#define GROUP_LIBC 0
|
||||
#define GROUP_OS 0
|
||||
#define GROUP_DATA_STRUCTURE 0
|
||||
#define GROUP_NETWORK 0
|
||||
#define GROUP_EXTRA 0
|
||||
|
||||
#define INCLUDE_ERRNO_TEST GROUP_LIBC
|
||||
#define INCLUDE_TIMESTAMP_TEST GROUP_OS
|
||||
|
@ -18,7 +18,7 @@
|
|||
#define INCLUDE_POOL_TEST GROUP_LIBC
|
||||
#define INCLUDE_POOL_PERF_TEST (PJ_HAS_MALLOC && GROUP_LIBC)
|
||||
#define INCLUDE_STRING_TEST GROUP_DATA_STRUCTURE
|
||||
#define INCLUDE_FIFOBUF_TEST GROUP_DATA_STRUCTURE
|
||||
#define INCLUDE_FIFOBUF_TEST 0 // GROUP_DATA_STRUCTURE
|
||||
#define INCLUDE_RBTREE_TEST GROUP_DATA_STRUCTURE
|
||||
#define INCLUDE_TIMER_TEST GROUP_DATA_STRUCTURE
|
||||
#define INCLUDE_ATOMIC_TEST GROUP_OS
|
||||
|
@ -35,14 +35,14 @@
|
|||
|
||||
|
||||
#define INCLUDE_ECHO_SERVER 0
|
||||
#define INCLUDE_ECHO_CLIENT 0
|
||||
#define INCLUDE_ECHO_CLIENT 1
|
||||
|
||||
#define ECHO_SERVER_MAX_THREADS 4
|
||||
#define ECHO_SERVER_START_PORT 65000
|
||||
#define ECHO_SERVER_ADDRESS "compaq.home"
|
||||
#define ECHO_SERVER_DURATION_MSEC (60*60*1000)
|
||||
|
||||
#define ECHO_CLIENT_MAX_THREADS 10
|
||||
#define ECHO_CLIENT_MAX_THREADS 2
|
||||
|
||||
PJ_BEGIN_DECL
|
||||
|
||||
|
|
|
@ -123,8 +123,11 @@ int timestamp_test(void)
|
|||
|
||||
/* See if elapsed time is reasonable. */
|
||||
if (elapsed < 1 || elapsed > 100000) {
|
||||
PJ_LOG(3,(THIS_FILE, "....error: elapsed time outside window (%u)",
|
||||
elapsed));
|
||||
PJ_LOG(3,(THIS_FILE, "....error: elapsed time outside window (%u, "
|
||||
"t1.u32.hi=%u, t1.u32.lo=%u, "
|
||||
"t2.u32.hi=%u, t2.u32.lo=%u)",
|
||||
elapsed,
|
||||
t1.u32.hi, t1.u32.lo, t2.u32.hi, t2.u32.lo));
|
||||
return -1030;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
/* doxygen index page */
|
||||
/** @mainpage
|
||||
|
||||
PortAudio is an open-source cross-platform ‘C’ library for audio input
|
||||
PortAudio is an open-source cross-platform †CË library for audio input
|
||||
and output. It is designed to simplify the porting of audio applications
|
||||
between various platforms, and also to simplify the development of audio
|
||||
software in general by hiding the complexities of device interfacing.
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue