diff options
| author | ruki <[email protected]> | 2016-07-12 22:26:23 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-07-12 22:26:23 +0800 |
| commit | 0f7173fe7610408d1f947517e48447a4b0fd4461 (patch) | |
| tree | 836124606b169f00b04343f407d5486a42208f8a /core/pkg/tbox.pkg | |
| parent | 2df6235f8b2b3c88c94676720c2e4076b2d0d9d9 (diff) | |
add process.waitlist interfaces
Diffstat (limited to 'core/pkg/tbox.pkg')
| -rwxr-xr-x | core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h | 4 | ||||
| -rwxr-xr-x | core/pkg/tbox.pkg/inc/tbox/platform/process.h | 75 | ||||
| -rwxr-xr-x | core/pkg/tbox.pkg/inc/tbox/platform/windows/interface/kernel32.h | 6 | ||||
| -rw-r--r-- | core/pkg/tbox.pkg/inc/tbox/tbox.config.h | 115 |
4 files changed, 199 insertions, 1 deletions
diff --git a/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h b/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h index ea46a2e3c..a330a7f95 100755 --- a/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h +++ b/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h @@ -6,10 +6,12 @@ #define TB_CONFIG_VERSION_MAJOR 1 #define TB_CONFIG_VERSION_MINOR 5 #define TB_CONFIG_VERSION_ALTER 3 -#define TB_CONFIG_VERSION_BUILD 201607031524 +#define TB_CONFIG_VERSION_BUILD 201607122000 // defines #define TB_CONFIG_OS_MACOSX 1 +#define _GNU_SOURCE 1 +#define _REENTRANT 1 #define TB_CONFIG_SMALL 1 #define TB_CONFIG_TYPE_HAVE_FLOAT 1 #define TB_CONFIG_POSIX_HAVE_POSIX_SPAWNP 1 diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/process.h b/core/pkg/tbox.pkg/inc/tbox/platform/process.h index dab5ac300..1c36d1355 100755 --- a/core/pkg/tbox.pkg/inc/tbox/platform/process.h +++ b/core/pkg/tbox.pkg/inc/tbox/platform/process.h @@ -102,6 +102,20 @@ typedef struct __tb_process_attr_t /// the process ref type typedef struct{}* tb_process_ref_t; +/// the process wait info type +typedef struct __tb_process_waitinfo_t +{ + // the index of the processes + tb_size_t index; + + // the process + tb_process_ref_t process; + + // the status + tb_long_t status; + +}tb_process_waitinfo_t, *tb_process_waitinfo_ref_t; + /* ////////////////////////////////////////////////////////////////////////////////////// * interfaces */ @@ -250,6 +264,67 @@ tb_void_t tb_process_suspend(tb_process_ref_t process); */ tb_long_t tb_process_wait(tb_process_ref_t process, tb_long_t* pstatus, tb_long_t timeout); +/*! wait the process list + * + * @code + + // init processes + tb_size_t count1 = 0; + tb_process_ref_t processes1[5] = {0}; + tb_process_ref_t processes2[5] = {0}; + for (; count1 < 4; count1++) + { + processes1[count1] = tb_process_init(argv[1], (tb_char_t const**)(argv + 1), tb_null); + tb_assert_and_check_break(processes1[count1]); + } + + // ok? + while (count1) + { + // trace + tb_trace_i("waiting: %ld", count1); + + // wait processes + tb_long_t infosize = -1; + tb_process_waitinfo_t infolist[4] = {{0}}; + if ((infosize = tb_process_waitlist(processes1, infolist, tb_arrayn(infolist), -1)) > 0) + { + tb_size_t i = 0; + for (i = 0; i < infosize; i++) + { + // trace + tb_trace_i("process(%ld:%p) exited: %ld", infolist[i].index, infolist[i].process, infolist[i].status); + + // exit process + if (infolist[i].process) tb_process_exit(infolist[i].process); + + // remove this process + processes1[infolist[i].index] = tb_null; + } + + // update processes + tb_size_t count2 = 0; + for (i = 0; i < count1; i++) + { + if (processes1[i]) processes2[count2++] = processes1[i]; + } + tb_memcpy(processes1, processes2, count2 * sizeof(tb_process_ref_t)); + processes1[count2] = tb_null; + count1 = count2; + } + } + + * @endcode + * + * @param processes the null-terminated process list + * @param infolist the info list + * @param infomaxn the info maxn + * @param timeout the timeout (ms), infinity: -1 + * + * @return > 0: the info list size, 0: timeout, -1: failed + */ +tb_long_t tb_process_waitlist(tb_process_ref_t const* processes, tb_process_waitinfo_ref_t infolist, tb_size_t infomaxn, tb_long_t timeout); + /* ////////////////////////////////////////////////////////////////////////////////////// * extern */ diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/windows/interface/kernel32.h b/core/pkg/tbox.pkg/inc/tbox/platform/windows/interface/kernel32.h index b9f3f3773..a8d32d976 100755 --- a/core/pkg/tbox.pkg/inc/tbox/platform/windows/interface/kernel32.h +++ b/core/pkg/tbox.pkg/inc/tbox/platform/windows/interface/kernel32.h @@ -77,6 +77,9 @@ typedef BOOL (WINAPI* tb_kernel32_CloseHandle_t)(HANDLE hObject); // the WaitForSingleObject func type typedef DWORD (WINAPI* tb_kernel32_WaitForSingleObject_t)(HANDLE hHandle, DWORD dwMilliseconds); +// the WaitForMultipleObjects func type +typedef DWORD (WINAPI* tb_kernel32_WaitForMultipleObjects_t)(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAll, DWORD dwMilliseconds); + // the GetExitCodeProcess func type typedef BOOL (WINAPI* tb_kernel32_GetExitCodeProcess_t)(HANDLE hProcess, LPDWORD lpExitCode); @@ -131,6 +134,9 @@ typedef struct __tb_kernel32_t // WaitForSingleObject tb_kernel32_WaitForSingleObject_t WaitForSingleObject; + // WaitForMultipleObjects + tb_kernel32_WaitForMultipleObjects_t WaitForMultipleObjects; + // GetExitCodeProcess tb_kernel32_GetExitCodeProcess_t GetExitCodeProcess; diff --git a/core/pkg/tbox.pkg/inc/tbox/tbox.config.h b/core/pkg/tbox.pkg/inc/tbox/tbox.config.h new file mode 100644 index 000000000..a330a7f95 --- /dev/null +++ b/core/pkg/tbox.pkg/inc/tbox/tbox.config.h @@ -0,0 +1,115 @@ +#ifndef TB_CONFIG_H +#define TB_CONFIG_H + +// version +#define TB_CONFIG_VERSION "1.5.3" +#define TB_CONFIG_VERSION_MAJOR 1 +#define TB_CONFIG_VERSION_MINOR 5 +#define TB_CONFIG_VERSION_ALTER 3 +#define TB_CONFIG_VERSION_BUILD 201607122000 + +// defines +#define TB_CONFIG_OS_MACOSX 1 +#define _GNU_SOURCE 1 +#define _REENTRANT 1 +#define TB_CONFIG_SMALL 1 +#define TB_CONFIG_TYPE_HAVE_FLOAT 1 +#define TB_CONFIG_POSIX_HAVE_POSIX_SPAWNP 1 +#define TB_CONFIG_LIBC_HAVE_MKTIME 1 +#define TB_CONFIG_LIBM_HAVE_ACOS 1 +#define TB_CONFIG_POSIX_HAVE_SOCKET 1 +#define TB_CONFIG_LIBC_HAVE_SETLOCALE 1 +#define TB_CONFIG_POSIX_HAVE_POLL 1 +#define TB_CONFIG_LIBC_HAVE_KILL 1 +#define TB_CONFIG_LIBM_HAVE_ATAN2 1 +#define TB_CONFIG_POSIX_HAVE_SCHED_YIELD 1 +#define TB_CONFIG_LIBC_HAVE_WCSLEN 1 +#define TB_CONFIG_LIBC_HAVE_WCSCMP 1 +#define TB_CONFIG_LIBC_HAVE_WCSNCAT 1 +#define TB_CONFIG_POSIX_HAVE_EXECVP 1 +#define TB_CONFIG_POSIX_HAVE_FORK 1 +#define TB_CONFIG_POSIX_HAVE_GETIFADDRS 1 +#define TB_CONFIG_POSIX_HAVE_DLOPEN 1 +#define TB_CONFIG_POSIX_HAVE_REGEXEC 1 +#define TB_CONFIG_POSIX_HAVE_VFORK 1 +#define TB_CONFIG_LIBC_HAVE_STRCAT 1 +#define TB_CONFIG_LIBC_HAVE_WCSSTR 1 +#define TB_CONFIG_LIBC_HAVE_WCSCAT 1 +#define TB_CONFIG_LIBM_HAVE_POW 1 +#define TB_CONFIG_LIBC_HAVE_MEMCPY 1 +#define TB_CONFIG_LIBM_HAVE_SQRTF 1 +#define TB_CONFIG_LIBC_HAVE_WCSNLEN 1 +#define TB_CONFIG_LIBM_HAVE_ACOSF 1 +#define TB_CONFIG_POSIX_HAVE_OPEN 1 +#define TB_CONFIG_LIBC_HAVE_STRNLEN 1 +#define TB_CONFIG_LIBM_HAVE_ATANF 1 +#define TB_CONFIG_LIBC_HAVE_STRNCAT 1 +#define TB_CONFIG_LIBC_HAVE_WCSNCPY 1 +#define TB_CONFIG_LIBC_HAVE_GMTIME 1 +#define TB_CONFIG_LIBM_HAVE_TAN 1 +#define TB_CONFIG_LIBM_HAVE_POWF 1 +#define TB_CONFIG_LIBM_HAVE_SINF 1 +#define TB_CONFIG_LIBM_HAVE_ATAN 1 +#define TB_CONFIG_LIBC_HAVE_STRNCMP 1 +#define TB_CONFIG_LIBC_HAVE_MEMMOVE 1 +#define TB_CONFIG_LIBC_HAVE_STRNCASECMP 1 +#define TB_CONFIG_LIBC_HAVE_STRLCPY 1 +#define TB_CONFIG_LIBC_HAVE_WCSCPY 1 +#define TB_CONFIG_LIBM_HAVE_SQRT 1 +#define TB_CONFIG_LIBC_HAVE_STRCMP 1 +#define TB_CONFIG_LIBC_HAVE_STRCASECMP 1 +#define TB_CONFIG_LIBC_HAVE_MEMSET 1 +#define TB_CONFIG_LIBC_HAVE_FPUTS 1 +#define TB_CONFIG_LIBM_HAVE_TANF 1 +#define TB_CONFIG_LIBC_HAVE_STRNCPY 1 +#define TB_CONFIG_LIBC_HAVE_LOCALTIME 1 +#define TB_CONFIG_LIBC_HAVE_WCSNCASECMP 1 +#define TB_CONFIG_LIBC_HAVE_STRCPY 1 +#define TB_CONFIG_LIBC_HAVE_WCSLCPY 1 +#define TB_CONFIG_SYSTEMV_HAVE_SEMGET 1 +#define TB_CONFIG_POSIX_HAVE_WAITPID 1 +#define TB_CONFIG_LIBC_HAVE_GETTIMEOFDAY 1 +#define TB_CONFIG_LIBC_HAVE_SIGNAL 1 +#define TB_CONFIG_LIBC_HAVE_STRSTR 1 +#define TB_CONFIG_POSIX_HAVE_WRITEV 1 +#define TB_CONFIG_LIBC_HAVE_WCSNCMP 1 +#define TB_CONFIG_POSIX_HAVE_READV 1 +#define TB_CONFIG_LIBM_HAVE_LOG2 1 +#define TB_CONFIG_LIBM_HAVE_COS 1 +#define TB_CONFIG_POSIX_HAVE_REGCOMP 1 +#define TB_CONFIG_POSIX_HAVE_PTHREAD_MUTEX_INIT 1 +#define TB_CONFIG_LIBM_HAVE_FMODF 1 +#define TB_CONFIG_POSIX_HAVE_SYSCONF 1 +#define TB_CONFIG_LIBC_HAVE_WCSTOMBS 1 +#define TB_CONFIG_LIBM_HAVE_FMOD 1 +#define TB_CONFIG_LIBC_HAVE_MEMCMP 1 +#define TB_CONFIG_POSIX_HAVE_GETPAGESIZE 1 +#define TB_CONFIG_POSIX_HAVE_SEM_INIT 1 +#define TB_CONFIG_POSIX_HAVE_GETHOSTNAME 1 +#define TB_CONFIG_POSIX_HAVE_OPENDIR 1 +#define TB_CONFIG_LIBM_HAVE_COSF 1 +#define TB_CONFIG_LIBM_HAVE_ATAN2F 1 +#define TB_CONFIG_LIBM_HAVE_EXP 1 +#define TB_CONFIG_LIBM_HAVE_SIN 1 +#define TB_CONFIG_POSIX_HAVE_PTHREAD_CREATE 1 +#define TB_CONFIG_LIBM_HAVE_ASIN 1 +#define TB_CONFIG_LIBM_HAVE_EXPF 1 +#define TB_CONFIG_LIBC_HAVE_STRLEN 1 +#define TB_CONFIG_MODULE_HAVE_THREAD 1 +#define TB_CONFIG_MODULE_HAVE_NETWORK 1 +#define TB_CONFIG_LIBC_HAVE_MEMMEM 1 +#define TB_CONFIG_LIBC_HAVE_WCSCASECMP 1 +#define TB_CONFIG_LIBC_HAVE_MBSTOWCS 1 +#define TB_CONFIG_LIBC_HAVE_SIGSETJMP 1 +#define TB_CONFIG_LIBM_HAVE_LOG2F 1 +#define TB_CONFIG_LIBM_HAVE_ASINF 1 +#define TB_CONFIG_LIBC_HAVE_SETJMP 1 +#define TB_CONFIG_LIBC_HAVE_STRCASESTR 1 +#define TB_CONFIG_LIBC_HAVE_BACKTRACE 1 + +// undefines +#undef TB_CONFIG_TRACE_INFO_ONLY +#undef TB_CONFIG_EXCEPTION_ENABLE +#undef TB_CONFIG_MEMORY_UNALIGNED_ACCESS_ENABLE + +#endif |
