signal.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2017/10/5 Bernard the first version
  9. * 2018/09/17 Jesven fix: in _signal_deliver RT_THREAD_STAT_MASK to RT_THREAD_STAT_SIGNAL_MASK
  10. * 2018/11/22 Jesven in smp version rt_hw_context_switch_to add a param
  11. */
  12. #include <stdint.h>
  13. #include <string.h>
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #ifdef RT_USING_SIGNALS
  17. #ifndef RT_SIG_INFO_MAX
  18. #ifdef ARCH_CPU_64BIT
  19. #define RT_SIG_INFO_MAX 64
  20. #else
  21. #define RT_SIG_INFO_MAX 32
  22. #endif /* ARCH_CPU_64BIT */
  23. #endif /* RT_SIG_INFO_MAX */
  24. #define DBG_TAG "SIGN"
  25. #define DBG_LVL DBG_WARNING
  26. #include <rtdbg.h>
  27. #define sig_mask(sig_no) (1u << sig_no)
  28. #define sig_valid(sig_no) (sig_no >= 0 && sig_no < RT_SIG_MAX)
  29. static struct rt_spinlock _thread_signal_lock = RT_SPINLOCK_INIT;
  30. struct siginfo_node
  31. {
  32. siginfo_t si;
  33. struct rt_slist_node list;
  34. };
  35. static struct rt_mempool *_siginfo_pool;
  36. static void _signal_deliver(rt_thread_t tid);
  37. void rt_thread_handle_sig(rt_bool_t clean_state);
  38. static void _signal_default_handler(int signo)
  39. {
  40. RT_UNUSED(signo);
  41. LOG_I("handled signo[%d] with default action.", signo);
  42. return ;
  43. }
  44. static void _signal_entry(void *parameter)
  45. {
  46. RT_UNUSED(parameter);
  47. rt_thread_t tid = rt_thread_self();
  48. /* handle signal */
  49. rt_thread_handle_sig(RT_FALSE);
  50. #ifdef RT_USING_SMP
  51. #else
  52. /* return to thread */
  53. tid->sp = tid->sig_ret;
  54. tid->sig_ret = RT_NULL;
  55. #endif /* RT_USING_SMP */
  56. LOG_D("switch back to: 0x%08x\n", tid->sp);
  57. RT_SCHED_CTX(tid).stat &= ~RT_THREAD_STAT_SIGNAL;
  58. #ifdef RT_USING_SMP
  59. rt_hw_context_switch_to((rt_uintptr_t)&parameter, tid);
  60. #else
  61. rt_hw_context_switch_to((rt_uintptr_t)&(tid->sp));
  62. #endif /* RT_USING_SMP */
  63. }
  64. /*
  65. * To deliver a signal to thread, there are cases:
  66. * 1. When thread is suspended, function resumes thread and
  67. * set signal stat;
  68. * 2. When thread is ready:
  69. * - If function delivers a signal to self thread, just handle
  70. * it.
  71. * - If function delivers a signal to another ready thread, OS
  72. * should build a slice context to handle it.
  73. */
  74. static void _signal_deliver(rt_thread_t tid)
  75. {
  76. rt_base_t level;
  77. level = rt_spin_lock_irqsave(&_thread_signal_lock);
  78. /* thread is not interested in pended signals */
  79. if (!(tid->sig_pending & tid->sig_mask))
  80. {
  81. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  82. return;
  83. }
  84. if ((RT_SCHED_CTX(tid).stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK)
  85. {
  86. /* resume thread to handle signal */
  87. #ifdef RT_USING_SMART
  88. rt_thread_wakeup(tid);
  89. #else
  90. rt_thread_resume(tid);
  91. #endif
  92. /* add signal state */
  93. RT_SCHED_CTX(tid).stat |= (RT_THREAD_STAT_SIGNAL | RT_THREAD_STAT_SIGNAL_PENDING);
  94. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  95. /* re-schedule */
  96. rt_schedule();
  97. }
  98. else
  99. {
  100. if (tid == rt_thread_self())
  101. {
  102. /* add signal state */
  103. RT_SCHED_CTX(tid).stat |= RT_THREAD_STAT_SIGNAL;
  104. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  105. /* do signal action in self thread context */
  106. if (rt_interrupt_get_nest() == 0)
  107. {
  108. rt_thread_handle_sig(RT_TRUE);
  109. }
  110. }
  111. else if (!((RT_SCHED_CTX(tid).stat & RT_THREAD_STAT_SIGNAL_MASK) & RT_THREAD_STAT_SIGNAL))
  112. {
  113. /* add signal state */
  114. RT_SCHED_CTX(tid).stat |= (RT_THREAD_STAT_SIGNAL | RT_THREAD_STAT_SIGNAL_PENDING);
  115. #ifdef RT_USING_SMP
  116. {
  117. int cpu_id;
  118. cpu_id = RT_SCHED_CTX(tid).oncpu;
  119. if ((cpu_id != RT_CPU_DETACHED) && (cpu_id != rt_cpu_get_id()))
  120. {
  121. rt_uint32_t cpu_mask;
  122. cpu_mask = RT_CPU_MASK ^ (1 << cpu_id);
  123. rt_hw_ipi_send(RT_SCHEDULE_IPI, cpu_mask);
  124. }
  125. }
  126. #else
  127. /* point to the signal handle entry */
  128. RT_SCHED_CTX(tid).stat &= ~RT_THREAD_STAT_SIGNAL_PENDING;
  129. tid->sig_ret = tid->sp;
  130. tid->sp = rt_hw_stack_init((void *)_signal_entry, RT_NULL,
  131. (void *)((char *)tid->sig_ret - 32), RT_NULL);
  132. #endif /* RT_USING_SMP */
  133. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  134. LOG_D("signal stack pointer @ 0x%08x", tid->sp);
  135. /* re-schedule */
  136. rt_schedule();
  137. }
  138. else
  139. {
  140. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  141. }
  142. }
  143. }
  144. #ifdef RT_USING_SMP
  145. void *rt_signal_check(void* context)
  146. {
  147. rt_sched_lock_level_t level;
  148. int cpu_id;
  149. struct rt_cpu* pcpu;
  150. struct rt_thread *current_thread;
  151. level = rt_spin_lock_irqsave(&_thread_signal_lock);
  152. cpu_id = rt_cpu_get_id();
  153. pcpu = rt_cpu_index(cpu_id);
  154. current_thread = pcpu->current_thread;
  155. if (pcpu->irq_nest)
  156. {
  157. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  158. return context;
  159. }
  160. if (current_thread->cpus_lock_nest == 1)
  161. {
  162. if (RT_SCHED_CTX(current_thread).stat & RT_THREAD_STAT_SIGNAL_PENDING)
  163. {
  164. void *sig_context;
  165. RT_SCHED_CTX(current_thread).stat &= ~RT_THREAD_STAT_SIGNAL_PENDING;
  166. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  167. sig_context = rt_hw_stack_init((void *)_signal_entry, context,
  168. (void*)((char*)context - 32), RT_NULL);
  169. return sig_context;
  170. }
  171. }
  172. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  173. return context;
  174. }
  175. #endif /* RT_USING_SMP */
  176. /**
  177. * @brief This function will install a processing function to a specific
  178. * signal and return the old processing function of this signal.
  179. *
  180. * @note This function needs to be used in conjunction with the
  181. * rt_signal_unmask() function to make the signal effective.
  182. *
  183. * @see rt_signal_unmask()
  184. *
  185. * @param signo is a specific signal value (range: 0 ~ RT_SIG_MAX).
  186. *
  187. * @param handler is sets the processing of signal value.
  188. *
  189. * @return Return the old processing function of this signal. ONLY When the
  190. * return value is SIG_ERR, the operation is failed.
  191. */
  192. rt_sighandler_t rt_signal_install(int signo, rt_sighandler_t handler)
  193. {
  194. rt_base_t level;
  195. rt_sighandler_t old = RT_NULL;
  196. rt_thread_t tid = rt_thread_self();
  197. if (!sig_valid(signo)) return SIG_ERR;
  198. level = rt_spin_lock_irqsave(&_thread_signal_lock);
  199. if (tid->sig_vectors == RT_NULL)
  200. {
  201. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  202. rt_thread_alloc_sig(tid);
  203. level = rt_spin_lock_irqsave(&_thread_signal_lock);
  204. }
  205. if (tid->sig_vectors)
  206. {
  207. old = tid->sig_vectors[signo];
  208. if (handler == SIG_IGN) tid->sig_vectors[signo] = RT_NULL;
  209. else if (handler == SIG_DFL) tid->sig_vectors[signo] = _signal_default_handler;
  210. else tid->sig_vectors[signo] = handler;
  211. }
  212. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  213. return old;
  214. }
  215. /**
  216. * @brief This function will block the specified signal.
  217. *
  218. * @note This function will block the specified signal, even if the
  219. * rt_thread_kill() function is called to send this signal to
  220. * the current thread, it will no longer take effect.
  221. *
  222. * @see rt_thread_kill()
  223. *
  224. * @param signo is a specific signal value (range: 0 ~ RT_SIG_MAX).
  225. */
  226. void rt_signal_mask(int signo)
  227. {
  228. rt_base_t level;
  229. rt_thread_t tid = rt_thread_self();
  230. level = rt_spin_lock_irqsave(&_thread_signal_lock);
  231. tid->sig_mask &= ~sig_mask(signo);
  232. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  233. }
  234. /**
  235. * @brief This function will unblock the specified signal.
  236. *
  237. * @note This function will unblock the specified signal. After calling
  238. * the rt_thread_kill() function to send this signal to the current
  239. * thread, it will take effect.
  240. *
  241. * @see rt_thread_kill()
  242. *
  243. * @param signo is a specific signal value (range: 0 ~ RT_SIG_MAX).
  244. */
  245. void rt_signal_unmask(int signo)
  246. {
  247. rt_base_t level;
  248. rt_thread_t tid = rt_thread_self();
  249. level = rt_spin_lock_irqsave(&_thread_signal_lock);
  250. tid->sig_mask |= sig_mask(signo);
  251. /* let thread handle pended signals */
  252. if (tid->sig_mask & tid->sig_pending)
  253. {
  254. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  255. _signal_deliver(tid);
  256. }
  257. else
  258. {
  259. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  260. }
  261. }
  262. /**
  263. * @brief This function will wait for the arrival of the set signal. If it does not wait for this signal, the thread will be
  264. * suspended until it waits for this signal or the waiting time exceeds the specified timeout: timeout.
  265. *
  266. * @param set is the set of signal values to be waited for. Use the function
  267. * sigaddset() to add the signal.
  268. *
  269. * @param si is a pointer to the received signal info. If you don't care about this value, you can use RT_NULL to set.
  270. *
  271. * @param timeout is a timeout period (unit: an OS tick).
  272. *
  273. * @return Return the operation status. When the return value is RT_EOK, the operation is successful.
  274. * If the return value is any other values, it means that the signal wait failed.
  275. */
  276. int rt_signal_wait(const rt_sigset_t *set, rt_siginfo_t *si, rt_int32_t timeout)
  277. {
  278. int ret = RT_EOK;
  279. rt_base_t level;
  280. rt_thread_t tid = rt_thread_self();
  281. struct siginfo_node *si_node = RT_NULL, *si_prev = RT_NULL;
  282. /* current context checking */
  283. RT_DEBUG_IN_THREAD_CONTEXT;
  284. /* parameters check */
  285. if (set == NULL || *set == 0 || si == NULL )
  286. {
  287. ret = -RT_EINVAL;
  288. goto __done_return;
  289. }
  290. /* clear siginfo to avoid unknown value */
  291. memset(si, 0x0, sizeof(rt_siginfo_t));
  292. level = rt_spin_lock_irqsave(&_thread_signal_lock);
  293. /* already pending */
  294. if (tid->sig_pending & *set) goto __done;
  295. if (timeout == 0)
  296. {
  297. ret = -RT_ETIMEOUT;
  298. goto __done_int;
  299. }
  300. /* suspend self thread */
  301. rt_thread_suspend_with_flag(tid, RT_UNINTERRUPTIBLE);
  302. /* set thread stat as waiting for signal */
  303. RT_SCHED_CTX(tid).stat |= RT_THREAD_STAT_SIGNAL_WAIT;
  304. /* start timeout timer */
  305. if (timeout != RT_WAITING_FOREVER)
  306. {
  307. /* reset the timeout of thread timer and start it */
  308. rt_timer_control(&(tid->thread_timer),
  309. RT_TIMER_CTRL_SET_TIME,
  310. &timeout);
  311. rt_timer_start(&(tid->thread_timer));
  312. }
  313. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  314. /* do thread scheduling */
  315. rt_schedule();
  316. level = rt_spin_lock_irqsave(&_thread_signal_lock);
  317. /* remove signal waiting flag */
  318. RT_SCHED_CTX(tid).stat &= ~RT_THREAD_STAT_SIGNAL_WAIT;
  319. /* check errno of thread */
  320. if (tid->error == -RT_ETIMEOUT)
  321. {
  322. tid->error = RT_EOK;
  323. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  324. /* timer timeout */
  325. ret = -RT_ETIMEOUT;
  326. goto __done_return;
  327. }
  328. __done:
  329. /* to get the first matched pending signals */
  330. si_node = (struct siginfo_node *)tid->si_list;
  331. while (si_node)
  332. {
  333. int signo;
  334. signo = si_node->si.si_signo;
  335. if (sig_mask(signo) & *set)
  336. {
  337. *si = si_node->si;
  338. LOG_D("sigwait: %d sig raised!", signo);
  339. if (si_prev) si_prev->list.next = si_node->list.next;
  340. else
  341. {
  342. struct siginfo_node *node_next;
  343. if (si_node->list.next)
  344. {
  345. node_next = (void *)rt_slist_entry(si_node->list.next, struct siginfo_node, list);
  346. tid->si_list = node_next;
  347. }
  348. else
  349. {
  350. tid->si_list = RT_NULL;
  351. }
  352. }
  353. /* clear pending */
  354. tid->sig_pending &= ~sig_mask(signo);
  355. rt_mp_free(si_node);
  356. break;
  357. }
  358. si_prev = si_node;
  359. if (si_node->list.next)
  360. {
  361. si_node = (void *)rt_slist_entry(si_node->list.next, struct siginfo_node, list);
  362. }
  363. else
  364. {
  365. si_node = RT_NULL;
  366. }
  367. }
  368. __done_int:
  369. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  370. __done_return:
  371. return ret;
  372. }
  373. void rt_thread_handle_sig(rt_bool_t clean_state)
  374. {
  375. rt_base_t level;
  376. rt_thread_t tid = rt_thread_self();
  377. struct siginfo_node *si_node;
  378. level = rt_spin_lock_irqsave(&_thread_signal_lock);
  379. if (tid->sig_pending & tid->sig_mask)
  380. {
  381. /* if thread is not waiting for signal */
  382. if (!(RT_SCHED_CTX(tid).stat & RT_THREAD_STAT_SIGNAL_WAIT))
  383. {
  384. while (tid->sig_pending & tid->sig_mask)
  385. {
  386. int signo, error;
  387. rt_sighandler_t handler;
  388. si_node = (struct siginfo_node *)tid->si_list;
  389. if (!si_node) break;
  390. /* remove this sig info node from list */
  391. if (si_node->list.next == RT_NULL)
  392. tid->si_list = RT_NULL;
  393. else
  394. tid->si_list = (void *)rt_slist_entry(si_node->list.next, struct siginfo_node, list);
  395. signo = si_node->si.si_signo;
  396. handler = tid->sig_vectors[signo];
  397. tid->sig_pending &= ~sig_mask(signo);
  398. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  399. LOG_D("handle signal: %d, handler 0x%08x", signo, handler);
  400. if (handler) handler(signo);
  401. level = rt_spin_lock_irqsave(&_thread_signal_lock);
  402. error = -RT_EINTR;
  403. rt_mp_free(si_node); /* release this siginfo node */
  404. /* set errno in thread tcb */
  405. tid->error = error;
  406. }
  407. /* whether clean signal status */
  408. if (clean_state == RT_TRUE)
  409. {
  410. RT_SCHED_CTX(tid).stat &= ~RT_THREAD_STAT_SIGNAL;
  411. }
  412. else
  413. {
  414. return;
  415. }
  416. }
  417. }
  418. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  419. }
  420. void rt_thread_alloc_sig(rt_thread_t tid)
  421. {
  422. int index;
  423. rt_bool_t need_free = RT_FALSE;
  424. rt_base_t level;
  425. rt_sighandler_t *vectors;
  426. vectors = (rt_sighandler_t *)RT_KERNEL_MALLOC(sizeof(rt_sighandler_t) * RT_SIG_MAX);
  427. RT_ASSERT(vectors != RT_NULL);
  428. for (index = 0; index < RT_SIG_MAX; index ++)
  429. {
  430. vectors[index] = _signal_default_handler;
  431. }
  432. level = rt_spin_lock_irqsave(&_thread_signal_lock);
  433. if (tid->sig_vectors == RT_NULL)
  434. {
  435. tid->sig_vectors = vectors;
  436. }
  437. else
  438. {
  439. need_free = RT_TRUE;
  440. }
  441. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  442. if (need_free)
  443. {
  444. rt_free(vectors);
  445. }
  446. }
  447. void rt_thread_free_sig(rt_thread_t tid)
  448. {
  449. rt_base_t level;
  450. struct siginfo_node *si_node;
  451. rt_sighandler_t *sig_vectors;
  452. level = rt_spin_lock_irqsave(&_thread_signal_lock);
  453. si_node = (struct siginfo_node *)tid->si_list;
  454. tid->si_list = RT_NULL;
  455. sig_vectors = tid->sig_vectors;
  456. tid->sig_vectors = RT_NULL;
  457. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  458. if (si_node)
  459. {
  460. struct rt_slist_node *node;
  461. struct rt_slist_node *node_to_free;
  462. LOG_D("free signal info list");
  463. node = &(si_node->list);
  464. do
  465. {
  466. node_to_free = node;
  467. node = node->next;
  468. si_node = rt_slist_entry(node_to_free, struct siginfo_node, list);
  469. rt_mp_free(si_node);
  470. } while (node);
  471. }
  472. if (sig_vectors)
  473. {
  474. RT_KERNEL_FREE(sig_vectors);
  475. }
  476. }
  477. /**
  478. * @brief This function can be used to send any signal to any thread.
  479. *
  480. * @param tid is a pointer to the thread that receives the signal.
  481. *
  482. * @param sig is a specific signal value (range: 0 ~ RT_SIG_MAX).
  483. *
  484. * @return Return the operation status. When the return value is RT_EOK, the operation is successful.
  485. * If the return value is any other values, it means that the signal send failed.
  486. */
  487. int rt_thread_kill(rt_thread_t tid, int sig)
  488. {
  489. siginfo_t si;
  490. rt_base_t level;
  491. struct siginfo_node *si_node;
  492. RT_ASSERT(tid != RT_NULL);
  493. if (!sig_valid(sig)) return -RT_EINVAL;
  494. LOG_I("send signal: %d", sig);
  495. si.si_signo = sig;
  496. si.si_code = SI_USER;
  497. si.si_value.sival_ptr = RT_NULL;
  498. level = rt_spin_lock_irqsave(&_thread_signal_lock);
  499. if (tid->sig_pending & sig_mask(sig))
  500. {
  501. /* whether already emits this signal? */
  502. struct rt_slist_node *node;
  503. struct siginfo_node *entry;
  504. si_node = (struct siginfo_node *)tid->si_list;
  505. if (si_node)
  506. node = (struct rt_slist_node *)&si_node->list;
  507. else
  508. node = RT_NULL;
  509. /* update sig info */
  510. for (; (node) != RT_NULL; node = node->next)
  511. {
  512. entry = rt_slist_entry(node, struct siginfo_node, list);
  513. if (entry->si.si_signo == sig)
  514. {
  515. memcpy(&(entry->si), &si, sizeof(siginfo_t));
  516. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  517. return 0;
  518. }
  519. }
  520. }
  521. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  522. si_node = (struct siginfo_node *) rt_mp_alloc(_siginfo_pool, 0);
  523. if (si_node)
  524. {
  525. rt_slist_init(&(si_node->list));
  526. memcpy(&(si_node->si), &si, sizeof(siginfo_t));
  527. level = rt_spin_lock_irqsave(&_thread_signal_lock);
  528. if (tid->si_list)
  529. {
  530. struct siginfo_node *si_list;
  531. si_list = (struct siginfo_node *)tid->si_list;
  532. rt_slist_append(&(si_list->list), &(si_node->list));
  533. }
  534. else
  535. {
  536. tid->si_list = si_node;
  537. }
  538. /* a new signal */
  539. tid->sig_pending |= sig_mask(sig);
  540. rt_spin_unlock_irqrestore(&_thread_signal_lock, level);
  541. }
  542. else
  543. {
  544. LOG_E("The allocation of signal info node failed.");
  545. return -RT_EEMPTY;
  546. }
  547. /* deliver signal to this thread */
  548. _signal_deliver(tid);
  549. return RT_EOK;
  550. }
  551. int rt_system_signal_init(void)
  552. {
  553. _siginfo_pool = rt_mp_create("signal", RT_SIG_INFO_MAX, sizeof(struct siginfo_node));
  554. if (_siginfo_pool == RT_NULL)
  555. {
  556. LOG_E("create memory pool for signal info failed.");
  557. RT_ASSERT(0);
  558. }
  559. return 0;
  560. }
  561. #endif /* RT_USING_SIGNALS */