added qse_cnd_t

This commit is contained in:
2015-09-24 14:35:50 +00:00
parent 2ca43127fc
commit 1f6fbd4f9f
12 changed files with 774 additions and 27 deletions

View File

@ -27,7 +27,7 @@
#ifndef _QSE_CMN_TIME_H_
#define _QSE_CMN_TIME_H_
/** @file
/** \file
* This file provides time manipulation functions.
*/

View File

@ -892,6 +892,9 @@
/* Patch level */
#undef QSE_PACKAGE_VERSION_PATCH
/* Define if pthread_cond_t is signed */
#undef QSE_PTHREAD_MUTEX_T_IS_SIGNED
/* Define if pthread_t is signed */
#undef QSE_PTHREAD_T_IS_SIGNED
@ -925,6 +928,12 @@
/* sizeof(off_t) */
#undef QSE_SIZEOF_OFF_T
/* sizeof(pthread_cond_t) */
#undef QSE_SIZEOF_PTHREAD_COND_T
/* sizeof(pthread_mutex_t) */
#undef QSE_SIZEOF_PTHREAD_MUTEX_T
/* sizeof(pthread_t) */
#undef QSE_SIZEOF_PTHREAD_T
@ -1012,6 +1021,12 @@
/* The size of `off_t', as computed by sizeof. */
#undef SIZEOF_OFF_T
/* The size of `pthread_cond_t', as computed by sizeof. */
#undef SIZEOF_PTHREAD_COND_T
/* The size of `pthread_mutex_t', as computed by sizeof. */
#undef SIZEOF_PTHREAD_MUTEX_T
/* The size of `pthread_t', as computed by sizeof. */
#undef SIZEOF_PTHREAD_T

View File

@ -1,6 +1,7 @@
pkgincludedir = $(includedir)/qse/sys
pkginclude_HEADERS = \
cnd.h \
mtx.h \
thr.h

View File

@ -117,7 +117,7 @@ am__can_run_installinfo = \
n|no|NO) false;; \
*) (install-info --version) >/dev/null 2>&1;; \
esac
am__pkginclude_HEADERS_DIST = mtx.h thr.h SocketAddress.hpp
am__pkginclude_HEADERS_DIST = cnd.h mtx.h thr.h SocketAddress.hpp
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
@ -343,7 +343,7 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
pkginclude_HEADERS = mtx.h thr.h $(am__append_1)
pkginclude_HEADERS = cnd.h mtx.h thr.h $(am__append_1)
all: all-am
.SUFFIXES:

140
qse/include/qse/sys/cnd.h Normal file
View File

@ -0,0 +1,140 @@
/*
* $Id$
*
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EQSERESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _QSE_CMN_CND_H_
#define _QSE_CMN_CND_H_
#include <qse/types.h>
#include <qse/macros.h>
#include <qse/cmn/time.h>
#include <qse/sys/mtx.h>
typedef struct qse_cnd_t qse_cnd_t;
#if defined(_WIN32)
/* define nothing */
#elif defined(__OS2__)
# error not implemented
#elif defined(__DOS__)
# error not implemented
#else
# if (QSE_SIZEOF_PTHREAD_COND_T == 0)
# error unsupported
# elif (QSE_SIZEOF_PTHREAD_COND_T == QSE_SIZEOF_INT)
# if defined(QSE_PTHREAD_COND_T_IS_SIGNED)
typedef int qse_cnd_hnd_t;
# else
typedef unsigned int qse_cnd_hnd_t;
# endif
# elif (QSE_SIZEOF_PTHREAD_COND_T == QSE_SIZEOF_LONG)
# if defined(QSE_PTHREAD_COND_T_IS_SIGNED)
typedef long qse_cnd_hnd_t;
# else
typedef unsigned long qse_cnd_hnd_t;
# endif
# else
# include <qse/pack1.h>
struct qse_cnd_hnd_t
{
qse_uint8_t b[QSE_SIZEOF_PTHREAD_COND_T];
};
typedef struct qse_cnd_hnd_t qse_cnd_hnd_t;
# include <qse/unpack.h>
# endif
#endif
struct qse_cnd_t
{
qse_mmgr_t* mmgr;
#if defined(_WIN32)
void* gate;
void* queue;
void* mutex;
unsigned int gone;
unsigned long blocked;
unsigned int waiting;
#else
qse_cnd_hnd_t hnd;
#endif
};
#ifdef __cplusplus
extern "C" {
#endif
qse_cnd_t* qse_cnd_open (
qse_mmgr_t* mmgr,
qse_size_t xtnsize
);
void qse_cnd_close (
qse_cnd_t* cnd
);
int qse_cnd_init (
qse_cnd_t* cnd,
qse_mmgr_t* mmgr
);
void qse_cnd_fini (
qse_cnd_t* cnd
);
qse_mmgr_t* qse_cnd_getmmgr (
qse_cnd_t* cnd
);
void* qse_cnd_getxtn (
qse_cnd_t* cnd
);
void qse_cnd_signal (
qse_cnd_t* cond
);
void qse_cnd_broadcast (
qse_cnd_t* cond
);
void qse_cnd_wait (
qse_cnd_t* cond,
qse_mtx_t* mutex,
qse_ntime_t* waiting_time
);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -31,21 +31,50 @@
#include <qse/types.h>
#include <qse/macros.h>
typedef struct qse_mtx_t qse_mtx_t;
#if defined(_WIN32)
/* <winnt.h> => typedef PVOID HANDLE; */
typedef void* qse_mtx_hnd_t;
#elif defined(__OS2__)
/* not implemented */
# error not implemented
#elif defined(__DOS__)
/* not implemented */
# error not implemented
#elif defined(__BEOS__)
typedef sem_id qse_mtx_hnd_t;
/* typedef sem_id qse_mtx_hnd_t; */
typdef qse_int32_t qse_mtx_hnd_t;
#else
# include <pthread.h>
typedef pthread_mutex_t qse_mtx_hnd_t;
#endif
typedef struct qse_mtx_t qse_mtx_t;
# if (QSE_SIZEOF_PTHREAD_MUTEX_T == 0)
# error unsupported
# elif (QSE_SIZEOF_PTHREAD_MUTEX_T == QSE_SIZEOF_INT)
# if defined(QSE_PTHREAD_MUTEX_T_IS_SIGNED)
typedef int qse_mtx_hnd_t;
# else
typedef unsigned int qse_mtx_hnd_t;
# endif
# elif (QSE_SIZEOF_PTHREAD_MUTEX_T == QSE_SIZEOF_LONG)
# if defined(QSE_PTHREAD_MUTEX_T_IS_SIGNED)
typedef long qse_mtx_hnd_t;
# else
typedef unsigned long qse_mtx_hnd_t;
# endif
# else
# include <qse/pack1.h>
struct qse_mtx_hnd_t
{
qse_uint8_t b[QSE_SIZEOF_PTHREAD_MUTEX_T];
};
typedef struct qse_mtx_hnd_t qse_mtx_hnd_t;
# include <qse/unpack.h>
# endif
#endif
struct qse_mtx_t
{