正在显示
5 个修改的文件
包含
215 行增加
和
217 行删除
| @@ -79,20 +79,20 @@ typedef struct _st_clist { | @@ -79,20 +79,20 @@ typedef struct _st_clist { | ||
| 79 | 79 | ||
| 80 | /* Insert element "_e" into the list, before "_l" */ | 80 | /* Insert element "_e" into the list, before "_l" */ |
| 81 | #define ST_INSERT_BEFORE(_e,_l) \ | 81 | #define ST_INSERT_BEFORE(_e,_l) \ |
| 82 | - ST_BEGIN_MACRO \ | ||
| 83 | - (_e)->next = (_l); \ | 82 | + ST_BEGIN_MACRO \ |
| 83 | + (_e)->next = (_l); \ | ||
| 84 | (_e)->prev = (_l)->prev; \ | 84 | (_e)->prev = (_l)->prev; \ |
| 85 | (_l)->prev->next = (_e); \ | 85 | (_l)->prev->next = (_e); \ |
| 86 | - (_l)->prev = (_e); \ | 86 | + (_l)->prev = (_e); \ |
| 87 | ST_END_MACRO | 87 | ST_END_MACRO |
| 88 | 88 | ||
| 89 | /* Insert element "_e" into the list, after "_l" */ | 89 | /* Insert element "_e" into the list, after "_l" */ |
| 90 | #define ST_INSERT_AFTER(_e,_l) \ | 90 | #define ST_INSERT_AFTER(_e,_l) \ |
| 91 | - ST_BEGIN_MACRO \ | 91 | + ST_BEGIN_MACRO \ |
| 92 | (_e)->next = (_l)->next; \ | 92 | (_e)->next = (_l)->next; \ |
| 93 | - (_e)->prev = (_l); \ | 93 | + (_e)->prev = (_l); \ |
| 94 | (_l)->next->prev = (_e); \ | 94 | (_l)->next->prev = (_e); \ |
| 95 | - (_l)->next = (_e); \ | 95 | + (_l)->next = (_e); \ |
| 96 | ST_END_MACRO | 96 | ST_END_MACRO |
| 97 | 97 | ||
| 98 | /* Return the element following element "_e" */ | 98 | /* Return the element following element "_e" */ |
| @@ -110,7 +110,7 @@ typedef struct _st_clist { | @@ -110,7 +110,7 @@ typedef struct _st_clist { | ||
| 110 | 110 | ||
| 111 | /* Remove the element "_e" from it's circular list */ | 111 | /* Remove the element "_e" from it's circular list */ |
| 112 | #define ST_REMOVE_LINK(_e) \ | 112 | #define ST_REMOVE_LINK(_e) \ |
| 113 | - ST_BEGIN_MACRO \ | 113 | + ST_BEGIN_MACRO \ |
| 114 | (_e)->prev->next = (_e)->next; \ | 114 | (_e)->prev->next = (_e)->next; \ |
| 115 | (_e)->next->prev = (_e)->prev; \ | 115 | (_e)->next->prev = (_e)->prev; \ |
| 116 | ST_END_MACRO | 116 | ST_END_MACRO |
| @@ -287,7 +287,7 @@ extern _st_eventsys_t *_st_eventsys; | @@ -287,7 +287,7 @@ extern _st_eventsys_t *_st_eventsys; | ||
| 287 | #define _ST_DEL_RUNQ(_thr) ST_REMOVE_LINK(&(_thr)->links) | 287 | #define _ST_DEL_RUNQ(_thr) ST_REMOVE_LINK(&(_thr)->links) |
| 288 | 288 | ||
| 289 | #define _ST_ADD_SLEEPQ(_thr, _timeout) _st_add_sleep_q(_thr, _timeout) | 289 | #define _ST_ADD_SLEEPQ(_thr, _timeout) _st_add_sleep_q(_thr, _timeout) |
| 290 | -#define _ST_DEL_SLEEPQ(_thr) _st_del_sleep_q(_thr) | 290 | +#define _ST_DEL_SLEEPQ(_thr) _st_del_sleep_q(_thr) |
| 291 | 291 | ||
| 292 | #define _ST_ADD_ZOMBIEQ(_thr) ST_APPEND_LINK(&(_thr)->links, &_ST_ZOMBIEQ) | 292 | #define _ST_ADD_ZOMBIEQ(_thr) ST_APPEND_LINK(&(_thr)->links, &_ST_ZOMBIEQ) |
| 293 | #define _ST_DEL_ZOMBIEQ(_thr) ST_REMOVE_LINK(&(_thr)->links) | 293 | #define _ST_DEL_ZOMBIEQ(_thr) ST_REMOVE_LINK(&(_thr)->links) |
| @@ -379,17 +379,17 @@ void _st_iterate_threads(void); | @@ -379,17 +379,17 @@ void _st_iterate_threads(void); | ||
| 379 | #endif | 379 | #endif |
| 380 | 380 | ||
| 381 | #ifdef ST_SWITCH_CB | 381 | #ifdef ST_SWITCH_CB |
| 382 | -#define ST_SWITCH_OUT_CB(_thread) \ | 382 | +#define ST_SWITCH_OUT_CB(_thread) \ |
| 383 | if (_st_this_vp.switch_out_cb != NULL && \ | 383 | if (_st_this_vp.switch_out_cb != NULL && \ |
| 384 | _thread != _st_this_vp.idle_thread && \ | 384 | _thread != _st_this_vp.idle_thread && \ |
| 385 | _thread->state != _ST_ST_ZOMBIE) { \ | 385 | _thread->state != _ST_ST_ZOMBIE) { \ |
| 386 | - _st_this_vp.switch_out_cb(); \ | 386 | + _st_this_vp.switch_out_cb(); \ |
| 387 | } | 387 | } |
| 388 | -#define ST_SWITCH_IN_CB(_thread) \ | 388 | +#define ST_SWITCH_IN_CB(_thread) \ |
| 389 | if (_st_this_vp.switch_in_cb != NULL && \ | 389 | if (_st_this_vp.switch_in_cb != NULL && \ |
| 390 | - _thread != _st_this_vp.idle_thread && \ | ||
| 391 | - _thread->state != _ST_ST_ZOMBIE) { \ | ||
| 392 | - _st_this_vp.switch_in_cb(); \ | 390 | + _thread != _st_this_vp.idle_thread && \ |
| 391 | + _thread->state != _ST_ST_ZOMBIE) { \ | ||
| 392 | + _st_this_vp.switch_in_cb(); \ | ||
| 393 | } | 393 | } |
| 394 | #else | 394 | #else |
| 395 | #define ST_SWITCH_OUT_CB(_thread) | 395 | #define ST_SWITCH_OUT_CB(_thread) |
| @@ -457,10 +457,10 @@ int st_cond_timedwait(_st_cond_t *cvar, st_utime_t timeout); | @@ -457,10 +457,10 @@ int st_cond_timedwait(_st_cond_t *cvar, st_utime_t timeout); | ||
| 457 | int st_cond_signal(_st_cond_t *cvar); | 457 | int st_cond_signal(_st_cond_t *cvar); |
| 458 | ssize_t st_read(_st_netfd_t *fd, void *buf, size_t nbyte, st_utime_t timeout); | 458 | ssize_t st_read(_st_netfd_t *fd, void *buf, size_t nbyte, st_utime_t timeout); |
| 459 | ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte, | 459 | ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte, |
| 460 | - st_utime_t timeout); | 460 | + st_utime_t timeout); |
| 461 | int st_poll(struct pollfd *pds, int npds, st_utime_t timeout); | 461 | int st_poll(struct pollfd *pds, int npds, st_utime_t timeout); |
| 462 | _st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg, | 462 | _st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg, |
| 463 | - int joinable, int stk_size); | 463 | + int joinable, int stk_size); |
| 464 | 464 | ||
| 465 | #endif /* !__ST_COMMON_H__ */ | 465 | #endif /* !__ST_COMMON_H__ */ |
| 466 | 466 |
| @@ -187,7 +187,7 @@ int st_netfd_fileno(_st_netfd_t *fd) | @@ -187,7 +187,7 @@ int st_netfd_fileno(_st_netfd_t *fd) | ||
| 187 | 187 | ||
| 188 | 188 | ||
| 189 | void st_netfd_setspecific(_st_netfd_t *fd, void *value, | 189 | void st_netfd_setspecific(_st_netfd_t *fd, void *value, |
| 190 | - _st_destructor_t destructor) | 190 | + _st_destructor_t destructor) |
| 191 | { | 191 | { |
| 192 | if (value != fd->private_data) { | 192 | if (value != fd->private_data) { |
| 193 | /* Free up previously set non-NULL data value */ | 193 | /* Free up previously set non-NULL data value */ |
| @@ -248,7 +248,7 @@ static void _st_netfd_free_aux_data(_st_netfd_t *fd) | @@ -248,7 +248,7 @@ static void _st_netfd_free_aux_data(_st_netfd_t *fd) | ||
| 248 | } | 248 | } |
| 249 | 249 | ||
| 250 | _st_netfd_t *st_accept(_st_netfd_t *fd, struct sockaddr *addr, int *addrlen, | 250 | _st_netfd_t *st_accept(_st_netfd_t *fd, struct sockaddr *addr, int *addrlen, |
| 251 | - st_utime_t timeout) | 251 | + st_utime_t timeout) |
| 252 | { | 252 | { |
| 253 | int osfd, err; | 253 | int osfd, err; |
| 254 | _st_netfd_t *newfd; | 254 | _st_netfd_t *newfd; |
| @@ -335,7 +335,7 @@ static void _st_netfd_free_aux_data(_st_netfd_t *fd) | @@ -335,7 +335,7 @@ static void _st_netfd_free_aux_data(_st_netfd_t *fd) | ||
| 335 | } | 335 | } |
| 336 | 336 | ||
| 337 | _st_netfd_t *st_accept(_st_netfd_t *fd, struct sockaddr *addr, int *addrlen, | 337 | _st_netfd_t *st_accept(_st_netfd_t *fd, struct sockaddr *addr, int *addrlen, |
| 338 | - st_utime_t timeout) | 338 | + st_utime_t timeout) |
| 339 | { | 339 | { |
| 340 | int osfd, err; | 340 | int osfd, err; |
| 341 | _st_netfd_t *newfd; | 341 | _st_netfd_t *newfd; |
| @@ -415,7 +415,7 @@ int st_connect(_st_netfd_t *fd, const struct sockaddr *addr, int addrlen, | @@ -415,7 +415,7 @@ int st_connect(_st_netfd_t *fd, const struct sockaddr *addr, int addrlen, | ||
| 415 | /* Try to find out whether the connection setup succeeded or failed */ | 415 | /* Try to find out whether the connection setup succeeded or failed */ |
| 416 | n = sizeof(int); | 416 | n = sizeof(int); |
| 417 | if (getsockopt(fd->osfd, SOL_SOCKET, SO_ERROR, (char *)&err, | 417 | if (getsockopt(fd->osfd, SOL_SOCKET, SO_ERROR, (char *)&err, |
| 418 | - (socklen_t *)&n) < 0) | 418 | + (socklen_t *)&n) < 0) |
| 419 | return -1; | 419 | return -1; |
| 420 | if (err) { | 420 | if (err) { |
| 421 | errno = err; | 421 | errno = err; |
| @@ -449,7 +449,7 @@ ssize_t st_read(_st_netfd_t *fd, void *buf, size_t nbyte, st_utime_t timeout) | @@ -449,7 +449,7 @@ ssize_t st_read(_st_netfd_t *fd, void *buf, size_t nbyte, st_utime_t timeout) | ||
| 449 | 449 | ||
| 450 | 450 | ||
| 451 | int st_read_resid(_st_netfd_t *fd, void *buf, size_t *resid, | 451 | int st_read_resid(_st_netfd_t *fd, void *buf, size_t *resid, |
| 452 | - st_utime_t timeout) | 452 | + st_utime_t timeout) |
| 453 | { | 453 | { |
| 454 | struct iovec iov, *riov; | 454 | struct iovec iov, *riov; |
| 455 | int riov_size, rv; | 455 | int riov_size, rv; |
| @@ -465,7 +465,7 @@ int st_read_resid(_st_netfd_t *fd, void *buf, size_t *resid, | @@ -465,7 +465,7 @@ int st_read_resid(_st_netfd_t *fd, void *buf, size_t *resid, | ||
| 465 | 465 | ||
| 466 | 466 | ||
| 467 | ssize_t st_readv(_st_netfd_t *fd, const struct iovec *iov, int iov_size, | 467 | ssize_t st_readv(_st_netfd_t *fd, const struct iovec *iov, int iov_size, |
| 468 | - st_utime_t timeout) | 468 | + st_utime_t timeout) |
| 469 | { | 469 | { |
| 470 | ssize_t n; | 470 | ssize_t n; |
| 471 | 471 | ||
| @@ -483,7 +483,7 @@ ssize_t st_readv(_st_netfd_t *fd, const struct iovec *iov, int iov_size, | @@ -483,7 +483,7 @@ ssize_t st_readv(_st_netfd_t *fd, const struct iovec *iov, int iov_size, | ||
| 483 | } | 483 | } |
| 484 | 484 | ||
| 485 | int st_readv_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size, | 485 | int st_readv_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size, |
| 486 | - st_utime_t timeout) | 486 | + st_utime_t timeout) |
| 487 | { | 487 | { |
| 488 | ssize_t n; | 488 | ssize_t n; |
| 489 | 489 | ||
| @@ -524,7 +524,7 @@ int st_readv_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size, | @@ -524,7 +524,7 @@ int st_readv_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size, | ||
| 524 | 524 | ||
| 525 | 525 | ||
| 526 | ssize_t st_read_fully(_st_netfd_t *fd, void *buf, size_t nbyte, | 526 | ssize_t st_read_fully(_st_netfd_t *fd, void *buf, size_t nbyte, |
| 527 | - st_utime_t timeout) | 527 | + st_utime_t timeout) |
| 528 | { | 528 | { |
| 529 | size_t resid = nbyte; | 529 | size_t resid = nbyte; |
| 530 | return st_read_resid(fd, buf, &resid, timeout) == 0 ? | 530 | return st_read_resid(fd, buf, &resid, timeout) == 0 ? |
| @@ -533,7 +533,7 @@ ssize_t st_read_fully(_st_netfd_t *fd, void *buf, size_t nbyte, | @@ -533,7 +533,7 @@ ssize_t st_read_fully(_st_netfd_t *fd, void *buf, size_t nbyte, | ||
| 533 | 533 | ||
| 534 | 534 | ||
| 535 | int st_write_resid(_st_netfd_t *fd, const void *buf, size_t *resid, | 535 | int st_write_resid(_st_netfd_t *fd, const void *buf, size_t *resid, |
| 536 | - st_utime_t timeout) | 536 | + st_utime_t timeout) |
| 537 | { | 537 | { |
| 538 | struct iovec iov, *riov; | 538 | struct iovec iov, *riov; |
| 539 | int riov_size, rv; | 539 | int riov_size, rv; |
| @@ -549,7 +549,7 @@ int st_write_resid(_st_netfd_t *fd, const void *buf, size_t *resid, | @@ -549,7 +549,7 @@ int st_write_resid(_st_netfd_t *fd, const void *buf, size_t *resid, | ||
| 549 | 549 | ||
| 550 | 550 | ||
| 551 | ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte, | 551 | ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte, |
| 552 | - st_utime_t timeout) | 552 | + st_utime_t timeout) |
| 553 | { | 553 | { |
| 554 | size_t resid = nbyte; | 554 | size_t resid = nbyte; |
| 555 | return st_write_resid(fd, buf, &resid, timeout) == 0 ? | 555 | return st_write_resid(fd, buf, &resid, timeout) == 0 ? |
| @@ -558,7 +558,7 @@ ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte, | @@ -558,7 +558,7 @@ ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte, | ||
| 558 | 558 | ||
| 559 | 559 | ||
| 560 | ssize_t st_writev(_st_netfd_t *fd, const struct iovec *iov, int iov_size, | 560 | ssize_t st_writev(_st_netfd_t *fd, const struct iovec *iov, int iov_size, |
| 561 | - st_utime_t timeout) | 561 | + st_utime_t timeout) |
| 562 | { | 562 | { |
| 563 | ssize_t n, rv; | 563 | ssize_t n, rv; |
| 564 | size_t nleft, nbyte; | 564 | size_t nleft, nbyte; |
| @@ -634,7 +634,7 @@ ssize_t st_writev(_st_netfd_t *fd, const struct iovec *iov, int iov_size, | @@ -634,7 +634,7 @@ ssize_t st_writev(_st_netfd_t *fd, const struct iovec *iov, int iov_size, | ||
| 634 | 634 | ||
| 635 | 635 | ||
| 636 | int st_writev_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size, | 636 | int st_writev_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size, |
| 637 | - st_utime_t timeout) | 637 | + st_utime_t timeout) |
| 638 | { | 638 | { |
| 639 | ssize_t n; | 639 | ssize_t n; |
| 640 | 640 | ||
| @@ -676,7 +676,7 @@ int st_writev_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size, | @@ -676,7 +676,7 @@ int st_writev_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size, | ||
| 676 | * Simple I/O functions for UDP. | 676 | * Simple I/O functions for UDP. |
| 677 | */ | 677 | */ |
| 678 | int st_recvfrom(_st_netfd_t *fd, void *buf, int len, struct sockaddr *from, | 678 | int st_recvfrom(_st_netfd_t *fd, void *buf, int len, struct sockaddr *from, |
| 679 | - int *fromlen, st_utime_t timeout) | 679 | + int *fromlen, st_utime_t timeout) |
| 680 | { | 680 | { |
| 681 | int n; | 681 | int n; |
| 682 | 682 |
trunk/research/st/public.h
100644 → 100755
| 1 | -/* | ||
| 2 | - * The contents of this file are subject to the Mozilla Public | ||
| 3 | - * License Version 1.1 (the "License"); you may not use this file | ||
| 4 | - * except in compliance with the License. You may obtain a copy of | ||
| 5 | - * the License at http://www.mozilla.org/MPL/ | ||
| 6 | - * | ||
| 7 | - * Software distributed under the License is distributed on an "AS | ||
| 8 | - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | ||
| 9 | - * implied. See the License for the specific language governing | ||
| 10 | - * rights and limitations under the License. | ||
| 11 | - * | ||
| 12 | - * The Original Code is the Netscape Portable Runtime library. | ||
| 13 | - * | ||
| 14 | - * The Initial Developer of the Original Code is Netscape | ||
| 15 | - * Communications Corporation. Portions created by Netscape are | ||
| 16 | - * Copyright (C) 1994-2000 Netscape Communications Corporation. All | ||
| 17 | - * Rights Reserved. | ||
| 18 | - * | ||
| 19 | - * Contributor(s): Silicon Graphics, Inc. | ||
| 20 | - * | ||
| 21 | - * Portions created by SGI are Copyright (C) 2000-2001 Silicon | ||
| 22 | - * Graphics, Inc. All Rights Reserved. | ||
| 23 | - * | ||
| 24 | - * Alternatively, the contents of this file may be used under the | ||
| 25 | - * terms of the GNU General Public License Version 2 or later (the | ||
| 26 | - * "GPL"), in which case the provisions of the GPL are applicable | ||
| 27 | - * instead of those above. If you wish to allow use of your | ||
| 28 | - * version of this file only under the terms of the GPL and not to | ||
| 29 | - * allow others to use your version of this file under the MPL, | ||
| 30 | - * indicate your decision by deleting the provisions above and | ||
| 31 | - * replace them with the notice and other provisions required by | ||
| 32 | - * the GPL. If you do not delete the provisions above, a recipient | ||
| 33 | - * may use your version of this file under either the MPL or the | ||
| 34 | - * GPL. | ||
| 35 | - */ | ||
| 36 | - | ||
| 37 | -#ifndef __ST_THREAD_H__ | ||
| 38 | -#define __ST_THREAD_H__ | ||
| 39 | - | ||
| 40 | -#include <unistd.h> | ||
| 41 | -#include <sys/types.h> | ||
| 42 | -#include <sys/socket.h> | ||
| 43 | -#include <sys/uio.h> | ||
| 44 | -#include <time.h> | ||
| 45 | -#include <errno.h> | ||
| 46 | -#include <poll.h> | ||
| 47 | - | ||
| 48 | -#define ST_VERSION "1.9" | ||
| 49 | -#define ST_VERSION_MAJOR 1 | ||
| 50 | -#define ST_VERSION_MINOR 9 | ||
| 51 | - | ||
| 52 | -/* Undefine this to remove the context switch callback feature. */ | ||
| 53 | -#define ST_SWITCH_CB | ||
| 54 | - | ||
| 55 | -#ifndef ETIME | ||
| 56 | -#define ETIME ETIMEDOUT | ||
| 57 | -#endif | ||
| 58 | - | ||
| 59 | -#ifndef ST_UTIME_NO_TIMEOUT | ||
| 60 | -#define ST_UTIME_NO_TIMEOUT ((st_utime_t) -1LL) | ||
| 61 | -#endif | ||
| 62 | - | ||
| 63 | -#ifndef ST_UTIME_NO_WAIT | ||
| 64 | -#define ST_UTIME_NO_WAIT 0 | ||
| 65 | -#endif | ||
| 66 | - | ||
| 67 | -#define ST_EVENTSYS_DEFAULT 0 | ||
| 68 | -#define ST_EVENTSYS_SELECT 1 | ||
| 69 | -#define ST_EVENTSYS_POLL 2 | ||
| 70 | -#define ST_EVENTSYS_ALT 3 | ||
| 71 | - | ||
| 72 | -#ifdef __cplusplus | ||
| 73 | -extern "C" { | ||
| 74 | -#endif | ||
| 75 | - | ||
| 76 | -typedef unsigned long long st_utime_t; | ||
| 77 | -typedef struct _st_thread * st_thread_t; | ||
| 78 | -typedef struct _st_cond * st_cond_t; | ||
| 79 | -typedef struct _st_mutex * st_mutex_t; | ||
| 80 | -typedef struct _st_netfd * st_netfd_t; | ||
| 81 | -#ifdef ST_SWITCH_CB | ||
| 82 | -typedef void (*st_switch_cb_t)(void); | ||
| 83 | -#endif | ||
| 84 | - | ||
| 85 | -extern int st_init(void); | ||
| 86 | -extern int st_getfdlimit(void); | ||
| 87 | - | ||
| 88 | -extern int st_set_eventsys(int eventsys); | ||
| 89 | -extern int st_get_eventsys(void); | ||
| 90 | -extern const char *st_get_eventsys_name(void); | ||
| 91 | - | ||
| 92 | -#ifdef ST_SWITCH_CB | ||
| 93 | -extern st_switch_cb_t st_set_switch_in_cb(st_switch_cb_t cb); | ||
| 94 | -extern st_switch_cb_t st_set_switch_out_cb(st_switch_cb_t cb); | ||
| 95 | -#endif | ||
| 96 | - | ||
| 97 | -extern st_thread_t st_thread_self(void); | ||
| 98 | -extern void st_thread_exit(void *retval); | ||
| 99 | -extern int st_thread_join(st_thread_t thread, void **retvalp); | ||
| 100 | -extern void st_thread_interrupt(st_thread_t thread); | ||
| 101 | -extern st_thread_t st_thread_create(void *(*start)(void *arg), void *arg, | ||
| 102 | - int joinable, int stack_size); | ||
| 103 | -extern int st_randomize_stacks(int on); | ||
| 104 | -extern int st_set_utime_function(st_utime_t (*func)(void)); | ||
| 105 | - | ||
| 106 | -extern st_utime_t st_utime(void); | ||
| 107 | -extern st_utime_t st_utime_last_clock(void); | ||
| 108 | -extern int st_timecache_set(int on); | ||
| 109 | -extern time_t st_time(void); | ||
| 110 | -extern int st_usleep(st_utime_t usecs); | ||
| 111 | -extern int st_sleep(int secs); | ||
| 112 | -extern st_cond_t st_cond_new(void); | ||
| 113 | -extern int st_cond_destroy(st_cond_t cvar); | ||
| 114 | -extern int st_cond_timedwait(st_cond_t cvar, st_utime_t timeout); | ||
| 115 | -extern int st_cond_wait(st_cond_t cvar); | ||
| 116 | -extern int st_cond_signal(st_cond_t cvar); | ||
| 117 | -extern int st_cond_broadcast(st_cond_t cvar); | ||
| 118 | -extern st_mutex_t st_mutex_new(void); | ||
| 119 | -extern int st_mutex_destroy(st_mutex_t lock); | ||
| 120 | -extern int st_mutex_lock(st_mutex_t lock); | ||
| 121 | -extern int st_mutex_unlock(st_mutex_t lock); | ||
| 122 | -extern int st_mutex_trylock(st_mutex_t lock); | ||
| 123 | - | ||
| 124 | -extern int st_key_create(int *keyp, void (*destructor)(void *)); | ||
| 125 | -extern int st_key_getlimit(void); | ||
| 126 | -extern int st_thread_setspecific(int key, void *value); | ||
| 127 | -extern void *st_thread_getspecific(int key); | ||
| 128 | - | ||
| 129 | -extern st_netfd_t st_netfd_open(int osfd); | ||
| 130 | -extern st_netfd_t st_netfd_open_socket(int osfd); | ||
| 131 | -extern void st_netfd_free(st_netfd_t fd); | ||
| 132 | -extern int st_netfd_close(st_netfd_t fd); | ||
| 133 | -extern int st_netfd_fileno(st_netfd_t fd); | ||
| 134 | -extern void st_netfd_setspecific(st_netfd_t fd, void *value, | ||
| 135 | - void (*destructor)(void *)); | ||
| 136 | -extern void *st_netfd_getspecific(st_netfd_t fd); | ||
| 137 | -extern int st_netfd_serialize_accept(st_netfd_t fd); | ||
| 138 | -extern int st_netfd_poll(st_netfd_t fd, int how, st_utime_t timeout); | ||
| 139 | - | ||
| 140 | -extern int st_poll(struct pollfd *pds, int npds, st_utime_t timeout); | ||
| 141 | -extern st_netfd_t st_accept(st_netfd_t fd, struct sockaddr *addr, int *addrlen, | ||
| 142 | - st_utime_t timeout); | ||
| 143 | -extern int st_connect(st_netfd_t fd, const struct sockaddr *addr, int addrlen, | ||
| 144 | - st_utime_t timeout); | ||
| 145 | -extern ssize_t st_read(st_netfd_t fd, void *buf, size_t nbyte, | ||
| 146 | - st_utime_t timeout); | ||
| 147 | -extern ssize_t st_read_fully(st_netfd_t fd, void *buf, size_t nbyte, | ||
| 148 | - st_utime_t timeout); | ||
| 149 | -extern int st_read_resid(st_netfd_t fd, void *buf, size_t *resid, | ||
| 150 | - st_utime_t timeout); | ||
| 151 | -extern ssize_t st_readv(st_netfd_t fd, const struct iovec *iov, int iov_size, | ||
| 152 | - st_utime_t timeout); | ||
| 153 | -extern int st_readv_resid(st_netfd_t fd, struct iovec **iov, int *iov_size, | ||
| 154 | - st_utime_t timeout); | ||
| 155 | -extern ssize_t st_write(st_netfd_t fd, const void *buf, size_t nbyte, | ||
| 156 | - st_utime_t timeout); | ||
| 157 | -extern int st_write_resid(st_netfd_t fd, const void *buf, size_t *resid, | ||
| 158 | - st_utime_t timeout); | ||
| 159 | -extern ssize_t st_writev(st_netfd_t fd, const struct iovec *iov, int iov_size, | ||
| 160 | - st_utime_t timeout); | ||
| 161 | -extern int st_writev_resid(st_netfd_t fd, struct iovec **iov, int *iov_size, | ||
| 162 | - st_utime_t timeout); | ||
| 163 | -extern int st_recvfrom(st_netfd_t fd, void *buf, int len, | ||
| 164 | - struct sockaddr *from, int *fromlen, | ||
| 165 | - st_utime_t timeout); | ||
| 166 | -extern int st_sendto(st_netfd_t fd, const void *msg, int len, | ||
| 167 | - const struct sockaddr *to, int tolen, st_utime_t timeout); | ||
| 168 | -extern int st_recvmsg(st_netfd_t fd, struct msghdr *msg, int flags, | ||
| 169 | - st_utime_t timeout); | ||
| 170 | -extern int st_sendmsg(st_netfd_t fd, const struct msghdr *msg, int flags, | ||
| 171 | - st_utime_t timeout); | ||
| 172 | -extern st_netfd_t st_open(const char *path, int oflags, mode_t mode); | ||
| 173 | - | ||
| 174 | -#ifdef DEBUG | ||
| 175 | -extern void _st_show_thread_stack(st_thread_t thread, const char *messg); | ||
| 176 | -extern void _st_iterate_threads(void); | ||
| 177 | -#endif | ||
| 178 | - | ||
| 179 | -#ifdef __cplusplus | ||
| 180 | -} | ||
| 181 | -#endif | ||
| 182 | - | ||
| 183 | -#endif /* !__ST_THREAD_H__ */ | ||
| 184 | - | 1 | +/* |
| 2 | + * The contents of this file are subject to the Mozilla Public | ||
| 3 | + * License Version 1.1 (the "License"); you may not use this file | ||
| 4 | + * except in compliance with the License. You may obtain a copy of | ||
| 5 | + * the License at http://www.mozilla.org/MPL/ | ||
| 6 | + * | ||
| 7 | + * Software distributed under the License is distributed on an "AS | ||
| 8 | + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | ||
| 9 | + * implied. See the License for the specific language governing | ||
| 10 | + * rights and limitations under the License. | ||
| 11 | + * | ||
| 12 | + * The Original Code is the Netscape Portable Runtime library. | ||
| 13 | + * | ||
| 14 | + * The Initial Developer of the Original Code is Netscape | ||
| 15 | + * Communications Corporation. Portions created by Netscape are | ||
| 16 | + * Copyright (C) 1994-2000 Netscape Communications Corporation. All | ||
| 17 | + * Rights Reserved. | ||
| 18 | + * | ||
| 19 | + * Contributor(s): Silicon Graphics, Inc. | ||
| 20 | + * | ||
| 21 | + * Portions created by SGI are Copyright (C) 2000-2001 Silicon | ||
| 22 | + * Graphics, Inc. All Rights Reserved. | ||
| 23 | + * | ||
| 24 | + * Alternatively, the contents of this file may be used under the | ||
| 25 | + * terms of the GNU General Public License Version 2 or later (the | ||
| 26 | + * "GPL"), in which case the provisions of the GPL are applicable | ||
| 27 | + * instead of those above. If you wish to allow use of your | ||
| 28 | + * version of this file only under the terms of the GPL and not to | ||
| 29 | + * allow others to use your version of this file under the MPL, | ||
| 30 | + * indicate your decision by deleting the provisions above and | ||
| 31 | + * replace them with the notice and other provisions required by | ||
| 32 | + * the GPL. If you do not delete the provisions above, a recipient | ||
| 33 | + * may use your version of this file under either the MPL or the | ||
| 34 | + * GPL. | ||
| 35 | + */ | ||
| 36 | + | ||
| 37 | +#ifndef __ST_THREAD_H__ | ||
| 38 | +#define __ST_THREAD_H__ | ||
| 39 | + | ||
| 40 | +#include <unistd.h> | ||
| 41 | +#include <sys/types.h> | ||
| 42 | +#include <sys/socket.h> | ||
| 43 | +#include <sys/uio.h> | ||
| 44 | +#include <time.h> | ||
| 45 | +#include <errno.h> | ||
| 46 | +#include <poll.h> | ||
| 47 | + | ||
| 48 | +#define ST_VERSION "1.9" | ||
| 49 | +#define ST_VERSION_MAJOR 1 | ||
| 50 | +#define ST_VERSION_MINOR 9 | ||
| 51 | + | ||
| 52 | +/* Undefine this to remove the context switch callback feature. */ | ||
| 53 | +#define ST_SWITCH_CB | ||
| 54 | + | ||
| 55 | +#ifndef ETIME | ||
| 56 | + #define ETIME ETIMEDOUT | ||
| 57 | +#endif | ||
| 58 | + | ||
| 59 | +#ifndef ST_UTIME_NO_TIMEOUT | ||
| 60 | + #define ST_UTIME_NO_TIMEOUT ((st_utime_t) -1LL) | ||
| 61 | +#endif | ||
| 62 | + | ||
| 63 | +#ifndef ST_UTIME_NO_WAIT | ||
| 64 | + #define ST_UTIME_NO_WAIT 0 | ||
| 65 | +#endif | ||
| 66 | + | ||
| 67 | +#define ST_EVENTSYS_DEFAULT 0 | ||
| 68 | +#define ST_EVENTSYS_SELECT 1 | ||
| 69 | +#define ST_EVENTSYS_POLL 2 | ||
| 70 | +#define ST_EVENTSYS_ALT 3 | ||
| 71 | + | ||
| 72 | +#ifdef __cplusplus | ||
| 73 | +extern "C" { | ||
| 74 | +#endif | ||
| 75 | + typedef unsigned long long st_utime_t; | ||
| 76 | + typedef struct _st_thread * st_thread_t; | ||
| 77 | + typedef struct _st_cond * st_cond_t; | ||
| 78 | + typedef struct _st_mutex * st_mutex_t; | ||
| 79 | + typedef struct _st_netfd * st_netfd_t; | ||
| 80 | + #ifdef ST_SWITCH_CB | ||
| 81 | + typedef void (*st_switch_cb_t)(void); | ||
| 82 | + #endif | ||
| 83 | + | ||
| 84 | + extern int st_init(void); | ||
| 85 | + extern int st_getfdlimit(void); | ||
| 86 | + | ||
| 87 | + extern int st_set_eventsys(int eventsys); | ||
| 88 | + extern int st_get_eventsys(void); | ||
| 89 | + extern const char *st_get_eventsys_name(void); | ||
| 90 | + | ||
| 91 | + #ifdef ST_SWITCH_CB | ||
| 92 | + extern st_switch_cb_t st_set_switch_in_cb(st_switch_cb_t cb); | ||
| 93 | + extern st_switch_cb_t st_set_switch_out_cb(st_switch_cb_t cb); | ||
| 94 | + #endif | ||
| 95 | + | ||
| 96 | + extern st_thread_t st_thread_self(void); | ||
| 97 | + extern void st_thread_exit(void *retval); | ||
| 98 | + extern int st_thread_join(st_thread_t thread, void **retvalp); | ||
| 99 | + extern void st_thread_interrupt(st_thread_t thread); | ||
| 100 | + extern st_thread_t st_thread_create(void *(*start)(void *arg), void *arg, | ||
| 101 | + int joinable, int stack_size); | ||
| 102 | + extern int st_randomize_stacks(int on); | ||
| 103 | + extern int st_set_utime_function(st_utime_t (*func)(void)); | ||
| 104 | + | ||
| 105 | + extern st_utime_t st_utime(void); | ||
| 106 | + extern st_utime_t st_utime_last_clock(void); | ||
| 107 | + extern int st_timecache_set(int on); | ||
| 108 | + extern time_t st_time(void); | ||
| 109 | + extern int st_usleep(st_utime_t usecs); | ||
| 110 | + extern int st_sleep(int secs); | ||
| 111 | + extern st_cond_t st_cond_new(void); | ||
| 112 | + extern int st_cond_destroy(st_cond_t cvar); | ||
| 113 | + extern int st_cond_timedwait(st_cond_t cvar, st_utime_t timeout); | ||
| 114 | + extern int st_cond_wait(st_cond_t cvar); | ||
| 115 | + extern int st_cond_signal(st_cond_t cvar); | ||
| 116 | + extern int st_cond_broadcast(st_cond_t cvar); | ||
| 117 | + extern st_mutex_t st_mutex_new(void); | ||
| 118 | + extern int st_mutex_destroy(st_mutex_t lock); | ||
| 119 | + extern int st_mutex_lock(st_mutex_t lock); | ||
| 120 | + extern int st_mutex_unlock(st_mutex_t lock); | ||
| 121 | + extern int st_mutex_trylock(st_mutex_t lock); | ||
| 122 | + | ||
| 123 | + extern int st_key_create(int *keyp, void (*destructor)(void *)); | ||
| 124 | + extern int st_key_getlimit(void); | ||
| 125 | + extern int st_thread_setspecific(int key, void *value); | ||
| 126 | + extern void *st_thread_getspecific(int key); | ||
| 127 | + | ||
| 128 | + extern st_netfd_t st_netfd_open(int osfd); | ||
| 129 | + extern st_netfd_t st_netfd_open_socket(int osfd); | ||
| 130 | + extern void st_netfd_free(st_netfd_t fd); | ||
| 131 | + extern int st_netfd_close(st_netfd_t fd); | ||
| 132 | + extern int st_netfd_fileno(st_netfd_t fd); | ||
| 133 | + extern void st_netfd_setspecific(st_netfd_t fd, void *value, | ||
| 134 | + void (*destructor)(void *)); | ||
| 135 | + extern void *st_netfd_getspecific(st_netfd_t fd); | ||
| 136 | + extern int st_netfd_serialize_accept(st_netfd_t fd); | ||
| 137 | + extern int st_netfd_poll(st_netfd_t fd, int how, st_utime_t timeout); | ||
| 138 | + | ||
| 139 | + extern int st_poll(struct pollfd *pds, int npds, st_utime_t timeout); | ||
| 140 | + extern st_netfd_t st_accept(st_netfd_t fd, struct sockaddr *addr, int *addrlen, | ||
| 141 | + st_utime_t timeout); | ||
| 142 | + extern int st_connect(st_netfd_t fd, const struct sockaddr *addr, int addrlen, | ||
| 143 | + st_utime_t timeout); | ||
| 144 | + extern ssize_t st_read(st_netfd_t fd, void *buf, size_t nbyte, | ||
| 145 | + st_utime_t timeout); | ||
| 146 | + extern ssize_t st_read_fully(st_netfd_t fd, void *buf, size_t nbyte, | ||
| 147 | + st_utime_t timeout); | ||
| 148 | + extern int st_read_resid(st_netfd_t fd, void *buf, size_t *resid, | ||
| 149 | + st_utime_t timeout); | ||
| 150 | + extern ssize_t st_readv(st_netfd_t fd, const struct iovec *iov, int iov_size, | ||
| 151 | + st_utime_t timeout); | ||
| 152 | + extern int st_readv_resid(st_netfd_t fd, struct iovec **iov, int *iov_size, | ||
| 153 | + st_utime_t timeout); | ||
| 154 | + extern ssize_t st_write(st_netfd_t fd, const void *buf, size_t nbyte, | ||
| 155 | + st_utime_t timeout); | ||
| 156 | + extern int st_write_resid(st_netfd_t fd, const void *buf, size_t *resid, | ||
| 157 | + st_utime_t timeout); | ||
| 158 | + extern ssize_t st_writev(st_netfd_t fd, const struct iovec *iov, int iov_size, | ||
| 159 | + st_utime_t timeout); | ||
| 160 | + extern int st_writev_resid(st_netfd_t fd, struct iovec **iov, int *iov_size, | ||
| 161 | + st_utime_t timeout); | ||
| 162 | + extern int st_recvfrom(st_netfd_t fd, void *buf, int len, | ||
| 163 | + struct sockaddr *from, int *fromlen, | ||
| 164 | + st_utime_t timeout); | ||
| 165 | + extern int st_sendto(st_netfd_t fd, const void *msg, int len, | ||
| 166 | + const struct sockaddr *to, int tolen, st_utime_t timeout); | ||
| 167 | + extern int st_recvmsg(st_netfd_t fd, struct msghdr *msg, int flags, | ||
| 168 | + st_utime_t timeout); | ||
| 169 | + extern int st_sendmsg(st_netfd_t fd, const struct msghdr *msg, int flags, | ||
| 170 | + st_utime_t timeout); | ||
| 171 | + extern st_netfd_t st_open(const char *path, int oflags, mode_t mode); | ||
| 172 | + | ||
| 173 | + #ifdef DEBUG | ||
| 174 | + extern void _st_show_thread_stack(st_thread_t thread, const char *messg); | ||
| 175 | + extern void _st_iterate_threads(void); | ||
| 176 | + #endif | ||
| 177 | +#ifdef __cplusplus | ||
| 178 | +} | ||
| 179 | +#endif | ||
| 180 | + | ||
| 181 | +#endif /* !__ST_THREAD_H__ */ | ||
| 182 | + |
| @@ -165,7 +165,7 @@ int st_init(void) | @@ -165,7 +165,7 @@ int st_init(void) | ||
| 165 | * Create idle thread | 165 | * Create idle thread |
| 166 | */ | 166 | */ |
| 167 | _st_this_vp.idle_thread = st_thread_create(_st_idle_thread_start, | 167 | _st_this_vp.idle_thread = st_thread_create(_st_idle_thread_start, |
| 168 | - NULL, 0, 0); | 168 | + NULL, 0, 0); |
| 169 | if (!_st_this_vp.idle_thread) | 169 | if (!_st_this_vp.idle_thread) |
| 170 | return -1; | 170 | return -1; |
| 171 | _st_this_vp.idle_thread->flags = _ST_FL_IDLE_THREAD; | 171 | _st_this_vp.idle_thread->flags = _ST_FL_IDLE_THREAD; |
| @@ -176,7 +176,7 @@ int st_init(void) | @@ -176,7 +176,7 @@ int st_init(void) | ||
| 176 | * Initialize primordial thread | 176 | * Initialize primordial thread |
| 177 | */ | 177 | */ |
| 178 | thread = (_st_thread_t *) calloc(1, sizeof(_st_thread_t) + | 178 | thread = (_st_thread_t *) calloc(1, sizeof(_st_thread_t) + |
| 179 | - (ST_KEYS_MAX * sizeof(void *))); | 179 | + (ST_KEYS_MAX * sizeof(void *))); |
| 180 | if (!thread) | 180 | if (!thread) |
| 181 | return -1; | 181 | return -1; |
| 182 | thread->private_data = (void **) (thread + 1); | 182 | thread->private_data = (void **) (thread + 1); |
| @@ -518,7 +518,7 @@ void st_thread_interrupt(_st_thread_t *thread) | @@ -518,7 +518,7 @@ void st_thread_interrupt(_st_thread_t *thread) | ||
| 518 | 518 | ||
| 519 | 519 | ||
| 520 | _st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg, | 520 | _st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg, |
| 521 | - int joinable, int stk_size) | 521 | + int joinable, int stk_size) |
| 522 | { | 522 | { |
| 523 | _st_thread_t *thread; | 523 | _st_thread_t *thread; |
| 524 | _st_stack_t *stack; | 524 | _st_stack_t *stack; |
| @@ -143,7 +143,7 @@ int st_usleep(st_utime_t usecs) | @@ -143,7 +143,7 @@ int st_usleep(st_utime_t usecs) | ||
| 143 | int st_sleep(int secs) | 143 | int st_sleep(int secs) |
| 144 | { | 144 | { |
| 145 | return st_usleep((secs >= 0) ? secs * (st_utime_t) 1000000LL : | 145 | return st_usleep((secs >= 0) ? secs * (st_utime_t) 1000000LL : |
| 146 | - ST_UTIME_NO_TIMEOUT); | 146 | + ST_UTIME_NO_TIMEOUT); |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | 149 |
-
请 注册 或 登录 后发表评论