@@ -631,7 +631,7 @@ static inline int is_dead(int id) {
631
631
return shmctl (id , IPC_STAT , & ds );
632
632
}
633
633
634
- static void open_shmem (void ) {
634
+ static int open_shmem (void ) {
635
635
636
636
int try = 0 ;
637
637
@@ -657,30 +657,42 @@ static void open_shmem(void) {
657
657
} while ((try < 10 ) && (shmid == -1 ));
658
658
659
659
if (shmid == -1 ) {
660
- fprintf ( stderr , "GotoBLAS : Can't open shared memory. Terminated.\n " );
661
- exit (1 );
660
+ perror ( "Obtaining shared memory segment failed in open_shmem " );
661
+ return (1 );
662
662
}
663
663
664
664
if (shmid != -1 ) {
665
- if ( (common = shmat (shmid , NULL , 0 )) == (void * )-1 ) perror ("Attaching shared memory segment" );
665
+ if ( (common = shmat (shmid , NULL , 0 )) == (void * )-1 ) {
666
+ perror ("Attaching shared memory segment failed in open_shmem" );
667
+ return (1 );
668
+ }
666
669
}
667
670
#ifdef DEBUG
668
671
fprintf (stderr , "Shared Memory id = %x Address = %p\n" , shmid , common );
669
672
#endif
670
-
673
+ return ( 0 );
671
674
}
672
675
673
- static void create_pshmem (void ) {
676
+ static int create_pshmem (void ) {
674
677
675
678
pshmid = shmget (IPC_PRIVATE , 4096 , IPC_CREAT | 0666 );
676
679
677
- paddr = shmat (pshmid , NULL , 0 );
678
-
679
- shmctl (pshmid , IPC_RMID , 0 );
680
+ if (pshmid == -1 ) {
681
+ perror ("Obtaining shared memory segment failed in create_pshmem" );
682
+ return (1 );
683
+ }
684
+
685
+ if ( (paddr = shmat (pshmid , NULL , 0 )) == (void * )-1 ) {
686
+ perror ("Attaching shared memory segment failed in create_pshmem" );
687
+ return (1 );
688
+ }
689
+
690
+ if (shmctl (pshmid , IPC_RMID , 0 ) == -1 ) return (1 );
680
691
681
692
#ifdef DEBUG
682
693
fprintf (stderr , "Private Shared Memory id = %x Address = %p\n" , pshmid , paddr );
683
694
#endif
695
+ return (0 );
684
696
}
685
697
686
698
static void local_cpu_map (void ) {
@@ -808,17 +820,23 @@ void gotoblas_affinity_init(void) {
808
820
return ;
809
821
}
810
822
811
- create_pshmem ();
812
-
813
- open_shmem ();
814
-
823
+ if (create_pshmem () != 0 ) {
824
+ disable_mapping = 1 ;
825
+ return ;
826
+ }
827
+
828
+ if (open_shmem () != 0 ) {
829
+ disable_mapping = 1 ;
830
+ return ;
831
+ }
832
+
815
833
while ((common -> lock ) && (common -> magic != SH_MAGIC )) {
816
834
if (is_dead (common -> shmid )) {
817
835
common -> lock = 0 ;
818
836
common -> shmid = 0 ;
819
837
common -> magic = 0 ;
820
838
} else {
821
- sched_yield () ;
839
+ YIELDING ;
822
840
}
823
841
}
824
842
0 commit comments