LW_SHARED_MASK macro

Started by Alexander Korotkovover 10 years ago5 messageshackers
Jump to latest
#1Alexander Korotkov
aekorotkov@gmail.com

Hackers,

while exploring lwlock.c I found following macro to be strange.

#define LW_SHARED_MASK ((uint32)(1 << 23))

This is macro is used to extract number of shared locks from state.

ereport(LOG,
(errhidestmt(true),
errhidecontext(true),
errmsg("%d: %s(%s): excl %u shared %u haswaiters %u waiters %u rOK %d",
MyProcPid,
where, MainLWLockNames[id],
!!(state & LW_VAL_EXCLUSIVE),
state & LW_SHARED_MASK,
!!(state & LW_FLAG_HAS_WAITERS),
pg_atomic_read_u32(&lock->nwaiters),
!!(state & LW_FLAG_RELEASE_OK))));

Should it be ((uint32) ((1 << 24)-1)) instead?

------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

lw_shared_mask.patchapplication/octet-stream; name=lw_shared_mask.patchDownload+2-2
#2Andres Freund
andres@anarazel.de
In reply to: Alexander Korotkov (#1)
Re: LW_SHARED_MASK macro

Hi,

On 2015-09-17 14:35:20 +0300, Alexander Korotkov wrote:

while exploring lwlock.c I found following macro to be strange.

#define LW_SHARED_MASK ((uint32)(1 << 23))

This is macro is used to extract number of shared locks from state.

ereport(LOG,
(errhidestmt(true),
errhidecontext(true),
errmsg("%d: %s(%s): excl %u shared %u haswaiters %u waiters %u rOK %d",
MyProcPid,
where, MainLWLockNames[id],
!!(state & LW_VAL_EXCLUSIVE),
state & LW_SHARED_MASK,
!!(state & LW_FLAG_HAS_WAITERS),
pg_atomic_read_u32(&lock->nwaiters),
!!(state & LW_FLAG_RELEASE_OK))));

Should it be ((uint32) ((1 << 24)-1)) instead?

Argh, that's somewhat embarassing. You're absolutely right. Luckily it's
only used for LOCK_DEBUG, but still...

Andres

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Alexander Korotkov
aekorotkov@gmail.com
In reply to: Andres Freund (#2)
Re: LW_SHARED_MASK macro

On Thu, Sep 17, 2015 at 5:38 PM, Andres Freund <andres@anarazel.de> wrote:

On 2015-09-17 14:35:20 +0300, Alexander Korotkov wrote:

while exploring lwlock.c I found following macro to be strange.

#define LW_SHARED_MASK ((uint32)(1 << 23))

This is macro is used to extract number of shared locks from state.

ereport(LOG,
(errhidestmt(true),
errhidecontext(true),
errmsg("%d: %s(%s): excl %u shared %u haswaiters %u waiters %u rOK %d",
MyProcPid,
where, MainLWLockNames[id],
!!(state & LW_VAL_EXCLUSIVE),
state & LW_SHARED_MASK,
!!(state & LW_FLAG_HAS_WAITERS),
pg_atomic_read_u32(&lock->nwaiters),
!!(state & LW_FLAG_RELEASE_OK))));

Should it be ((uint32) ((1 << 24)-1)) instead?

Argh, that's somewhat embarassing. You're absolutely right. Luckily it's
only used for LOCK_DEBUG, but still...

Great. BTW, are you going to commit this?

------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

#4Andres Freund
andres@anarazel.de
In reply to: Alexander Korotkov (#3)
Re: LW_SHARED_MASK macro

On 2015-09-21 22:34:46 +0300, Alexander Korotkov wrote:

Great. BTW, are you going to commit this?

Yes, will do so tomorrow.

Thanks,

Andres

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Andres Freund
andres@anarazel.de
In reply to: Andres Freund (#4)
Re: LW_SHARED_MASK macro

On 2015-09-21 21:36:15 +0200, Andres Freund wrote:

On 2015-09-21 22:34:46 +0300, Alexander Korotkov wrote:

Great. BTW, are you going to commit this?

Yes, will do so tomorrow.

And done. Thanks for noticing.

Andres

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers