正在显示
3 个修改的文件
包含
48 行增加
和
56 行删除
| @@ -50,7 +50,7 @@ | @@ -50,7 +50,7 @@ | ||
| 50 | 50 | ||
| 51 | /* Enable assertions only if DEBUG is defined */ | 51 | /* Enable assertions only if DEBUG is defined */ |
| 52 | #ifndef DEBUG | 52 | #ifndef DEBUG |
| 53 | -#define NDEBUG | 53 | + #define NDEBUG |
| 54 | #endif | 54 | #endif |
| 55 | #include <assert.h> | 55 | #include <assert.h> |
| 56 | #define ST_ASSERT(expr) assert(expr) | 56 | #define ST_ASSERT(expr) assert(expr) |
| @@ -59,15 +59,14 @@ | @@ -59,15 +59,14 @@ | ||
| 59 | #define ST_END_MACRO } | 59 | #define ST_END_MACRO } |
| 60 | 60 | ||
| 61 | #ifdef DEBUG | 61 | #ifdef DEBUG |
| 62 | -#define ST_HIDDEN /*nothing*/ | 62 | + #define ST_HIDDEN /*nothing*/ |
| 63 | #else | 63 | #else |
| 64 | -#define ST_HIDDEN static | 64 | + #define ST_HIDDEN static |
| 65 | #endif | 65 | #endif |
| 66 | 66 | ||
| 67 | #include "public.h" | 67 | #include "public.h" |
| 68 | #include "md.h" | 68 | #include "md.h" |
| 69 | 69 | ||
| 70 | - | ||
| 71 | /***************************************** | 70 | /***************************************** |
| 72 | * Circular linked list definitions | 71 | * Circular linked list definitions |
| 73 | */ | 72 | */ |
| @@ -137,7 +136,6 @@ typedef struct _st_clist { | @@ -137,7 +136,6 @@ typedef struct _st_clist { | ||
| 137 | 136 | ||
| 138 | typedef void (*_st_destructor_t)(void *); | 137 | typedef void (*_st_destructor_t)(void *); |
| 139 | 138 | ||
| 140 | - | ||
| 141 | typedef struct _st_stack { | 139 | typedef struct _st_stack { |
| 142 | _st_clist_t links; | 140 | _st_clist_t links; |
| 143 | char *vaddr; /* Base of stack's allocated memory */ | 141 | char *vaddr; /* Base of stack's allocated memory */ |
| @@ -146,9 +144,9 @@ typedef struct _st_stack { | @@ -146,9 +144,9 @@ typedef struct _st_stack { | ||
| 146 | char *stk_bottom; /* Lowest address of stack's usable portion */ | 144 | char *stk_bottom; /* Lowest address of stack's usable portion */ |
| 147 | char *stk_top; /* Highest address of stack's usable portion */ | 145 | char *stk_top; /* Highest address of stack's usable portion */ |
| 148 | void *sp; /* Stack pointer from C's point of view */ | 146 | void *sp; /* Stack pointer from C's point of view */ |
| 149 | -#ifdef __ia64__ | 147 | + #ifdef __ia64__ |
| 150 | void *bsp; /* Register stack backing store pointer */ | 148 | void *bsp; /* Register stack backing store pointer */ |
| 151 | -#endif | 149 | + #endif |
| 152 | } _st_stack_t; | 150 | } _st_stack_t; |
| 153 | 151 | ||
| 154 | 152 | ||
| @@ -171,9 +169,9 @@ struct _st_thread { | @@ -171,9 +169,9 @@ struct _st_thread { | ||
| 171 | 169 | ||
| 172 | _st_clist_t links; /* For putting on run/sleep/zombie queue */ | 170 | _st_clist_t links; /* For putting on run/sleep/zombie queue */ |
| 173 | _st_clist_t wait_links; /* For putting on mutex/condvar wait queue */ | 171 | _st_clist_t wait_links; /* For putting on mutex/condvar wait queue */ |
| 174 | -#ifdef DEBUG | 172 | + #ifdef DEBUG |
| 175 | _st_clist_t tlink; /* For putting on thread queue */ | 173 | _st_clist_t tlink; /* For putting on thread queue */ |
| 176 | -#endif | 174 | + #endif |
| 177 | 175 | ||
| 178 | st_utime_t due; /* Wakeup time when thread is sleeping */ | 176 | st_utime_t due; /* Wakeup time when thread is sleeping */ |
| 179 | _st_thread_t *left; /* For putting in timeout heap */ | 177 | _st_thread_t *left; /* For putting in timeout heap */ |
| @@ -223,18 +221,18 @@ typedef struct _st_vp { | @@ -223,18 +221,18 @@ typedef struct _st_vp { | ||
| 223 | _st_clist_t run_q; /* run queue for this vp */ | 221 | _st_clist_t run_q; /* run queue for this vp */ |
| 224 | _st_clist_t io_q; /* io queue for this vp */ | 222 | _st_clist_t io_q; /* io queue for this vp */ |
| 225 | _st_clist_t zombie_q; /* zombie queue for this vp */ | 223 | _st_clist_t zombie_q; /* zombie queue for this vp */ |
| 226 | -#ifdef DEBUG | 224 | + #ifdef DEBUG |
| 227 | _st_clist_t thread_q; /* all threads of this vp */ | 225 | _st_clist_t thread_q; /* all threads of this vp */ |
| 228 | -#endif | 226 | + #endif |
| 229 | int pagesize; | 227 | int pagesize; |
| 230 | 228 | ||
| 231 | _st_thread_t *sleep_q; /* sleep queue for this vp */ | 229 | _st_thread_t *sleep_q; /* sleep queue for this vp */ |
| 232 | int sleepq_size; /* number of threads on sleep queue */ | 230 | int sleepq_size; /* number of threads on sleep queue */ |
| 233 | 231 | ||
| 234 | -#ifdef ST_SWITCH_CB | 232 | + #ifdef ST_SWITCH_CB |
| 235 | st_switch_cb_t switch_out_cb; /* called when a thread is switched out */ | 233 | st_switch_cb_t switch_out_cb; /* called when a thread is switched out */ |
| 236 | st_switch_cb_t switch_in_cb; /* called when a thread is switched in */ | 234 | st_switch_cb_t switch_in_cb; /* called when a thread is switched in */ |
| 237 | -#endif | 235 | + #endif |
| 238 | } _st_vp_t; | 236 | } _st_vp_t; |
| 239 | 237 | ||
| 240 | 238 | ||
| @@ -265,7 +263,7 @@ extern _st_eventsys_t *_st_eventsys; | @@ -265,7 +263,7 @@ extern _st_eventsys_t *_st_eventsys; | ||
| 265 | #define _ST_IOQ (_st_this_vp.io_q) | 263 | #define _ST_IOQ (_st_this_vp.io_q) |
| 266 | #define _ST_ZOMBIEQ (_st_this_vp.zombie_q) | 264 | #define _ST_ZOMBIEQ (_st_this_vp.zombie_q) |
| 267 | #ifdef DEBUG | 265 | #ifdef DEBUG |
| 268 | -#define _ST_THREADQ (_st_this_vp.thread_q) | 266 | + #define _ST_THREADQ (_st_this_vp.thread_q) |
| 269 | #endif | 267 | #endif |
| 270 | 268 | ||
| 271 | #define _ST_PAGE_SIZE (_st_this_vp.pagesize) | 269 | #define _ST_PAGE_SIZE (_st_this_vp.pagesize) |
| @@ -293,8 +291,8 @@ extern _st_eventsys_t *_st_eventsys; | @@ -293,8 +291,8 @@ extern _st_eventsys_t *_st_eventsys; | ||
| 293 | #define _ST_DEL_ZOMBIEQ(_thr) ST_REMOVE_LINK(&(_thr)->links) | 291 | #define _ST_DEL_ZOMBIEQ(_thr) ST_REMOVE_LINK(&(_thr)->links) |
| 294 | 292 | ||
| 295 | #ifdef DEBUG | 293 | #ifdef DEBUG |
| 296 | -#define _ST_ADD_THREADQ(_thr) ST_APPEND_LINK(&(_thr)->tlink, &_ST_THREADQ) | ||
| 297 | -#define _ST_DEL_THREADQ(_thr) ST_REMOVE_LINK(&(_thr)->tlink) | 294 | + #define _ST_ADD_THREADQ(_thr) ST_APPEND_LINK(&(_thr)->tlink, &_ST_THREADQ) |
| 295 | + #define _ST_DEL_THREADQ(_thr) ST_REMOVE_LINK(&(_thr)->tlink) | ||
| 298 | #endif | 296 | #endif |
| 299 | 297 | ||
| 300 | 298 | ||
| @@ -317,13 +315,12 @@ extern _st_eventsys_t *_st_eventsys; | @@ -317,13 +315,12 @@ extern _st_eventsys_t *_st_eventsys; | ||
| 317 | #define _ST_FL_INTERRUPT 0x08 | 315 | #define _ST_FL_INTERRUPT 0x08 |
| 318 | #define _ST_FL_TIMEDOUT 0x10 | 316 | #define _ST_FL_TIMEDOUT 0x10 |
| 319 | 317 | ||
| 320 | - | ||
| 321 | /***************************************** | 318 | /***************************************** |
| 322 | * Pointer conversion | 319 | * Pointer conversion |
| 323 | */ | 320 | */ |
| 324 | 321 | ||
| 325 | #ifndef offsetof | 322 | #ifndef offsetof |
| 326 | -#define offsetof(type, identifier) ((size_t)&(((type *)0)->identifier)) | 323 | + #define offsetof(type, identifier) ((size_t)&(((type *)0)->identifier)) |
| 327 | #endif | 324 | #endif |
| 328 | 325 | ||
| 329 | #define _ST_THREAD_PTR(_qp) \ | 326 | #define _ST_THREAD_PTR(_qp) \ |
| @@ -339,7 +336,7 @@ extern _st_eventsys_t *_st_eventsys; | @@ -339,7 +336,7 @@ extern _st_eventsys_t *_st_eventsys; | ||
| 339 | ((_st_pollq_t *)((char *)(_qp) - offsetof(_st_pollq_t, links))) | 336 | ((_st_pollq_t *)((char *)(_qp) - offsetof(_st_pollq_t, links))) |
| 340 | 337 | ||
| 341 | #ifdef DEBUG | 338 | #ifdef DEBUG |
| 342 | -#define _ST_THREAD_THREADQ_PTR(_qp) \ | 339 | + #define _ST_THREAD_THREADQ_PTR(_qp) \ |
| 343 | ((_st_thread_t *)((char *)(_qp) - offsetof(_st_thread_t, tlink))) | 340 | ((_st_thread_t *)((char *)(_qp) - offsetof(_st_thread_t, tlink))) |
| 344 | #endif | 341 | #endif |
| 345 | 342 | ||
| @@ -349,21 +346,21 @@ extern _st_eventsys_t *_st_eventsys; | @@ -349,21 +346,21 @@ extern _st_eventsys_t *_st_eventsys; | ||
| 349 | */ | 346 | */ |
| 350 | 347 | ||
| 351 | #ifndef ST_UTIME_NO_TIMEOUT | 348 | #ifndef ST_UTIME_NO_TIMEOUT |
| 352 | -#define ST_UTIME_NO_TIMEOUT ((st_utime_t) -1LL) | 349 | + #define ST_UTIME_NO_TIMEOUT ((st_utime_t) -1LL) |
| 353 | #endif | 350 | #endif |
| 354 | 351 | ||
| 355 | #ifndef __ia64__ | 352 | #ifndef __ia64__ |
| 356 | -#define ST_DEFAULT_STACK_SIZE (64*1024) | 353 | + #define ST_DEFAULT_STACK_SIZE (64*1024) |
| 357 | #else | 354 | #else |
| 358 | -#define ST_DEFAULT_STACK_SIZE (128*1024) /* Includes register stack size */ | 355 | + #define ST_DEFAULT_STACK_SIZE (128*1024) /* Includes register stack size */ |
| 359 | #endif | 356 | #endif |
| 360 | 357 | ||
| 361 | #ifndef ST_KEYS_MAX | 358 | #ifndef ST_KEYS_MAX |
| 362 | -#define ST_KEYS_MAX 16 | 359 | + #define ST_KEYS_MAX 16 |
| 363 | #endif | 360 | #endif |
| 364 | 361 | ||
| 365 | #ifndef ST_MIN_POLLFDS_SIZE | 362 | #ifndef ST_MIN_POLLFDS_SIZE |
| 366 | -#define ST_MIN_POLLFDS_SIZE 64 | 363 | + #define ST_MIN_POLLFDS_SIZE 64 |
| 367 | #endif | 364 | #endif |
| 368 | 365 | ||
| 369 | 366 | ||
| @@ -372,28 +369,28 @@ extern _st_eventsys_t *_st_eventsys; | @@ -372,28 +369,28 @@ extern _st_eventsys_t *_st_eventsys; | ||
| 372 | */ | 369 | */ |
| 373 | 370 | ||
| 374 | #ifdef DEBUG | 371 | #ifdef DEBUG |
| 375 | -void _st_iterate_threads(void); | ||
| 376 | -#define ST_DEBUG_ITERATE_THREADS() _st_iterate_threads() | 372 | + void _st_iterate_threads(void); |
| 373 | + #define ST_DEBUG_ITERATE_THREADS() _st_iterate_threads() | ||
| 377 | #else | 374 | #else |
| 378 | -#define ST_DEBUG_ITERATE_THREADS() | 375 | + #define ST_DEBUG_ITERATE_THREADS() |
| 379 | #endif | 376 | #endif |
| 380 | 377 | ||
| 381 | #ifdef ST_SWITCH_CB | 378 | #ifdef ST_SWITCH_CB |
| 382 | -#define ST_SWITCH_OUT_CB(_thread) \ | 379 | + #define ST_SWITCH_OUT_CB(_thread) \ |
| 383 | if (_st_this_vp.switch_out_cb != NULL && \ | 380 | if (_st_this_vp.switch_out_cb != NULL && \ |
| 384 | _thread != _st_this_vp.idle_thread && \ | 381 | _thread != _st_this_vp.idle_thread && \ |
| 385 | _thread->state != _ST_ST_ZOMBIE) { \ | 382 | _thread->state != _ST_ST_ZOMBIE) { \ |
| 386 | _st_this_vp.switch_out_cb(); \ | 383 | _st_this_vp.switch_out_cb(); \ |
| 387 | } | 384 | } |
| 388 | -#define ST_SWITCH_IN_CB(_thread) \ | 385 | + #define ST_SWITCH_IN_CB(_thread) \ |
| 389 | if (_st_this_vp.switch_in_cb != NULL && \ | 386 | if (_st_this_vp.switch_in_cb != NULL && \ |
| 390 | _thread != _st_this_vp.idle_thread && \ | 387 | _thread != _st_this_vp.idle_thread && \ |
| 391 | _thread->state != _ST_ST_ZOMBIE) { \ | 388 | _thread->state != _ST_ST_ZOMBIE) { \ |
| 392 | _st_this_vp.switch_in_cb(); \ | 389 | _st_this_vp.switch_in_cb(); \ |
| 393 | } | 390 | } |
| 394 | #else | 391 | #else |
| 395 | -#define ST_SWITCH_OUT_CB(_thread) | ||
| 396 | -#define ST_SWITCH_IN_CB(_thread) | 392 | + #define ST_SWITCH_OUT_CB(_thread) |
| 393 | + #define ST_SWITCH_IN_CB(_thread) | ||
| 397 | #endif | 394 | #endif |
| 398 | 395 | ||
| 399 | /* | 396 | /* |
| @@ -424,9 +421,9 @@ void _st_iterate_threads(void); | @@ -424,9 +421,9 @@ void _st_iterate_threads(void); | ||
| 424 | * Initialize the thread context preparing it to execute _main | 421 | * Initialize the thread context preparing it to execute _main |
| 425 | */ | 422 | */ |
| 426 | #ifdef MD_INIT_CONTEXT | 423 | #ifdef MD_INIT_CONTEXT |
| 427 | -#define _ST_INIT_CONTEXT MD_INIT_CONTEXT | 424 | + #define _ST_INIT_CONTEXT MD_INIT_CONTEXT |
| 428 | #else | 425 | #else |
| 429 | -#error Unknown OS | 426 | + #error Unknown OS |
| 430 | #endif | 427 | #endif |
| 431 | 428 | ||
| 432 | /* | 429 | /* |
| @@ -456,11 +453,9 @@ int st_cond_destroy(_st_cond_t *cvar); | @@ -456,11 +453,9 @@ int st_cond_destroy(_st_cond_t *cvar); | ||
| 456 | int st_cond_timedwait(_st_cond_t *cvar, st_utime_t timeout); | 453 | int st_cond_timedwait(_st_cond_t *cvar, st_utime_t timeout); |
| 457 | int st_cond_signal(_st_cond_t *cvar); | 454 | 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); | 455 | 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, | ||
| 460 | - st_utime_t timeout); | 456 | +ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte, st_utime_t timeout); |
| 461 | int st_poll(struct pollfd *pds, int npds, st_utime_t timeout); | 457 | 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, | ||
| 463 | - int joinable, int stk_size); | 458 | +_st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg, int joinable, int stk_size); |
| 464 | 459 | ||
| 465 | #endif /* !__ST_COMMON_H__ */ | 460 | #endif /* !__ST_COMMON_H__ */ |
| 466 | 461 |
| @@ -43,15 +43,15 @@ | @@ -43,15 +43,15 @@ | ||
| 43 | #define __ST_MD_H__ | 43 | #define __ST_MD_H__ |
| 44 | 44 | ||
| 45 | #if defined(ETIMEDOUT) && !defined(ETIME) | 45 | #if defined(ETIMEDOUT) && !defined(ETIME) |
| 46 | -#define ETIME ETIMEDOUT | 46 | + #define ETIME ETIMEDOUT |
| 47 | #endif | 47 | #endif |
| 48 | 48 | ||
| 49 | #if defined(MAP_ANONYMOUS) && !defined(MAP_ANON) | 49 | #if defined(MAP_ANONYMOUS) && !defined(MAP_ANON) |
| 50 | -#define MAP_ANON MAP_ANONYMOUS | 50 | + #define MAP_ANON MAP_ANONYMOUS |
| 51 | #endif | 51 | #endif |
| 52 | 52 | ||
| 53 | #ifndef MAP_FAILED | 53 | #ifndef MAP_FAILED |
| 54 | -#define MAP_FAILED -1 | 54 | + #define MAP_FAILED -1 |
| 55 | #endif | 55 | #endif |
| 56 | 56 | ||
| 57 | /***************************************** | 57 | /***************************************** |
| @@ -59,35 +59,33 @@ | @@ -59,35 +59,33 @@ | ||
| 59 | */ | 59 | */ |
| 60 | 60 | ||
| 61 | #if defined (AIX) | 61 | #if defined (AIX) |
| 62 | + #define MD_STACK_GROWS_DOWN | ||
| 63 | + #define MD_USE_SYSV_ANON_MMAP | ||
| 64 | + #define MD_ACCEPT_NB_INHERITED | ||
| 65 | + #define MD_ALWAYS_UNSERIALIZED_ACCEPT | ||
| 62 | 66 | ||
| 63 | -#define MD_STACK_GROWS_DOWN | ||
| 64 | -#define MD_USE_SYSV_ANON_MMAP | ||
| 65 | -#define MD_ACCEPT_NB_INHERITED | ||
| 66 | -#define MD_ALWAYS_UNSERIALIZED_ACCEPT | ||
| 67 | - | ||
| 68 | -#ifndef MD_HAVE_SOCKLEN_T | ||
| 69 | -#define MD_HAVE_SOCKLEN_T | ||
| 70 | -#define socklen_t unsigned long | ||
| 71 | -#endif | 67 | + #ifndef MD_HAVE_SOCKLEN_T |
| 68 | + #define MD_HAVE_SOCKLEN_T | ||
| 69 | + #define socklen_t unsigned long | ||
| 70 | + #endif | ||
| 72 | 71 | ||
| 73 | -#define MD_SETJMP(env) _setjmp(env) | ||
| 74 | -#define MD_LONGJMP(env, val) _longjmp(env, val) | 72 | + #define MD_SETJMP(env) _setjmp(env) |
| 73 | + #define MD_LONGJMP(env, val) _longjmp(env, val) | ||
| 75 | 74 | ||
| 76 | -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ | 75 | + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ |
| 77 | ST_BEGIN_MACRO \ | 76 | ST_BEGIN_MACRO \ |
| 78 | if (MD_SETJMP((_thread)->context)) \ | 77 | if (MD_SETJMP((_thread)->context)) \ |
| 79 | _main(); \ | 78 | _main(); \ |
| 80 | (_thread)->context[3] = (long) (_sp); \ | 79 | (_thread)->context[3] = (long) (_sp); \ |
| 81 | ST_END_MACRO | 80 | ST_END_MACRO |
| 82 | 81 | ||
| 83 | -#define MD_GET_UTIME() \ | 82 | + #define MD_GET_UTIME() \ |
| 84 | timebasestruct_t rt; \ | 83 | timebasestruct_t rt; \ |
| 85 | (void) read_real_time(&rt, TIMEBASE_SZ); \ | 84 | (void) read_real_time(&rt, TIMEBASE_SZ); \ |
| 86 | (void) time_base_to_time(&rt, TIMEBASE_SZ); \ | 85 | (void) time_base_to_time(&rt, TIMEBASE_SZ); \ |
| 87 | return (rt.tb_high * 1000000LL + rt.tb_low / 1000) | 86 | return (rt.tb_high * 1000000LL + rt.tb_low / 1000) |
| 88 | 87 | ||
| 89 | #elif defined (CYGWIN) | 88 | #elif defined (CYGWIN) |
| 90 | - | ||
| 91 | #define MD_STACK_GROWS_DOWN | 89 | #define MD_STACK_GROWS_DOWN |
| 92 | #define MD_USE_BSD_ANON_MMAP | 90 | #define MD_USE_BSD_ANON_MMAP |
| 93 | #define MD_ACCEPT_NB_NOT_INHERITED | 91 | #define MD_ACCEPT_NB_NOT_INHERITED |
| @@ -129,8 +129,7 @@ extern "C" { | @@ -129,8 +129,7 @@ extern "C" { | ||
| 129 | extern void st_netfd_free(st_netfd_t fd); | 129 | extern void st_netfd_free(st_netfd_t fd); |
| 130 | extern int st_netfd_close(st_netfd_t fd); | 130 | extern int st_netfd_close(st_netfd_t fd); |
| 131 | extern int st_netfd_fileno(st_netfd_t fd); | 131 | extern int st_netfd_fileno(st_netfd_t fd); |
| 132 | - extern void st_netfd_setspecific(st_netfd_t fd, void *value, | ||
| 133 | - void (*destructor)(void *)); | 132 | + extern void st_netfd_setspecific(st_netfd_t fd, void *value, void (*destructor)(void *)); |
| 134 | extern void *st_netfd_getspecific(st_netfd_t fd); | 133 | extern void *st_netfd_getspecific(st_netfd_t fd); |
| 135 | extern int st_netfd_serialize_accept(st_netfd_t fd); | 134 | extern int st_netfd_serialize_accept(st_netfd_t fd); |
| 136 | extern int st_netfd_poll(st_netfd_t fd, int how, st_utime_t timeout); | 135 | extern int st_netfd_poll(st_netfd_t fd, int how, st_utime_t timeout); |
-
请 注册 或 登录 后发表评论