Skip to content

Commit bdc6514

Browse files
authored
Substitute C-style casting with C++ one (#119)
Also, fix some whitespace issues and placement of * around the lines that have been changed.
1 parent f0989b7 commit bdc6514

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

src/backend/mpi/coherence.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ namespace argo {
5151

5252
// If the page is dirty, downgrade it
5353
if(cacheControl[cache_index].dirty == DIRTY) {
54-
mprotect((char*)start_address + page_address, block_size, PROT_READ);
55-
for(int i = 0; i <CACHELINE; i++) {
54+
mprotect(reinterpret_cast<char*>(start_address) + page_address, block_size, PROT_READ);
55+
for(int i = 0; i < CACHELINE; i++) {
5656
storepageDIFF(cache_index+i, page_address+page_size*i);
5757
}
5858
argo_write_buffer->erase(cache_index);
@@ -79,7 +79,7 @@ namespace argo {
7979
cacheControl[cache_index].dirty = CLEAN;
8080
cacheControl[cache_index].state = INVALID;
8181
touchedcache[cache_index] = 0;
82-
mprotect((char*)start_address + page_address, block_size, PROT_NONE);
82+
mprotect(reinterpret_cast<char*>(start_address) + page_address, block_size, PROT_NONE);
8383
}
8484
cache_locks[cache_index].unlock();
8585
}
@@ -129,7 +129,7 @@ namespace argo {
129129

130130
// If the page is dirty, downgrade it
131131
if(cacheControl[cache_index].dirty == DIRTY) {
132-
mprotect((char*)start_address + page_address, block_size, PROT_READ);
132+
mprotect(reinterpret_cast<char*>(start_address) + page_address, block_size, PROT_READ);
133133
for(int i = 0; i <CACHELINE; i++) {
134134
storepageDIFF(cache_index+i, page_address+page_size*i);
135135
}

src/backend/mpi/swdsm.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ void argo_initialize(std::size_t argo_size, std::size_t cache_size) {
754754
printf("maximum virtual memory: %ld GiB\n", vm::size() >> 30);
755755
#endif
756756

757-
threadbarrier = (pthread_barrier_t *) malloc(sizeof(pthread_barrier_t)*(NUM_THREADS+1));
757+
threadbarrier = static_cast<pthread_barrier_t *>(malloc(sizeof(pthread_barrier_t)*(NUM_THREADS+1)));
758758
for(std::size_t i = 1; i <= NUM_THREADS; i++) {
759759
pthread_barrier_init(&threadbarrier[i], NULL, i);
760760
}
@@ -785,11 +785,10 @@ void argo_initialize(std::size_t argo_size, std::size_t cache_size) {
785785
MPI_Comm_create(MPI_COMM_WORLD, workgroup, &workcomm);
786786
MPI_Group_rank(workgroup, reinterpret_cast<int*>(&workrank));
787787

788-
789-
//Allocate local memory for each node,
790-
size_of_all = argo_size; //total distr. global memory
788+
// Allocate local memory for each node
789+
size_of_all = argo_size; // total distr. global memory
791790
GLOBAL_NULL = size_of_all+1;
792-
size_of_chunk = argo_size/(numtasks); //part on each node
791+
size_of_chunk = argo_size/(numtasks); // part on each node
793792
sig::signal_handler<SIGSEGV>::install_argo_handler(&handler);
794793

795794
std::size_t cacheControlSize = sizeof(control_data)*cachesize;
@@ -811,7 +810,7 @@ void argo_initialize(std::size_t argo_size, std::size_t cache_size) {
811810
cacheData = static_cast<char*>(vm::allocate_mappable(pagesize, cachesize*pagesize));
812811
cacheControl = static_cast<control_data*>(vm::allocate_mappable(pagesize, cacheControlSize));
813812

814-
touchedcache = (argo_byte *)malloc(cachesize);
813+
touchedcache = static_cast<argo_byte*>(malloc(cachesize));
815814
if(touchedcache == NULL) {
816815
printf("malloc error out of memory\n");
817816
exit(EXIT_FAILURE);
@@ -958,7 +957,7 @@ void self_invalidation() {
958957
std::uint64_t id = static_cast<std::uint64_t>(1) << getID();
959958

960959
double t1 = MPI_Wtime();
961-
for(std::size_t i = 0; i < cachesize; i+=CACHELINE) {
960+
for(std::size_t i = 0; i < cachesize; i += CACHELINE) {
962961
if(touchedcache[i] != 0) {
963962
std::uintptr_t distrAddr = cacheControl[i].tag;
964963
std::uintptr_t lineAddr = distrAddr/(CACHELINE*pagesize);
@@ -987,7 +986,7 @@ void self_invalidation() {
987986
cacheControl[i].dirty = CLEAN;
988987
cacheControl[i].state = INVALID;
989988
touchedcache[i] = 0;
990-
mprotect((char*)startAddr + lineAddr, pagesize*CACHELINE, PROT_NONE);
989+
mprotect(static_cast<char*>(startAddr) + lineAddr, pagesize*CACHELINE, PROT_NONE);
991990
}
992991
}
993992
}
@@ -1000,7 +999,7 @@ void self_upgrade(upgrade_type upgrade) {
1000999
upgrade == upgrade_type::upgrade_all);
10011000
const std::uint64_t node_id_bit = static_cast<std::uint64_t>(1) << getID();
10021001

1003-
for(std::size_t i = 0; i < classificationSize; i+=2) {
1002+
for(std::size_t i = 0; i < classificationSize; i += 2) {
10041003
std::size_t page_index = i/2;
10051004
std::uintptr_t page_addr = page_index*pagesize*CACHELINE;
10061005
void* global_addr = static_cast<char*>(startAddr) + page_addr;
@@ -1190,8 +1189,8 @@ void storepageDIFF(std::size_t index, std::uintptr_t addr) {
11901189
const std::size_t win_index = get_data_win_index(offset);
11911190
const std::size_t win_offset = get_data_win_offset(offset);
11921191

1193-
char * copy = (char *)(pagecopy + index*pagesize);
1194-
char * real = (char *)startAddr+addr;
1192+
char* copy = static_cast<char*>(pagecopy + index*pagesize);
1193+
char* real = static_cast<char*>(startAddr)+addr;
11951194
size_t drf_unit = sizeof(char);
11961195

11971196
mpi_lock_data[win_index][homenode].lock(MPI_LOCK_EXCLUSIVE, homenode, data_windows[win_index][homenode]);
@@ -1206,7 +1205,7 @@ void storepageDIFF(std::size_t index, std::uintptr_t addr) {
12061205
}
12071206
}
12081207
if(branchval != 0) {
1209-
cnt+=drf_unit;
1208+
cnt += drf_unit;
12101209
} else {
12111210
if(cnt > 0) {
12121211
MPI_Put(&real[i-cnt], cnt, MPI_BYTE, homenode, win_offset+(i-cnt), cnt, MPI_BYTE, data_windows[win_index][homenode]);

0 commit comments

Comments
 (0)