process shared robust mutexes for tdb

Rusty Russell rusty at samba.org
Tue Mar 26 18:15:41 MDT 2013


Volker Lendecke <Volker.Lendecke at SerNet.DE> writes:
> On Tue, Mar 26, 2013 at 09:37:01AM +1030, Rusty Russell wrote:
>> > +/*
>> > + * If we run with mutexes, we store the "struct tdb_mutexes" at the
>> > + * beginning of the file. We store an additional tdb_header right
>> > + * beyond the mutex area, page aligned. All the offsets within the tdb
>> > + * are relative to the area behind the mutex area. tdb->map_ptr points
>> > + * behind the mmap area as well, so the read and write path in the
>> > + * mutex case can remain unchanged.
>> 
>> I think this comment has dated.  The tdb->map_ptr is now a complete mmap
>> area, so that sentence can be deleted.
>
> Nope, it's not. See tdb_mmap():
>
> tdb->map_ptr = mmap(NULL, tdb->map_size,
>                     PROT_READ|(tdb->read_only?0:PROT_WRITE),
>                     MAP_SHARED|MAP_FILE, tdb->fd,
>                     tdb_mutex_size(tdb));
>
> The last argument is the offset we start at. That is the
> reason why we have to adjust the offsets in tdb_pread/write:
> When doing mmap, that's where the implicit offset adjust is.

Ah, it's the "behind" language which confused me again, sorry.

>> > +		tdb->num_chain_mutexes_locked += 1;
>> > +		*pret = 0;
>> > +		return true;
>> > +	}
>> 
>> This += 1 and -= 1 appears a few places here: it's a bit weird...
>
> +=1 was twice. I replaced one with =1. I only see one -=1;
>
> Or do you strongly prefer ++? I always use +=1, that's just
> my style.

Yeah, I expected ++ / --.  The += 1 make me look for the subtle trick...

Thanks,
Rusty.


More information about the samba-technical mailing list