Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 332ee2d

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 hardware TAS instruction needs).
1 parent 17364ed commit 332ee2d

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/30 02:54:38 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/s_lock.c,v 1.32 2004/08/30 23: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-
volatile slock_t test_lock;
252+
struct test_lock_struct
253+
{
254+
char pad1;
255+
slock_t lock;
256+
char pad2;
257+
};
258+
259+
volatile struct test_lock_struct test_lock;
253260

254261
int
255262
main()
256263
{
257264
srandom((unsigned int) 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+
return 1;
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
return 1;
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+
return 1;
288+
}
289+
290+
if (S_LOCK_FREE(&test_lock.lock))
270291
{
271292
printf("S_LOCK_TEST: failed, lock not locked\n");
272293
return 1;
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+
return 1;
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
return 1;
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+
return 1;
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
return 1;
@@ -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
return 1;

0 commit comments

Comments
 (0)