Re: Which types of locking should I use?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello, Jan.

Thank you for your time.
I'm deaf about mathematical techniques, so I didn't use list_head.
I defined the following structure before I saw your hints, and it worked fine.
I'm sorry I'm too late to use your hints.


typedef struct {
  const char *filename;    // ('\0'-terminated) pathname
  const void *next_item;   // Pointer to the next ITEM, NULL if no more ITEMs.
  unsigned short int perm; // Access Mode
} ITEM;

typedef struct {
  ITEM *first_item;        // Pointer to the first ITEM, NULL if no ITEM.
  const char *header_text; // Comments
} TAG;


I used spinlock only for write access, no lock for read access.

(1) Once memory for ITEM is allocated, it remains there forever.
(2) ITEM is appended to the tail of the linked-list after ITEM.next_item is initialized to NULL.

So, if the reader found that TAG.first_item != NULL or ITEM.next_item != NULL,
the next ITEM always exist and valid,
and never overruns because the last ITEM.next_item is always NULL.
( Do I need to use wmb() between NewItem.next_item = NULL and TailItem.next_item = NewItem
  as "Avoiding Locks: Read And Write Ordering" in "Unreliable Guide To Locking" ?)

Thank you.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux