Skip site navigation (1) Skip section navigation (2)

Re: trivial refactoring of WaitOnLock

From: "Qingqing Zhou" <zhouqq(at)cs(dot)toronto(dot)edu>
To: pgsql-patches(at)postgresql(dot)org
Subject: Re: trivial refactoring of WaitOnLock
Date: 2005-03-09 07:42:55
Message-ID: d0m9me$2r13$1@news.hub.org (view raw or flat)
Thread:
Lists: pgsql-patches
off-by-one is true, but I am not sure if the revised code is faster.
sprintf() need the extra job to parse the format. In win32, I am sure it is
much slower.

"Neil Conway" <neilc(at)samurai(dot)com> ???? news:422E3EAC(dot)9000403(at)samurai(dot)com(dot)(dot)(dot)
> This patch refactors some code in WaitOnLock slightly. The old code was
> slow, and I believe it was off-by-one (it allocates one byte of memory
> more than needed).
>
> Barring any objections I'll apply this to HEAD later today.
>
> -Neil
>


----------------------------------------------------------------------------
----


> Index: src/backend/storage/lmgr/lock.c
> ===================================================================
> RCS file: /var/lib/cvs/pgsql/src/backend/storage/lmgr/lock.c,v
> retrieving revision 1.147
> diff -c -r1.147 lock.c
> *** src/backend/storage/lmgr/lock.c 1 Mar 2005 21:14:59 -0000 1.147
> --- src/backend/storage/lmgr/lock.c 8 Mar 2005 05:42:06 -0000
> ***************
> *** 1076,1081 ****
> --- 1076,1082 ----
>   LockMethod lockMethodTable = LockMethods[lockmethodid];
>   char    *new_status,
>      *old_status;
> + size_t len;
>
>   Assert(lockmethodid < NumLockMethods);
>
> ***************
> *** 1083,1091 ****
>      locallock->lock, locallock->tag.mode);
>
>   old_status = pstrdup(get_ps_display());
> ! new_status = (char *) palloc(strlen(old_status) + 10);
> ! strcpy(new_status, old_status);
> ! strcat(new_status, " waiting");
>   set_ps_display(new_status);
>
>   awaitedLock = locallock;
> --- 1084,1092 ----
>      locallock->lock, locallock->tag.mode);
>
>   old_status = pstrdup(get_ps_display());
> ! len = strlen(old_status);
> ! new_status = (char *) palloc(len + 8 + 1);
> ! sprintf(new_status, "%s waiting", old_status);
>   set_ps_display(new_status);
>
>   awaitedLock = locallock;
>


----------------------------------------------------------------------------
----


>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>



In response to

Responses

pgsql-patches by date

Next:From: Russell SmithDate: 2005-03-09 09:08:08
Subject: Re: trivial refactoring of WaitOnLock
Previous:From: Alvaro HerreraDate: 2005-03-09 04:05:31
Subject: Re: Shared dependency patch

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group