Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 3 Jun 2005 15:24:19 +0200
From:      "Norbert Koch" <NKoch@demig.de>
To:        "Freebsd-Hackers@Freebsd. Org" <freebsd-hackers@freebsd.org>
Subject:   synchronization question about /sys/dev/vkbd/vkbd.c
Message-ID:  <000001c5683f$8c7c1e60$4801a8c0@ws-ew-3.W2KDEMIG>

next in thread | raw e-mail | index | archive | help
Hello.

When looking at /sys/dev/vkbd/vkbd.c I found
one thing, that I do not understand.

There are three places, where a flag TASK is used:

1. in vkbd_dev_close():

  while(state->ks_flag & TASK) VKBD_SLEEP (...);

2. in vkbd_dev_write()

  VKBD_LOCK ();
  ...
  if (!(state->ks_flags & TASK) && task_enqueue(...))
    state->ks_flags |= TASK;
  ...
  VKBD_UNLOCK ();

3. in vkbd_dev_intr()

  ...
  /* call intr */
  ...
  VKBD_LOCK();
  state->ks_flags &= ~TASK;
  wakeup(...);
  VKBD_UNLOCK();

As I understand:
vkbd_dev_write() writes data into its queue
and wants vkbd_dev_intr() to process the queue.

My question is:
Is it not possible, that vkbd_dev_intr() could be
interrupted at any position before the VKBD_LOCK()
and then vkbd_dev_write() called?
If yes, how should vkbd_dev_write() know, that it should
call task_enqueue(), as TASK is still set?

Why not always call task_enqueue() unconditionally here
and leave TASK only to synchronize the close call?

Thank you for any help,

Norbert Koch
    



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000001c5683f$8c7c1e60$4801a8c0>