Re: Which types of locking should I use?

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

 



On Thu, May 06, 2004 at 22:55:23 +0900, Tetsuo Handa wrote:
> Hello, Jan.
> 
> Thank you for your time.
> I'm deaf about mathematical techniques, so I didn't use list_head.

There is NOTHING MATHEMATICAL in list.h. list.h simply provides
a WORKING and SIMPLE to use implementation of doubly-linked lists with
head. The "working" property is very valuable -- it's damn hard to debug
invalid pointers in kernel. Kernel likes to do all kinds of really
strange things when you have bugs like these.

> 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;

Could you explain to me, why are you allocating TWO SEPARATE memory
chunks (for the string and for the filename), whe ONE could do?!?!
(Unless, of course, somebody else allocated the filename, but from what
you wrote before, it didn't seem to be the case).

> 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.

Why? You can just as easily prepend.

> 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" ?)

Yes, you do need to use wmb(). Physical writeout order is not specified
otherwise.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>

Attachment: signature.asc
Description: Digital signature


[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