Changeset 4f2166b9a2565b2ccc5fbcbb9869b2a41119a342
- Timestamp:
- 10/19/09 22:14:15 (5 weeks ago)
- Author:
- Alejandro R. Sedeño <asedeno@mit.edu>
- git-author:
- Alejandro R. Sedeño <asedeno@mit.edu> / 2009-10-13T03:01:31Z-0400
- Parents:
- cc1a6d41c20d85ff1ef77c4f918f98a62291088f
- Children:
- dbf94e9d63a677506783cbdb11f0d965aa5f1d70
- git-committer:
- Alejandro R. Sedeño <asedeno@mit.edu> / 2009-10-19T22:14:15Z-0400
- Message:
-
Add a pre-select action list.
Allow us to add actions that should be performed before calling
pselect(). If the action performs any useful work, it should return
non-zero. If any of the actions return a non-zero value, the timeout
for pselect() will be set to 0s, so that we can process all of these
actions again in case they are interacting with one another, while
still keeping an eye on our file descriptors and timers.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r40bda84
|
r4f2166b
|
|
| 113 | 113 | owl_message_init_fmtext_cache(); |
| 114 | 114 | owl_list_create(&(g->dispatchlist)); |
| | 115 | owl_list_create(&(g->psa_list)); |
| 115 | 116 | g->timerlist = NULL; |
| 116 | 117 | g->interrupted = FALSE; |
| … |
… |
|
| 953 | 954 | } |
| 954 | 955 | |
| | 956 | owl_list *owl_global_get_psa_list(owl_global *g) |
| | 957 | { |
| | 958 | return &(g->psa_list); |
| | 959 | } |
| | 960 | |
| 955 | 961 | GList **owl_global_get_timerlist(owl_global *g) |
| 956 | 962 | { |
-
|
r40bda84
|
r4f2166b
|
|
| 504 | 504 | void *data; |
| 505 | 505 | } owl_dispatch; |
| | 506 | |
| | 507 | typedef struct _owl_ps_action { |
| | 508 | int needs_gc; |
| | 509 | int (*callback)(struct _owl_ps_action *, void *); |
| | 510 | void (*destroy)(struct _owl_ps_action *); |
| | 511 | void *data; |
| | 512 | } owl_ps_action; |
| 506 | 513 | |
| 507 | 514 | typedef struct _owl_popexec { |
| … |
… |
|
| 584 | 591 | owl_obarray obarray; |
| 585 | 592 | owl_list dispatchlist; |
| | 593 | owl_list psa_list; |
| 586 | 594 | GList *timerlist; |
| 587 | 595 | owl_timer *aim_nop_timer; |
-
|
r9f5e847
|
r4f2166b
|
|
| 2 | 2 | |
| 3 | 3 | static int dispatch_active = 0; |
| | 4 | static int psa_active = 0; |
| 4 | 5 | |
| 5 | 6 | int _owl_select_timer_cmp(const owl_timer *t1, const owl_timer *t2) { |
| … |
… |
|
| 353 | 354 | } |
| 354 | 355 | |
| | 356 | owl_ps_action *owl_select_add_pre_select_action(int (*cb)(owl_ps_action *, void *), void (*destroy)(owl_ps_action *), void *data) |
| | 357 | { |
| | 358 | owl_ps_action *a = owl_malloc(sizeof(owl_ps_action)); |
| | 359 | owl_list *psa_list = owl_global_get_psa_list(&g); |
| | 360 | a->needs_gc = 0; |
| | 361 | a->callback = cb; |
| | 362 | a->destroy = destroy; |
| | 363 | a->data = data; |
| | 364 | owl_list_append_element(psa_list, a); |
| | 365 | return a; |
| | 366 | } |
| | 367 | |
| | 368 | void owl_select_psa_gc(void) |
| | 369 | { |
| | 370 | int i; |
| | 371 | owl_list *psa_list; |
| | 372 | owl_ps_action *a; |
| | 373 | |
| | 374 | psa_list = owl_global_get_psa_list(&g); |
| | 375 | for (i = owl_list_get_size(psa_list) - 1; i >= 0; i--) { |
| | 376 | a = owl_list_get_element(psa_list, i); |
| | 377 | if (a->needs_gc) { |
| | 378 | owl_list_remove_element(psa_list, i); |
| | 379 | if (a->destroy) { |
| | 380 | a->destroy(a); |
| | 381 | } |
| | 382 | owl_free(a); |
| | 383 | } |
| | 384 | } |
| | 385 | } |
| | 386 | |
| | 387 | void owl_select_remove_pre_select_action(owl_ps_action *a) |
| | 388 | { |
| | 389 | a->needs_gc = 1; |
| | 390 | if (!psa_active) |
| | 391 | owl_select_psa_gc(); |
| | 392 | } |
| | 393 | |
| | 394 | int owl_select_do_pre_select_actions(void) |
| | 395 | { |
| | 396 | int i, len, ret; |
| | 397 | owl_list *psa_list; |
| | 398 | |
| | 399 | psa_active = 1; |
| | 400 | ret = 0; |
| | 401 | psa_list = owl_global_get_psa_list(&g); |
| | 402 | len = owl_list_get_size(psa_list); |
| | 403 | for (i = 0; i < len; i++) { |
| | 404 | owl_ps_action *a = owl_list_get_element(psa_list, i); |
| | 405 | if (a->callback != NULL && a->callback(a, a->data)) { |
| | 406 | ret = 1; |
| | 407 | } |
| | 408 | } |
| | 409 | psa_active = 0; |
| | 410 | owl_select_psa_gc(); |
| | 411 | return ret; |
| | 412 | } |
| | 413 | |
| 355 | 414 | void owl_select(void) |
| 356 | 415 | { |
| … |
… |
|
| 400 | 459 | /* END AIM HACK */ |
| 401 | 460 | |
| | 461 | if (owl_select_do_pre_select_actions()) { |
| | 462 | timeout.tv_sec = 0; |
| | 463 | timeout.tv_nsec = 0; |
| | 464 | } |
| | 465 | |
| 402 | 466 | ret = pselect(max_fd+1, &r, &aim_wfds, &e, &timeout, &mask); |
| 403 | 467 | |