正在显示
3 个修改的文件
包含
140 行增加
和
148 行删除
| @@ -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,22 +59,21 @@ | @@ -59,22 +59,21 @@ | ||
| 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 | */ |
| 74 | 73 | ||
| 75 | typedef struct _st_clist { | 74 | typedef struct _st_clist { |
| 76 | - struct _st_clist *next; | ||
| 77 | - struct _st_clist *prev; | 75 | + struct _st_clist *next; |
| 76 | + struct _st_clist *prev; | ||
| 78 | } _st_clist_t; | 77 | } _st_clist_t; |
| 79 | 78 | ||
| 80 | /* Insert element "_e" into the list, before "_l" */ | 79 | /* Insert element "_e" into the list, before "_l" */ |
| @@ -137,114 +136,113 @@ typedef struct _st_clist { | @@ -137,114 +136,113 @@ 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; | ||
| 143 | - char *vaddr; /* Base of stack's allocated memory */ | ||
| 144 | - int vaddr_size; /* Size of stack's allocated memory */ | ||
| 145 | - int stk_size; /* Size of usable portion of the stack */ | ||
| 146 | - char *stk_bottom; /* Lowest address of stack's usable portion */ | ||
| 147 | - char *stk_top; /* Highest address of stack's usable portion */ | ||
| 148 | - void *sp; /* Stack pointer from C's point of view */ | ||
| 149 | -#ifdef __ia64__ | ||
| 150 | - void *bsp; /* Register stack backing store pointer */ | ||
| 151 | -#endif | 140 | + _st_clist_t links; |
| 141 | + char *vaddr; /* Base of stack's allocated memory */ | ||
| 142 | + int vaddr_size; /* Size of stack's allocated memory */ | ||
| 143 | + int stk_size; /* Size of usable portion of the stack */ | ||
| 144 | + char *stk_bottom; /* Lowest address of stack's usable portion */ | ||
| 145 | + char *stk_top; /* Highest address of stack's usable portion */ | ||
| 146 | + void *sp; /* Stack pointer from C's point of view */ | ||
| 147 | + #ifdef __ia64__ | ||
| 148 | + void *bsp; /* Register stack backing store pointer */ | ||
| 149 | + #endif | ||
| 152 | } _st_stack_t; | 150 | } _st_stack_t; |
| 153 | 151 | ||
| 154 | 152 | ||
| 155 | typedef struct _st_cond { | 153 | typedef struct _st_cond { |
| 156 | - _st_clist_t wait_q; /* Condition variable wait queue */ | 154 | + _st_clist_t wait_q; /* Condition variable wait queue */ |
| 157 | } _st_cond_t; | 155 | } _st_cond_t; |
| 158 | 156 | ||
| 159 | 157 | ||
| 160 | typedef struct _st_thread _st_thread_t; | 158 | typedef struct _st_thread _st_thread_t; |
| 161 | 159 | ||
| 162 | struct _st_thread { | 160 | struct _st_thread { |
| 163 | - int state; /* Thread's state */ | ||
| 164 | - int flags; /* Thread's flags */ | ||
| 165 | - | ||
| 166 | - void *(*start)(void *arg); /* The start function of the thread */ | ||
| 167 | - void *arg; /* Argument of the start function */ | ||
| 168 | - void *retval; /* Return value of the start function */ | ||
| 169 | - | ||
| 170 | - _st_stack_t *stack; /* Info about thread's stack */ | ||
| 171 | - | ||
| 172 | - _st_clist_t links; /* For putting on run/sleep/zombie queue */ | ||
| 173 | - _st_clist_t wait_links; /* For putting on mutex/condvar wait queue */ | ||
| 174 | -#ifdef DEBUG | ||
| 175 | - _st_clist_t tlink; /* For putting on thread queue */ | ||
| 176 | -#endif | ||
| 177 | - | ||
| 178 | - st_utime_t due; /* Wakeup time when thread is sleeping */ | ||
| 179 | - _st_thread_t *left; /* For putting in timeout heap */ | ||
| 180 | - _st_thread_t *right; /* -- see docs/timeout_heap.txt for details */ | ||
| 181 | - int heap_index; | ||
| 182 | - | ||
| 183 | - void **private_data; /* Per thread private data */ | ||
| 184 | - | ||
| 185 | - _st_cond_t *term; /* Termination condition variable for join */ | ||
| 186 | - | ||
| 187 | - jmp_buf context; /* Thread's context */ | 161 | + int state; /* Thread's state */ |
| 162 | + int flags; /* Thread's flags */ | ||
| 163 | + | ||
| 164 | + void *(*start)(void *arg); /* The start function of the thread */ | ||
| 165 | + void *arg; /* Argument of the start function */ | ||
| 166 | + void *retval; /* Return value of the start function */ | ||
| 167 | + | ||
| 168 | + _st_stack_t *stack; /* Info about thread's stack */ | ||
| 169 | + | ||
| 170 | + _st_clist_t links; /* For putting on run/sleep/zombie queue */ | ||
| 171 | + _st_clist_t wait_links; /* For putting on mutex/condvar wait queue */ | ||
| 172 | + #ifdef DEBUG | ||
| 173 | + _st_clist_t tlink; /* For putting on thread queue */ | ||
| 174 | + #endif | ||
| 175 | + | ||
| 176 | + st_utime_t due; /* Wakeup time when thread is sleeping */ | ||
| 177 | + _st_thread_t *left; /* For putting in timeout heap */ | ||
| 178 | + _st_thread_t *right; /* -- see docs/timeout_heap.txt for details */ | ||
| 179 | + int heap_index; | ||
| 180 | + | ||
| 181 | + void **private_data; /* Per thread private data */ | ||
| 182 | + | ||
| 183 | + _st_cond_t *term; /* Termination condition variable for join */ | ||
| 184 | + | ||
| 185 | + jmp_buf context; /* Thread's context */ | ||
| 188 | }; | 186 | }; |
| 189 | 187 | ||
| 190 | 188 | ||
| 191 | typedef struct _st_mutex { | 189 | typedef struct _st_mutex { |
| 192 | - _st_thread_t *owner; /* Current mutex owner */ | ||
| 193 | - _st_clist_t wait_q; /* Mutex wait queue */ | 190 | + _st_thread_t *owner; /* Current mutex owner */ |
| 191 | + _st_clist_t wait_q; /* Mutex wait queue */ | ||
| 194 | } _st_mutex_t; | 192 | } _st_mutex_t; |
| 195 | 193 | ||
| 196 | 194 | ||
| 197 | typedef struct _st_pollq { | 195 | typedef struct _st_pollq { |
| 198 | - _st_clist_t links; /* For putting on io queue */ | ||
| 199 | - _st_thread_t *thread; /* Polling thread */ | ||
| 200 | - struct pollfd *pds; /* Array of poll descriptors */ | ||
| 201 | - int npds; /* Length of the array */ | ||
| 202 | - int on_ioq; /* Is it on ioq? */ | 196 | + _st_clist_t links; /* For putting on io queue */ |
| 197 | + _st_thread_t *thread; /* Polling thread */ | ||
| 198 | + struct pollfd *pds; /* Array of poll descriptors */ | ||
| 199 | + int npds; /* Length of the array */ | ||
| 200 | + int on_ioq; /* Is it on ioq? */ | ||
| 203 | } _st_pollq_t; | 201 | } _st_pollq_t; |
| 204 | 202 | ||
| 205 | 203 | ||
| 206 | typedef struct _st_eventsys_ops { | 204 | typedef struct _st_eventsys_ops { |
| 207 | - const char *name; /* Name of this event system */ | ||
| 208 | - int val; /* Type of this event system */ | ||
| 209 | - int (*init)(void); /* Initialization */ | ||
| 210 | - void (*dispatch)(void); /* Dispatch function */ | ||
| 211 | - int (*pollset_add)(struct pollfd *, int); /* Add descriptor set */ | ||
| 212 | - void (*pollset_del)(struct pollfd *, int); /* Delete descriptor set */ | ||
| 213 | - int (*fd_new)(int); /* New descriptor allocated */ | ||
| 214 | - int (*fd_close)(int); /* Descriptor closed */ | ||
| 215 | - int (*fd_getlimit)(void); /* Descriptor hard limit */ | 205 | + const char *name; /* Name of this event system */ |
| 206 | + int val; /* Type of this event system */ | ||
| 207 | + int (*init)(void); /* Initialization */ | ||
| 208 | + void (*dispatch)(void); /* Dispatch function */ | ||
| 209 | + int (*pollset_add)(struct pollfd *, int); /* Add descriptor set */ | ||
| 210 | + void (*pollset_del)(struct pollfd *, int); /* Delete descriptor set */ | ||
| 211 | + int (*fd_new)(int); /* New descriptor allocated */ | ||
| 212 | + int (*fd_close)(int); /* Descriptor closed */ | ||
| 213 | + int (*fd_getlimit)(void); /* Descriptor hard limit */ | ||
| 216 | } _st_eventsys_t; | 214 | } _st_eventsys_t; |
| 217 | 215 | ||
| 218 | 216 | ||
| 219 | typedef struct _st_vp { | 217 | typedef struct _st_vp { |
| 220 | - _st_thread_t *idle_thread; /* Idle thread for this vp */ | ||
| 221 | - st_utime_t last_clock; /* The last time we went into vp_check_clock() */ | ||
| 222 | - | ||
| 223 | - _st_clist_t run_q; /* run queue for this vp */ | ||
| 224 | - _st_clist_t io_q; /* io queue for this vp */ | ||
| 225 | - _st_clist_t zombie_q; /* zombie queue for this vp */ | ||
| 226 | -#ifdef DEBUG | ||
| 227 | - _st_clist_t thread_q; /* all threads of this vp */ | ||
| 228 | -#endif | ||
| 229 | - int pagesize; | ||
| 230 | - | ||
| 231 | - _st_thread_t *sleep_q; /* sleep queue for this vp */ | ||
| 232 | - int sleepq_size; /* number of threads on sleep queue */ | ||
| 233 | - | ||
| 234 | -#ifdef ST_SWITCH_CB | ||
| 235 | - 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 */ | ||
| 237 | -#endif | 218 | + _st_thread_t *idle_thread; /* Idle thread for this vp */ |
| 219 | + st_utime_t last_clock; /* The last time we went into vp_check_clock() */ | ||
| 220 | + | ||
| 221 | + _st_clist_t run_q; /* run queue for this vp */ | ||
| 222 | + _st_clist_t io_q; /* io queue for this vp */ | ||
| 223 | + _st_clist_t zombie_q; /* zombie queue for this vp */ | ||
| 224 | + #ifdef DEBUG | ||
| 225 | + _st_clist_t thread_q; /* all threads of this vp */ | ||
| 226 | + #endif | ||
| 227 | + int pagesize; | ||
| 228 | + | ||
| 229 | + _st_thread_t *sleep_q; /* sleep queue for this vp */ | ||
| 230 | + int sleepq_size; /* number of threads on sleep queue */ | ||
| 231 | + | ||
| 232 | + #ifdef ST_SWITCH_CB | ||
| 233 | + st_switch_cb_t switch_out_cb; /* called when a thread is switched out */ | ||
| 234 | + st_switch_cb_t switch_in_cb; /* called when a thread is switched in */ | ||
| 235 | + #endif | ||
| 238 | } _st_vp_t; | 236 | } _st_vp_t; |
| 239 | 237 | ||
| 240 | 238 | ||
| 241 | typedef struct _st_netfd { | 239 | typedef struct _st_netfd { |
| 242 | - int osfd; /* Underlying OS file descriptor */ | ||
| 243 | - int inuse; /* In-use flag */ | ||
| 244 | - void *private_data; /* Per descriptor private data */ | ||
| 245 | - _st_destructor_t destructor; /* Private data destructor function */ | ||
| 246 | - void *aux_data; /* Auxiliary data for internal use */ | ||
| 247 | - struct _st_netfd *next; /* For putting on the free list */ | 240 | + int osfd; /* Underlying OS file descriptor */ |
| 241 | + int inuse; /* In-use flag */ | ||
| 242 | + void *private_data; /* Per descriptor private data */ | ||
| 243 | + _st_destructor_t destructor; /* Private data destructor function */ | ||
| 244 | + void *aux_data; /* Auxiliary data for internal use */ | ||
| 245 | + struct _st_netfd *next; /* For putting on the free list */ | ||
| 248 | } _st_netfd_t; | 246 | } _st_netfd_t; |
| 249 | 247 | ||
| 250 | 248 | ||
| @@ -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,8 +336,8 @@ extern _st_eventsys_t *_st_eventsys; | @@ -339,8 +336,8 @@ 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) \ | ||
| 343 | - ((_st_thread_t *)((char *)(_qp) - offsetof(_st_thread_t, tlink))) | 339 | + #define _ST_THREAD_THREADQ_PTR(_qp) \ |
| 340 | + ((_st_thread_t *)((char *)(_qp) - offsetof(_st_thread_t, tlink))) | ||
| 344 | #endif | 341 | #endif |
| 345 | 342 | ||
| 346 | 343 | ||
| @@ -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) \ | ||
| 383 | - if (_st_this_vp.switch_out_cb != NULL && \ | 379 | + #define ST_SWITCH_OUT_CB(_thread) \ |
| 380 | + if (_st_this_vp.switch_out_cb != NULL && \ | ||
| 381 | + _thread != _st_this_vp.idle_thread && \ | ||
| 382 | + _thread->state != _ST_ST_ZOMBIE) { \ | ||
| 383 | + _st_this_vp.switch_out_cb(); \ | ||
| 384 | + } | ||
| 385 | + #define ST_SWITCH_IN_CB(_thread) \ | ||
| 386 | + if (_st_this_vp.switch_in_cb != NULL && \ | ||
| 384 | _thread != _st_this_vp.idle_thread && \ | 387 | _thread != _st_this_vp.idle_thread && \ |
| 385 | _thread->state != _ST_ST_ZOMBIE) { \ | 388 | _thread->state != _ST_ST_ZOMBIE) { \ |
| 386 | - _st_this_vp.switch_out_cb(); \ | ||
| 387 | - } | ||
| 388 | -#define ST_SWITCH_IN_CB(_thread) \ | ||
| 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(); \ | ||
| 393 | - } | 389 | + _st_this_vp.switch_in_cb(); \ |
| 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 | - | ||
| 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 | ||
| 72 | - | ||
| 73 | -#define MD_SETJMP(env) _setjmp(env) | ||
| 74 | -#define MD_LONGJMP(env, val) _longjmp(env, val) | ||
| 75 | - | ||
| 76 | -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ | ||
| 77 | - ST_BEGIN_MACRO \ | ||
| 78 | - if (MD_SETJMP((_thread)->context)) \ | ||
| 79 | - _main(); \ | ||
| 80 | - (_thread)->context[3] = (long) (_sp); \ | ||
| 81 | - ST_END_MACRO | ||
| 82 | - | ||
| 83 | -#define MD_GET_UTIME() \ | ||
| 84 | - timebasestruct_t rt; \ | ||
| 85 | - (void) read_real_time(&rt, TIMEBASE_SZ); \ | ||
| 86 | - (void) time_base_to_time(&rt, TIMEBASE_SZ); \ | ||
| 87 | - return (rt.tb_high * 1000000LL + rt.tb_low / 1000) | 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 | ||
| 66 | + | ||
| 67 | + #ifndef MD_HAVE_SOCKLEN_T | ||
| 68 | + #define MD_HAVE_SOCKLEN_T | ||
| 69 | + #define socklen_t unsigned long | ||
| 70 | + #endif | ||
| 71 | + | ||
| 72 | + #define MD_SETJMP(env) _setjmp(env) | ||
| 73 | + #define MD_LONGJMP(env, val) _longjmp(env, val) | ||
| 74 | + | ||
| 75 | + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ | ||
| 76 | + ST_BEGIN_MACRO \ | ||
| 77 | + if (MD_SETJMP((_thread)->context)) \ | ||
| 78 | + _main(); \ | ||
| 79 | + (_thread)->context[3] = (long) (_sp); \ | ||
| 80 | + ST_END_MACRO | ||
| 81 | + | ||
| 82 | + #define MD_GET_UTIME() \ | ||
| 83 | + timebasestruct_t rt; \ | ||
| 84 | + (void) read_real_time(&rt, TIMEBASE_SZ); \ | ||
| 85 | + (void) time_base_to_time(&rt, TIMEBASE_SZ); \ | ||
| 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); |
-
请 注册 或 登录 后发表评论