da_signal.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright [2021] JD.com, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef DA_SIGNAL_H_
  17. #define DA_SIGNAL_H_
  18. #include "compiler.h"
  19. #include "da_queue.h"
  20. #include <signal.h>
  21. #include <string.h>
  22. #define MAX_SIGNAL 256
  23. /* those are highly dynamic and stored in pools */
  24. struct sig_handler {
  25. TAILQ_ENTRY(sig_handler) sig_tqe;
  26. void *handler; /* function to call or task to wake up */
  27. int arg; /*arg needed when process function or signals*/
  28. };
  29. TAILQ_HEAD(sig_tqh, sig_handler);
  30. /* one per signal */
  31. struct signal_descriptor {
  32. int count; /* number of times raised */
  33. struct sig_tqh sig_tqh; /* sig_handler */
  34. };
  35. extern volatile int signal_queue_len;
  36. extern struct signal_descriptor signal_state[];
  37. extern struct pool_head *pool2_sig_handlers;
  38. void signal_handler(int sig);
  39. void __signal_process_queue();
  40. int signal_init();
  41. void deinit_signals();
  42. struct sig_handler *
  43. signal_register_fct(int sig, void (*fct)(struct sig_handler *), int arg);
  44. void signal_unregister_handler(int sig, struct sig_handler *handler);
  45. void signal_unregister_target(int sig, void *target);
  46. static inline void signal_process_queue() {
  47. if (unlikely(signal_queue_len > 0))
  48. __signal_process_queue();
  49. }
  50. #endif /* DA_SIGNAL_H_ */