Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit332ee2d

Browse files
committed
Improve spinlock selftest to make it able to detect misdeclaration of
the slock_t datatype (ie, declared type smaller than what the hardwareTAS instruction needs).
1 parent17364ed commit332ee2d

File tree

1 file changed

+44
-11
lines changed

1 file changed

+44
-11
lines changed

‎src/backend/storage/lmgr/s_lock.c

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/s_lock.c,v 1.31 2004/08/3002:54:38 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/s_lock.c,v 1.32 2004/08/3023:47:20 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -249,40 +249,73 @@ tas_dummy()/* really means: extern int tas(slock_t
249249
* test program for verifying a port's spinlock support.
250250
*/
251251

252-
volatileslock_ttest_lock;
252+
structtest_lock_struct
253+
{
254+
charpad1;
255+
slock_tlock;
256+
charpad2;
257+
};
258+
259+
volatilestructtest_lock_structtest_lock;
253260

254261
int
255262
main()
256263
{
257264
srandom((unsignedint)time(NULL));
258265

259-
S_INIT_LOCK(&test_lock);
266+
test_lock.pad1=test_lock.pad2=0x44;
267+
268+
S_INIT_LOCK(&test_lock.lock);
269+
270+
if (test_lock.pad1!=0x44||test_lock.pad2!=0x44)
271+
{
272+
printf("S_LOCK_TEST: failed, declared datatype is wrong size\n");
273+
return1;
274+
}
260275

261-
if (!S_LOCK_FREE(&test_lock))
276+
if (!S_LOCK_FREE(&test_lock.lock))
262277
{
263278
printf("S_LOCK_TEST: failed, lock not initialized\n");
264279
return1;
265280
}
266281

267-
S_LOCK(&test_lock);
282+
S_LOCK(&test_lock.lock);
268283

269-
if (S_LOCK_FREE(&test_lock))
284+
if (test_lock.pad1!=0x44||test_lock.pad2!=0x44)
285+
{
286+
printf("S_LOCK_TEST: failed, declared datatype is wrong size\n");
287+
return1;
288+
}
289+
290+
if (S_LOCK_FREE(&test_lock.lock))
270291
{
271292
printf("S_LOCK_TEST: failed, lock not locked\n");
272293
return1;
273294
}
274295

275-
S_UNLOCK(&test_lock);
296+
S_UNLOCK(&test_lock.lock);
297+
298+
if (test_lock.pad1!=0x44||test_lock.pad2!=0x44)
299+
{
300+
printf("S_LOCK_TEST: failed, declared datatype is wrong size\n");
301+
return1;
302+
}
276303

277-
if (!S_LOCK_FREE(&test_lock))
304+
if (!S_LOCK_FREE(&test_lock.lock))
278305
{
279306
printf("S_LOCK_TEST: failed, lock not unlocked\n");
280307
return1;
281308
}
282309

283-
S_LOCK(&test_lock);
310+
S_LOCK(&test_lock.lock);
311+
312+
if (test_lock.pad1!=0x44||test_lock.pad2!=0x44)
313+
{
314+
printf("S_LOCK_TEST: failed, declared datatype is wrong size\n");
315+
return1;
316+
}
284317

285-
if (S_LOCK_FREE(&test_lock))
318+
if (S_LOCK_FREE(&test_lock.lock))
286319
{
287320
printf("S_LOCK_TEST: failed, lock not re-locked\n");
288321
return1;
@@ -293,7 +326,7 @@ main()
293326
printf(" if S_LOCK() and TAS() are working.\n");
294327
fflush(stdout);
295328

296-
s_lock(&test_lock,__FILE__,__LINE__);
329+
s_lock(&test_lock.lock,__FILE__,__LINE__);
297330

298331
printf("S_LOCK_TEST: failed, lock not locked\n");
299332
return1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp