Skip to content

Commit ea3fc30

Browse files
committed
refactor: remove unused pthreadslockwrite mutex
This lock is initialised in a few places, but never locked/unlocked. Rename pthreadslockread as pthreadslock, since it is (and always has been) used for both reading and writing.
1 parent bf24cec commit ea3fc30

11 files changed

Lines changed: 82 additions & 94 deletions

File tree

sources/checkpoint.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,8 +2099,7 @@ int DoRecovery(int *moduletype)
20992099
R_COPY_B(d->where, size, void*);
21002100
}
21012101
#ifdef WITHPTHREADS
2102-
d->pthreadslockread = dummylock;
2103-
d->pthreadslockwrite = dummylock;
2102+
d->pthreadslock = dummylock;
21042103
#endif
21052104
if ( d->nfactors > 1 ) {
21062105
R_COPY_B(d->factors,sizeof(FACDOLLAR)*d->nfactors,FACDOLLAR*);

sources/dollar.c

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,7 @@ int AssignDollar(PHEAD WORD *term, WORD level)
252252
*/
253253
#ifdef WITHPTHREADS
254254
if ( dtype > 0 ) {
255-
/* LOCK(d->pthreadslockwrite); */
256-
LOCK(d->pthreadslockread);
255+
LOCK(d->pthreadslock);
257256
NewValIsZero:;
258257
switch ( d->type ) {
259258
case DOLZERO: goto NoChangeZero;
@@ -278,8 +277,7 @@ NewValIsZero:;
278277
cbuf[AM.dbufnum].NumTerms[numdollar] = 0;
279278
NoChangeZero:;
280279
CleanDollarFactors(d);
281-
/* UNLOCK(d->pthreadslockwrite); */
282-
UNLOCK(d->pthreadslockread);
280+
UNLOCK(d->pthreadslock);
283281
AN.ncmod = oldncmod;
284282
return(0);
285283
}
@@ -301,8 +299,7 @@ NoChangeZero:;
301299
*/
302300
#ifdef WITHPTHREADS
303301
if ( dtype > 0 ) {
304-
/* LOCK(d->pthreadslockwrite); */
305-
LOCK(d->pthreadslockread);
302+
LOCK(d->pthreadslock);
306303
if ( d->size < MINALLOC ) {
307304
WORD oldsize, *oldwhere, i;
308305
oldsize = d->size; oldwhere = d->where;
@@ -365,8 +362,7 @@ HandleDolZero:;
365362
cbuf[AM.dbufnum].NumTerms[numdollar] = 1;
366363
NoChangeOne:;
367364
CleanDollarFactors(d);
368-
/* UNLOCK(d->pthreadslockwrite); */
369-
UNLOCK(d->pthreadslockread);
365+
UNLOCK(d->pthreadslock);
370366
AN.ncmod = oldncmod;
371367
return(0);
372368
}
@@ -398,7 +394,7 @@ NoChangeOne:;
398394
depends on the dollar variable.
399395
*/
400396
#ifdef WITHPTHREADS
401-
LOCK(d->pthreadslockread);
397+
LOCK(d->pthreadslock);
402398
#endif
403399
CleanDollarFactors(d);
404400
/*
@@ -566,8 +562,7 @@ HandleDolZero1:;
566562
}
567563
#ifdef WITHPTHREADS
568564
NoChange:;
569-
/* UNLOCK(d->pthreadslockwrite); */
570-
UNLOCK(d->pthreadslockread);
565+
UNLOCK(d->pthreadslock);
571566
#endif
572567
AN.ncmod = oldncmod;
573568
return(0);
@@ -1088,7 +1083,7 @@ WORD DolToTensor(PHEAD WORD numdollar)
10881083
d = ModOptdollars[nummodopt].dstruct+AT.identity;
10891084
}
10901085
else {
1091-
LOCK(d->pthreadslockread);
1086+
LOCK(d->pthreadslock);
10921087
}
10931088
}
10941089
}
@@ -1122,7 +1117,7 @@ WORD DolToTensor(PHEAD WORD numdollar)
11221117
retval = 0;
11231118
}
11241119
#ifdef WITHPTHREADS
1125-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
1120+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
11261121
#endif
11271122
return(retval);
11281123
}
@@ -1149,7 +1144,7 @@ WORD DolToFunction(PHEAD WORD numdollar)
11491144
d = ModOptdollars[nummodopt].dstruct+AT.identity;
11501145
}
11511146
else {
1152-
LOCK(d->pthreadslockread);
1147+
LOCK(d->pthreadslock);
11531148
}
11541149
}
11551150
}
@@ -1179,7 +1174,7 @@ WORD DolToFunction(PHEAD WORD numdollar)
11791174
retval = 0;
11801175
}
11811176
#ifdef WITHPTHREADS
1182-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
1177+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
11831178
#endif
11841179
return(retval);
11851180
}
@@ -1206,7 +1201,7 @@ WORD DolToVector(PHEAD WORD numdollar)
12061201
d = ModOptdollars[nummodopt].dstruct+AT.identity;
12071202
}
12081203
else {
1209-
LOCK(d->pthreadslockread);
1204+
LOCK(d->pthreadslock);
12101205
}
12111206
}
12121207
}
@@ -1243,7 +1238,7 @@ WORD DolToVector(PHEAD WORD numdollar)
12431238
retval = 0;
12441239
}
12451240
#ifdef WITHPTHREADS
1246-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
1241+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
12471242
#endif
12481243
return(retval);
12491244
}
@@ -1329,7 +1324,7 @@ WORD DolToSymbol(PHEAD WORD numdollar)
13291324
d = ModOptdollars[nummodopt].dstruct+AT.identity;
13301325
}
13311326
else {
1332-
LOCK(d->pthreadslockread);
1327+
LOCK(d->pthreadslock);
13331328
}
13341329
}
13351330
}
@@ -1356,7 +1351,7 @@ WORD DolToSymbol(PHEAD WORD numdollar)
13561351
retval = -1;
13571352
}
13581353
#ifdef WITHPTHREADS
1359-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
1354+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
13601355
#endif
13611356
return(retval);
13621357
}
@@ -1383,7 +1378,7 @@ WORD DolToIndex(PHEAD WORD numdollar)
13831378
d = ModOptdollars[nummodopt].dstruct+AT.identity;
13841379
}
13851380
else {
1386-
LOCK(d->pthreadslockread);
1381+
LOCK(d->pthreadslock);
13871382
}
13881383
}
13891384
}
@@ -1432,7 +1427,7 @@ WORD DolToIndex(PHEAD WORD numdollar)
14321427
retval = 0;
14331428
}
14341429
#ifdef WITHPTHREADS
1435-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
1430+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
14361431
#endif
14371432
return(retval);
14381433
}
@@ -1571,8 +1566,7 @@ DOLLARS DolToTerms(PHEAD WORD numdollar)
15711566
newd->size = size;
15721567
newd->numdummies = d->numdummies;
15731568
#ifdef WITHPTHREADS
1574-
newd->pthreadslockread = dummylock;
1575-
newd->pthreadslockwrite = dummylock;
1569+
newd->pthreadslock = dummylock;
15761570
#endif
15771571
size++;
15781572
NCOPY(t,w,size);
@@ -1763,8 +1757,7 @@ int InsideDollar(PHEAD WORD *ll, WORD level)
17631757
d = ModOptdollars[nummodopt].dstruct+AT.identity;
17641758
}
17651759
else {
1766-
/* LOCK(d->pthreadslockwrite); */
1767-
LOCK(d->pthreadslockread);
1760+
LOCK(d->pthreadslock);
17681761
}
17691762
}
17701763
}
@@ -1817,8 +1810,7 @@ int InsideDollar(PHEAD WORD *ll, WORD level)
18171810
*/
18181811
#ifdef WITHPTHREADS
18191812
if ( dtype > 0 && dtype != MODLOCAL ) {
1820-
/* UNLOCK(d->pthreadslockwrite); */
1821-
UNLOCK(d->pthreadslockread);
1813+
UNLOCK(d->pthreadslock);
18221814
}
18231815
#endif
18241816
if ( newd->factors ) M_free(newd->factors,"Dollar factors");
@@ -1874,7 +1866,7 @@ LONG TermsInDollar(WORD num)
18741866
d = ModOptdollars[nummodopt].dstruct+AT.identity;
18751867
}
18761868
else {
1877-
LOCK(d->pthreadslockread);
1869+
LOCK(d->pthreadslock);
18781870
}
18791871
}
18801872
}
@@ -1895,7 +1887,7 @@ LONG TermsInDollar(WORD num)
18951887
else if ( d->type == DOLZERO ) n = 0;
18961888
else n = 1;
18971889
#ifdef WITHPTHREADS
1898-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
1890+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
18991891
#endif
19001892
return(n);
19011893
}
@@ -1923,7 +1915,7 @@ LONG SizeOfDollar(WORD num)
19231915
d = ModOptdollars[nummodopt].dstruct+AT.identity;
19241916
}
19251917
else {
1926-
LOCK(d->pthreadslockread);
1918+
LOCK(d->pthreadslock);
19271919
}
19281920
}
19291921
}
@@ -1947,7 +1939,7 @@ LONG SizeOfDollar(WORD num)
19471939
else if ( d->type == DOLZERO ) n = 0;
19481940
else n = 1;
19491941
#ifdef WITHPTHREADS
1950-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
1942+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
19511943
#endif
19521944
return(n);
19531945
}
@@ -2974,14 +2966,14 @@ int DollarFactorize(PHEAD WORD numdollar)
29742966
d = ModOptdollars[nummodopt].dstruct+AT.identity;
29752967
}
29762968
else {
2977-
LOCK(d->pthreadslockread);
2969+
LOCK(d->pthreadslock);
29782970
}
29792971
}
29802972
}
29812973
#endif
29822974
CleanDollarFactors(d);
29832975
#ifdef WITHPTHREADS
2984-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
2976+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
29852977
#endif
29862978
if ( d->type != DOLTERMS ) { /* only one term */
29872979
if ( d->type != DOLZERO ) d->nfactors = 1;
@@ -3231,13 +3223,13 @@ int DollarFactorize(PHEAD WORD numdollar)
32313223
Be careful: there should be more than one factor now.
32323224
*/
32333225
#ifdef WITHPTHREADS
3234-
if ( dtype > 0 && dtype != MODLOCAL ) { LOCK(d->pthreadslockread); }
3226+
if ( dtype > 0 && dtype != MODLOCAL ) { LOCK(d->pthreadslock); }
32353227
#endif
32363228
if ( nfactors == 1 && extrafactor == 0 ) { /* we can use the buf1 contents */
32373229
if ( factorsincontent == 0 ) {
32383230
d->nfactors = 1;
32393231
#ifdef WITHPTHREADS
3240-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3232+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
32413233
#endif
32423234
/*
32433235
We used here (before 3-sep-2015) the original and did not make
@@ -3289,7 +3281,7 @@ getout2: AR.SortType = oldsorttype;
32893281
M_free(d->factors,"factors in dollar");
32903282
d->factors = 0;
32913283
#ifdef WITHPTHREADS
3292-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3284+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
32933285
#endif
32943286
M_free(buf3,"DollarFactorize-4");
32953287
if ( buf2 != buf1 && buf2 ) M_free(buf2,"DollarFactorize-4");
@@ -3533,7 +3525,7 @@ nextj:;
35333525
#] Step 8:
35343526
*/
35353527
#ifdef WITHPTHREADS
3536-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
3528+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
35373529
#endif
35383530
return(0);
35393531
}

sources/if.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ int DoIfStatement(PHEAD WORD *ifcode, WORD *term)
475475
d = ModOptdollars[nummodopt].dstruct+AT.identity;
476476
}
477477
else {
478-
LOCK(d->pthreadslockread);
478+
LOCK(d->pthreadslock);
479479
}
480480
}
481481
}
@@ -532,7 +532,7 @@ int DoIfStatement(PHEAD WORD *ifcode, WORD *term)
532532
case DOLUNDEFINED:
533533
if ( AC.UnsureDollarMode == 0 ) {
534534
#ifdef WITHPTHREADS
535-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
535+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
536536
#endif
537537
MLOCK(ErrorMessageLock);
538538
MesPrint("$%s is undefined",AC.dollarnames->namebuffer+d->name);
@@ -549,7 +549,7 @@ int DoIfStatement(PHEAD WORD *ifcode, WORD *term)
549549
|| d->where[2] < 0 || d->where[2] >= AM.OffsetIndex ) {
550550
if ( AC.UnsureDollarMode == 0 ) {
551551
#ifdef WITHPTHREADS
552-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
552+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
553553
#endif
554554
MLOCK(ErrorMessageLock);
555555
MesPrint("$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
@@ -570,7 +570,7 @@ int DoIfStatement(PHEAD WORD *ifcode, WORD *term)
570570
}
571571
else if ( AC.UnsureDollarMode == 0 ) {
572572
#ifdef WITHPTHREADS
573-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
573+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
574574
#endif
575575
MLOCK(ErrorMessageLock);
576576
MesPrint("$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
@@ -586,7 +586,7 @@ int DoIfStatement(PHEAD WORD *ifcode, WORD *term)
586586
) {
587587
if ( AC.UnsureDollarMode == 0 ) {
588588
#ifdef WITHPTHREADS
589-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
589+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
590590
#endif
591591
MLOCK(ErrorMessageLock);
592592
MesPrint("$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
@@ -635,7 +635,7 @@ int DoIfStatement(PHEAD WORD *ifcode, WORD *term)
635635
else {
636636
if ( AC.UnsureDollarMode == 0 ) {
637637
#ifdef WITHPTHREADS
638-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
638+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
639639
#endif
640640
MLOCK(ErrorMessageLock);
641641
MesPrint("$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
@@ -661,7 +661,7 @@ int DoIfStatement(PHEAD WORD *ifcode, WORD *term)
661661
generic:;
662662
if ( AC.UnsureDollarMode == 0 ) {
663663
#ifdef WITHPTHREADS
664-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
664+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
665665
#endif
666666
MLOCK(ErrorMessageLock);
667667
MesPrint("$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
@@ -673,7 +673,7 @@ generic:;
673673
}
674674
}
675675
#ifdef WITHPTHREADS
676-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
676+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
677677
#endif
678678
}
679679
break;

sources/message.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ int MesPrint(const char *fmt, ... )
425425
d = ModOptdollars[nummodopt].dstruct+AT.identity;
426426
}
427427
else {
428-
LOCK(d->pthreadslockread);
428+
LOCK(d->pthreadslock);
429429
}
430430
}
431431
}
@@ -480,7 +480,7 @@ printterms: first = 1;
480480
AddToLine((UBYTE *)Out);
481481
if ( WriteInnerTerm(term,first) ) {
482482
#ifdef WITHPTHREADS
483-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
483+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
484484
#endif
485485
Terminate(-1);
486486
}
@@ -511,7 +511,7 @@ dosubterm: if ( AC.LineLength > MAXLINELENGTH ) AC.LineLength = MAXLINELENGTH
511511
AddToLine((UBYTE *)Out);
512512
if ( WriteSubTerm(tt,1) ) {
513513
#ifdef WITHPTHREADS
514-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
514+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
515515
#endif
516516
Terminate(-1);
517517
}
@@ -615,7 +615,7 @@ dollarzero: *t++ = '0'; *t = 0;
615615
}
616616
}
617617
#ifdef WITHPTHREADS
618-
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
618+
if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
619619
#endif
620620
AN.listinprint += 2;
621621
while ( AN.listinprint[0] == DOLLAREXPR2 ) AN.listinprint += 2;

sources/module.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,7 @@ UBYTE * DoModDollar(UBYTE *s, int type)
718718
dlocal->where[i] = dglobal->where[i];
719719
dlocal->where[dlocal->size] = 0;
720720
}
721-
dlocal->pthreadslockread = dummylock;
722-
dlocal->pthreadslockwrite = dummylock;
721+
dlocal->pthreadslock = dummylock;
723722
dlocal->nfactors = dglobal->nfactors;
724723
if ( dglobal->nfactors > 1 ) {
725724
int nsize;

0 commit comments

Comments
 (0)