信号处理,信号队列

最近几天在看信号,对实时信号的实时性不是很理解,今天看了下 __dequeue_signal 差不多理解了,一个实时信号可以有多个实时队列,在signal集合里一个signal可能有多个signal队列。

信号,有信号队列,有信号集

sigpending是信号pending的结构体,里面有sigqueue的链表,和signal的一个集合,这个集合,实际是一个 unsigned long 64位的类型的值,所以也可以这个也限制了信号的数据,也只能支持64个信号。

typedef unsigned long sigset_t; 

struct sigpending {
	struct list_head list;
	sigset_t signal;
};

 

 

__dequeue_signal 取出信息

static int __dequeue_signal(struct sigpending *pending, sigset_t *mask,
			siginfo_t *info)
{
	int sig = next_signal(pending, mask);

	if (sig) {
		if (current->notifier) {
			if (sigismember(current->notifier_mask, sig)) {
				if (!(current->notifier)(current->notifier_data)) {
					clear_thread_flag(TIF_SIGPENDING);
					return 0;
				}
			}
		}

		collect_signal(sig, pending, info);
	}

	return sig;
}

colloct_signal 收集信号,如果存在二个的队列,则不从signal里删除对应sig比特位

static void collect_signal(int sig, struct sigpending *list, siginfo_t *info)
{
	struct sigqueue *q, *first = NULL;

	/*
	 * Collect the siginfo appropriate to this signal.  Check if
	 * there is another siginfo for the same signal.
	*/
	list_for_each_entry(q, &list->list, list) {
		if (q->info.si_signo == sig) {
			if (first)
				goto still_pending;
			first = q;
		}
	}

	sigdelset(&list->signal, sig);

	if (first) {
still_pending:
		list_del_init(&first->list);
		copy_siginfo(info, &first->info);
		__sigqueue_free(first);
	} else {
		/*
		 * Ok, it wasn't in the queue.  This must be
		 * a fast-pathed signal or we must have been
		 * out of queue space.  So zero out the info.
		 */
		info->si_signo = sig;
		info->si_errno = 0;
		info->si_code = SI_USER;
		info->si_pid = 0;
		info->si_uid = 0;
	}
}

参考了下面的文章,但是他里面没有取信号的讲解,所以写文章补充下。

 

参考:http://kernel.meizu.com/linux-signal.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Qt 中,可以使用 `QFutureWatcher` 类来监视后台线程的进度并在处理完成后发出信号。如果您想要监视消息队列的处理完成信号,您可以将 `QFutureWatcher` 与 `QFuture` 结合使用来监视消息队列的处理进度。 以下是一个使用 `QFutureWatcher` 监视消息队列的示例代码: ```cpp #include <QtConcurrent/QtConcurrent> #include <QFutureWatcher> // Define a function to process the message queue void processMessageQueue(QQueue<QString>& messageQueue) { while (!messageQueue.isEmpty()) { QString message = messageQueue.dequeue(); // Process the message here } } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QQueue<QString> messageQueue; // Add some messages to the queue messageQueue.enqueue("Message 1"); messageQueue.enqueue("Message 2"); messageQueue.enqueue("Message 3"); // Use QtConcurrent to process the message queue in a background thread QFuture<void> future = QtConcurrent::run(processMessageQueue, messageQueue); // Use QFutureWatcher to monitor the progress of the background thread QFutureWatcher<void> watcher; QObject::connect(&watcher, &QFutureWatcher<void>::finished, [&]() { qDebug() << "Message queue processing finished!"; }); watcher.setFuture(future); return a.exec(); } ``` 在上面的示例中,我们使用 `QtConcurrent::run` 函数在后台线程中处理消息队列。然后,我们使用 `QFutureWatcher` 类监视处理进度并在处理完成后发出信号。在 `QFutureWatcher::finished` 信号的槽函数中,我们可以执行任何需要在处理完成后执行的操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值