123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- struct sHT_task_queue
- {
-
- struct sHT_task *head;
-
- struct sHT_task **tailp;
- };
- static inline void
- sHT_task_queue_init(struct sHT_task_queue *q)
- {
- *q = (struct sHT_task_queue) {
-
- .head = NULL,
- .tailp = &q->head,
- };
- }
- __attribute__((nonnull (1, 2)))
- static inline void
- sHT_qadd(struct sHT_task_queue *q, struct sHT_task *task)
- {
- sHT_require(!(task->flags & sHT_TASK_QUEUED));
- task->flags |= sHT_TASK_QUEUED;
-
- *q->tailp = task;
- q->tailp = &task->next;
- }
- __attribute__((nonnull (1, 2)))
- static inline void
- sHT_qadd_try(struct sHT_task_queue *q, struct sHT_task *task)
- {
- if (sHT_and_any(task->flags, sHT_TASK_QUEUED))
- return;
- task->flags |= sHT_TASK_QUEUED;
-
- *q->tailp = task;
- q->tailp = &task->next;
- }
- __attribute__((always_inline))
- static inline void
- sHT_qtake(struct sHT_task_queue *q, void (* nil)(struct sHT_task_queue *), void (* some)(struct sHT_task_queue *, struct sHT_task *))
- {
- struct sHT_task *first = q->head;
- if (sHT_null_p(first)) {
- nil(q);
- return;
- }
- struct sHT_task *next = q->head = first->next;
- if (sHT_null_p(next))
-
- q->tailp = &q->head;
- some(q, first);
- }
- typedef void (sHT_task_perform)(void *cookie, struct sHT_task *);
- __attribute__((nonnull (2, 3)))
- __attribute__((always_inline))
- static inline void
- sHT_perform_all(void *cookie, struct sHT_task_deque *deck, sHT_task_perform *f)
- {
-
- size_t n_todo = deck->n;
- for (size_t i = 0; sHT_gt(n_todo, i); i++) {
- size_t j = deck->head + i;
-
- j %= deck->capacity;
- struct sHT_task *task = deck->tasks[j];
- task->flags &= ~sHT_TASK_SCHEDULED;
- f(cookie, task);
- }
- deck->head = (deck->head + n_todo) % deck->capacity;
- deck->n -= n_todo;
- }
- typedef int sHT_watch_set;
- enum sHT_watch_set_alloc_error
- {
-
- sHT_WATCH_SET_ALLOC_EMFILE = -1,
-
- sHT_WATCH_SET_ALLOC_ENFILE = -2,
-
- sHT_WATCH_SET_ALLOC_ENOMEM = -3,
- };
- int
- sHT_alloc_watch_set(void);
- void
- sHT_free_watch_set(sHT_watch_set watches);
- enum sHT_watch_set_install
- {
-
- sHT_WATCH_SET_INSTALL_DONE = 0,
-
- sHT_WATCH_SET_INSTALL_ENOMEM = 1,
-
- sHT_WATCH_SET_INSTALL_LIMIT = 2,
- };
- __attribute__((warn_unused_result))
- __attribute__((nonnull (3)))
- enum sHT_watch_set_install
- sHT_install_edge_trigger(sHT_watch_set watches, int fd, struct sHT_task *task);
- void
- sHT_delete_edge_trigger(sHT_watch_set watches, int fd);
|