Skip to content

Commit

Permalink
[runtime] C++ compliance fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tritao committed Apr 16, 2015
1 parent c6e9591 commit 030a43a
Show file tree
Hide file tree
Showing 24 changed files with 112 additions and 94 deletions.
6 changes: 3 additions & 3 deletions mono/metadata/mempool-internals.h
Expand Up @@ -11,7 +11,7 @@ g_list_prepend_mempool (MonoMemPool *mp, GList *list, gpointer data)
{
GList *new_list;

new_list = mono_mempool_alloc (mp, sizeof (GList));
new_list = (GList *) mono_mempool_alloc (mp, sizeof (GList));
new_list->data = data;
new_list->prev = list ? list->prev : NULL;
new_list->next = list;
Expand All @@ -29,7 +29,7 @@ g_slist_prepend_mempool (MonoMemPool *mp, GSList *list, gpointer data)
{
GSList *new_list;

new_list = mono_mempool_alloc (mp, sizeof (GSList));
new_list = (GSList *) mono_mempool_alloc (mp, sizeof (GSList));
new_list->data = data;
new_list->next = list;

Expand All @@ -42,7 +42,7 @@ g_slist_append_mempool (MonoMemPool *mp, GSList *list, gpointer data)
GSList *new_list;
GSList *last;

new_list = mono_mempool_alloc (mp, sizeof (GSList));
new_list = (GSList *) mono_mempool_alloc (mp, sizeof (GSList));
new_list->data = data;
new_list->next = NULL;

Expand Down
2 changes: 1 addition & 1 deletion mono/utils/hazard-pointer.c
Expand Up @@ -101,7 +101,7 @@ mono_thread_small_id_alloc (void)
int num_pages = (hazard_table_size * sizeof (MonoThreadHazardPointers) + pagesize - 1) / pagesize;

if (hazard_table == NULL) {
hazard_table = mono_valloc (NULL,
hazard_table = (MonoThreadHazardPointers *volatile) mono_valloc (NULL,
sizeof (MonoThreadHazardPointers) * HAZARD_TABLE_MAX_SIZE,
MONO_MMAP_NONE);
}
Expand Down
19 changes: 12 additions & 7 deletions mono/utils/lock-free-alloc.c
Expand Up @@ -182,7 +182,7 @@ desc_alloc (void)
for (;;) {
gboolean success;

desc = get_hazardous_pointer ((gpointer * volatile)&desc_avail, hp, 1);
desc = (Descriptor *) get_hazardous_pointer ((gpointer * volatile)&desc_avail, hp, 1);
if (desc) {
Descriptor *next = desc->next;
success = (InterlockedCompareExchangePointer ((gpointer * volatile)&desc_avail, next, desc) == desc);
Expand All @@ -191,7 +191,7 @@ desc_alloc (void)
Descriptor *d;
int i;

desc = mono_valloc (0, desc_size * NUM_DESC_BATCH, prot_flags_for_activate (TRUE));
desc = (Descriptor *) mono_valloc (0, desc_size * NUM_DESC_BATCH, prot_flags_for_activate (TRUE));

/* Organize into linked list. */
d = desc;
Expand Down Expand Up @@ -225,7 +225,7 @@ desc_alloc (void)
static void
desc_enqueue_avail (gpointer _desc)
{
Descriptor *desc = _desc;
Descriptor *desc = (Descriptor *) _desc;
Descriptor *old_head;

g_assert (desc->anchor.data.state == STATE_EMPTY);
Expand Down Expand Up @@ -285,7 +285,7 @@ list_get_partial (MonoLockFreeAllocSizeClass *sc)
static void
desc_put_partial (gpointer _desc)
{
Descriptor *desc = _desc;
Descriptor *desc = (Descriptor *) _desc;

g_assert (desc->anchor.data.state != STATE_FULL);

Expand Down Expand Up @@ -366,8 +366,10 @@ alloc_from_active_or_partial (MonoLockFreeAllocator *heap)

do {
unsigned int next;

new_anchor = old_anchor = *(volatile Anchor*)&desc->anchor.value;
volatile Anchor* value;
value = (volatile Anchor*)&desc->anchor.value;
old_anchor = *(Anchor*)&value;
new_anchor = old_anchor;
if (old_anchor.data.state == STATE_EMPTY) {
/* We must free it because we own it. */
desc_retire (desc);
Expand Down Expand Up @@ -472,7 +474,10 @@ mono_lock_free_free (gpointer ptr, size_t block_size)
sb = desc->sb;

do {
new_anchor = old_anchor = *(volatile Anchor*)&desc->anchor.value;
volatile Anchor* value;
value = (volatile Anchor*)&desc->anchor.value;
old_anchor = *(Anchor*)&value;
new_anchor = old_anchor;
*(unsigned int*)ptr = old_anchor.data.avail;
new_anchor.data.avail = ((char*)ptr - (char*)sb) / desc->slot_size;
g_assert (new_anchor.data.avail < LOCK_FREE_ALLOC_SB_USABLE_SIZE (block_size) / desc->slot_size);
Expand Down
6 changes: 3 additions & 3 deletions mono/utils/lock-free-array-queue.c
Expand Up @@ -37,7 +37,7 @@ alloc_chunk (MonoLockFreeArray *arr)
{
int size = mono_pagesize ();
int num_entries = (size - (sizeof (Chunk) - arr->entry_size * MONO_ZERO_LEN_ARRAY)) / arr->entry_size;
Chunk *chunk = mono_valloc (0, size, MONO_MMAP_READ | MONO_MMAP_WRITE);
Chunk *chunk = (Chunk *) mono_valloc (0, size, MONO_MMAP_READ | MONO_MMAP_WRITE);
g_assert (chunk);
chunk->num_entries = num_entries;
return chunk;
Expand Down Expand Up @@ -137,7 +137,7 @@ mono_lock_free_array_queue_push (MonoLockFreeArrayQueue *q, gpointer entry_data_

do {
index = InterlockedIncrement (&q->num_used_entries) - 1;
entry = mono_lock_free_array_nth (&q->array, index);
entry = (Entry *) mono_lock_free_array_nth (&q->array, index);
} while (InterlockedCompareExchange (&entry->state, STATE_BUSY, STATE_FREE) != STATE_FREE);

mono_memory_write_barrier ();
Expand Down Expand Up @@ -172,7 +172,7 @@ mono_lock_free_array_queue_pop (MonoLockFreeArrayQueue *q, gpointer entry_data_p
return FALSE;
} while (InterlockedCompareExchange (&q->num_used_entries, index - 1, index) != index);

entry = mono_lock_free_array_nth (&q->array, index - 1);
entry = (Entry *) mono_lock_free_array_nth (&q->array, index - 1);
} while (InterlockedCompareExchange (&entry->state, STATE_BUSY, STATE_USED) != STATE_USED);

/* Reading the item must happen before CASing the state. */
Expand Down
12 changes: 6 additions & 6 deletions mono/utils/lock-free-queue.c
Expand Up @@ -57,9 +57,9 @@

#include <mono/utils/lock-free-queue.h>

#define INVALID_NEXT ((void*)-1)
#define END_MARKER ((void*)-2)
#define FREE_NEXT ((void*)-3)
#define INVALID_NEXT ((MonoLockFreeQueueNode *volatile)-1)
#define END_MARKER ((MonoLockFreeQueueNode *volatile)-2)
#define FREE_NEXT ((MonoLockFreeQueueNode *volatile)-3)

void
mono_lock_free_queue_init (MonoLockFreeQueue *q)
Expand Down Expand Up @@ -113,7 +113,7 @@ mono_lock_free_queue_enqueue (MonoLockFreeQueue *q, MonoLockFreeQueueNode *node)
for (;;) {
MonoLockFreeQueueNode *next;

tail = get_hazardous_pointer ((gpointer volatile*)&q->tail, hp, 0);
tail = (MonoLockFreeQueueNode *) get_hazardous_pointer ((gpointer volatile*)&q->tail, hp, 0);
mono_memory_read_barrier ();
/*
* We never dereference next so we don't need a
Expand Down Expand Up @@ -157,7 +157,7 @@ mono_lock_free_queue_enqueue (MonoLockFreeQueue *q, MonoLockFreeQueueNode *node)
static void
free_dummy (gpointer _dummy)
{
MonoLockFreeQueueDummy *dummy = _dummy;
MonoLockFreeQueueDummy *dummy = (MonoLockFreeQueueDummy *) _dummy;
mono_lock_free_queue_node_free (&dummy->node);
g_assert (dummy->in_use);
mono_memory_write_barrier ();
Expand Down Expand Up @@ -218,7 +218,7 @@ mono_lock_free_queue_dequeue (MonoLockFreeQueue *q)
for (;;) {
MonoLockFreeQueueNode *tail, *next;

head = get_hazardous_pointer ((gpointer volatile*)&q->head, hp, 0);
head = (MonoLockFreeQueueNode *) get_hazardous_pointer ((gpointer volatile*)&q->head, hp, 0);
tail = (MonoLockFreeQueueNode*)q->tail;
mono_memory_read_barrier ();
next = head->next;
Expand Down
12 changes: 6 additions & 6 deletions mono/utils/mono-codeman.c
Expand Up @@ -252,7 +252,7 @@ codechunk_valloc (void *preferred, guint32 size)
* Keep a small freelist of memory blocks to decrease pressure on the kernel memory subsystem to avoid #3321.
*/
mono_mutex_lock (&valloc_mutex);
freelist = g_hash_table_lookup (valloc_freelists, GUINT_TO_POINTER (size));
freelist = (GSList *) g_hash_table_lookup (valloc_freelists, GUINT_TO_POINTER (size));
if (freelist) {
ptr = freelist->data;
memset (ptr, 0, size);
Expand All @@ -273,7 +273,7 @@ codechunk_vfree (void *ptr, guint32 size)
GSList *freelist;

mono_mutex_lock (&valloc_mutex);
freelist = g_hash_table_lookup (valloc_freelists, GUINT_TO_POINTER (size));
freelist = (GSList *) g_hash_table_lookup (valloc_freelists, GUINT_TO_POINTER (size));
if (!freelist || g_slist_length (freelist) < VALLOC_FREELIST_SIZE) {
freelist = g_slist_prepend (freelist, ptr);
g_hash_table_insert (valloc_freelists, GUINT_TO_POINTER (size), freelist);
Expand All @@ -293,7 +293,7 @@ codechunk_cleanup (void)
return;
g_hash_table_iter_init (&iter, valloc_freelists);
while (g_hash_table_iter_next (&iter, &key, &value)) {
GSList *freelist = value;
GSList *freelist = (GSList *) value;
GSList *l;

for (l = freelist; l; l = l->next) {
Expand Down Expand Up @@ -332,7 +332,7 @@ mono_code_manager_cleanup (void)
MonoCodeManager*
mono_code_manager_new (void)
{
MonoCodeManager *cman = g_malloc0 (sizeof (MonoCodeManager));
MonoCodeManager *cman = (MonoCodeManager *) g_malloc0 (sizeof (MonoCodeManager));
if (!cman)
return NULL;
#if defined(__native_client_codegen__) && defined(__native_client__)
Expand Down Expand Up @@ -577,7 +577,7 @@ new_codechunk (CodeChunk *last, int dynamic, int size, int bind_size)
#endif
}

chunk = malloc (sizeof (CodeChunk));
chunk = (CodeChunk *) malloc (sizeof (CodeChunk));
if (!chunk) {
if (flags == CODE_FLAG_MALLOC)
dlfree (ptr);
Expand All @@ -587,7 +587,7 @@ new_codechunk (CodeChunk *last, int dynamic, int size, int bind_size)
}
chunk->next = NULL;
chunk->size = chunk_size;
chunk->data = ptr;
chunk->data = (char *) ptr;
chunk->flags = flags;
chunk->pos = bsize;
chunk->bsize = bsize;
Expand Down
26 changes: 13 additions & 13 deletions mono/utils/mono-counters.c
Expand Up @@ -165,7 +165,7 @@ register_internal (const char *name, int type, void *addr, int size)
}
}

counter = malloc (sizeof (MonoCounter));
counter = (MonoCounter *) malloc (sizeof (MonoCounter));
if (!counter) {
mono_mutex_unlock (&counters_mutex);
return;
Expand Down Expand Up @@ -292,7 +292,7 @@ mono_counters_on_register (MonoCounterRegisterCallback callback)
}

mono_mutex_lock (&counters_mutex);
register_callbacks = g_slist_append (register_callbacks, callback);
register_callbacks = g_slist_append (register_callbacks, (gpointer) callback);
mono_mutex_unlock (&counters_mutex);
}

Expand Down Expand Up @@ -406,16 +406,16 @@ cpu_load_15min (void)
static void
initialize_system_counters (void)
{
register_internal ("User Time", SYSCOUNTER_TIME, &user_time, sizeof (gint64));
register_internal ("System Time", SYSCOUNTER_TIME, &system_time, sizeof (gint64));
register_internal ("Total Time", SYSCOUNTER_TIME, &total_time, sizeof (gint64));
register_internal ("Working Set", SYSCOUNTER_BYTES, &working_set, sizeof (gint64));
register_internal ("Private Bytes", SYSCOUNTER_BYTES, &private_bytes, sizeof (gint64));
register_internal ("Virtual Bytes", SYSCOUNTER_BYTES, &virtual_bytes, sizeof (gint64));
register_internal ("Page Faults", SYSCOUNTER_COUNT, &page_faults, sizeof (gint64));
register_internal ("CPU Load Average - 1min", SYSCOUNTER_LOAD, &cpu_load_1min, sizeof (double));
register_internal ("CPU Load Average - 5min", SYSCOUNTER_LOAD, &cpu_load_5min, sizeof (double));
register_internal ("CPU Load Average - 15min", SYSCOUNTER_LOAD, &cpu_load_15min, sizeof (double));
register_internal ("User Time", SYSCOUNTER_TIME, (gpointer) &user_time, sizeof (gint64));
register_internal ("System Time", SYSCOUNTER_TIME, (gpointer) &system_time, sizeof (gint64));
register_internal ("Total Time", SYSCOUNTER_TIME, (gpointer) &total_time, sizeof (gint64));
register_internal ("Working Set", SYSCOUNTER_BYTES, (gpointer) &working_set, sizeof (gint64));
register_internal ("Private Bytes", SYSCOUNTER_BYTES, (gpointer) &private_bytes, sizeof (gint64));
register_internal ("Virtual Bytes", SYSCOUNTER_BYTES, (gpointer) &virtual_bytes, sizeof (gint64));
register_internal ("Page Faults", SYSCOUNTER_COUNT, (gpointer) &page_faults, sizeof (gint64));
register_internal ("CPU Load Average - 1min", SYSCOUNTER_LOAD, (gpointer) &cpu_load_1min, sizeof (double));
register_internal ("CPU Load Average - 5min", SYSCOUNTER_LOAD, (gpointer) &cpu_load_5min, sizeof (double));
register_internal ("CPU Load Average - 15min", SYSCOUNTER_LOAD, (gpointer) &cpu_load_15min, sizeof (double));
}

/**
Expand Down Expand Up @@ -497,7 +497,7 @@ sample_internal (MonoCounter *counter, void *buffer, int buffer_size)
size = 0;
} else {
size = counter->size;
strncpy (buffer, strval, size - 1);
strncpy ((char *) buffer, strval, size - 1);
((char*)buffer)[size - 1] = '\0';
}
}
Expand Down
6 changes: 3 additions & 3 deletions mono/utils/mono-dl.c
Expand Up @@ -55,15 +55,15 @@ read_string (char *p, FILE *file)
if (!endp)
return NULL;
*endp = 0;
return g_memdup (startp, (endp - startp) + 1);
return (char *) g_memdup (startp, (endp - startp) + 1);
}
if (*p == 0)
return NULL;
startp = p;
while (*p && !isspace (*p))
++p;
*p = 0;
return g_memdup (startp, (p - startp) + 1);
return (char *) g_memdup (startp, (p - startp) + 1);
}

/*
Expand Down Expand Up @@ -139,7 +139,7 @@ mono_dl_open (const char *name, int flags, char **error_msg)
if (error_msg)
*error_msg = NULL;

module = malloc (sizeof (MonoDl));
module = (MonoDl *) malloc (sizeof (MonoDl));
if (!module) {
if (error_msg)
*error_msg = g_strdup ("Out of memory");
Expand Down
18 changes: 9 additions & 9 deletions mono/utils/mono-linked-list-set.c
Expand Up @@ -94,12 +94,12 @@ mono_lls_find (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, uintptr_t
*/
mono_hazard_pointer_set (hp, 2, prev);

cur = get_hazardous_pointer_with_mask ((gpointer*)prev, hp, 1);
cur = (MonoLinkedListSetNode *) get_hazardous_pointer_with_mask ((gpointer*)prev, hp, 1);

while (1) {
if (cur == NULL)
return FALSE;
next = get_hazardous_pointer_with_mask ((gpointer*)&cur->next, hp, 0);
next = (MonoLinkedListSetNode *) get_hazardous_pointer_with_mask ((gpointer*)&cur->next, hp, 0);
cur_key = cur->key;

/*
Expand All @@ -119,7 +119,7 @@ mono_lls_find (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, uintptr_t
prev = &cur->next;
mono_hazard_pointer_set (hp, 2, cur);
} else {
next = mono_lls_pointer_unmask (next);
next = (MonoLinkedListSetNode *) mono_lls_pointer_unmask (next);
if (InterlockedCompareExchangePointer ((volatile gpointer*)prev, next, cur) == cur) {
/* The hazard pointer must be cleared after the CAS. */
mono_memory_write_barrier ();
Expand All @@ -129,7 +129,7 @@ mono_lls_find (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, uintptr_t
} else
goto try_again;
}
cur = mono_lls_pointer_unmask (next);
cur = (MonoLinkedListSetNode *) mono_lls_pointer_unmask (next);
mono_hazard_pointer_set (hp, 1, cur);
}
}
Expand All @@ -152,8 +152,8 @@ mono_lls_insert (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, MonoLink
while (1) {
if (mono_lls_find (list, hp, value->key))
return FALSE;
cur = mono_hazard_pointer_get_val (hp, 1);
prev = mono_hazard_pointer_get_val (hp, 2);
cur = (MonoLinkedListSetNode *) mono_hazard_pointer_get_val (hp, 1);
prev = (MonoLinkedListSetNode **) mono_hazard_pointer_get_val (hp, 2);

value->next = cur;
mono_hazard_pointer_set (hp, 0, value);
Expand All @@ -178,9 +178,9 @@ mono_lls_remove (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, MonoLink
if (!mono_lls_find (list, hp, value->key))
return FALSE;

next = mono_hazard_pointer_get_val (hp, 0);
cur = mono_hazard_pointer_get_val (hp, 1);
prev = mono_hazard_pointer_get_val (hp, 2);
next = (MonoLinkedListSetNode *) mono_hazard_pointer_get_val (hp, 0);
cur = (MonoLinkedListSetNode *) mono_hazard_pointer_get_val (hp, 1);
prev = (MonoLinkedListSetNode **) mono_hazard_pointer_get_val (hp, 2);

g_assert (cur == value);

Expand Down
14 changes: 7 additions & 7 deletions mono/utils/mono-linked-list-set.h
Expand Up @@ -81,7 +81,7 @@ Requires the world to be stoped
static inline MonoLinkedListSetNode*
mono_lls_info_step (MonoLinkedListSetNode *val, MonoThreadHazardPointers *hp)
{
val = mono_lls_pointer_unmask (val);
val = (MonoLinkedListSetNode *) mono_lls_pointer_unmask (val);
mono_hazard_pointer_set (hp, 1, val);
return val;
}
Expand All @@ -92,20 +92,20 @@ Provides snapshot iteration
#define MONO_LLS_FOREACH_SAFE(list, element, type) {\
MonoThreadHazardPointers *__hp = mono_hazard_pointer_get (); \
MonoLinkedListSetNode *__cur, *__next; \
for (__cur = mono_lls_pointer_unmask (get_hazardous_pointer ((gpointer volatile*)&(list)->head, __hp, 1)); \
for (__cur = (MonoLinkedListSetNode *) mono_lls_pointer_unmask (get_hazardous_pointer ((gpointer volatile*)&(list)->head, __hp, 1)); \
__cur; \
__cur = mono_lls_info_step (__next, __hp)) { \
__next = get_hazardous_pointer_with_mask ((gpointer volatile*)&__cur->next, __hp, 0); \
__cur = (MonoLinkedListSetNode *) mono_lls_info_step (__next, __hp)) { \
__next = (MonoLinkedListSetNode *) get_hazardous_pointer_with_mask ((gpointer volatile*)&__cur->next, __hp, 0); \
if (!mono_lls_pointer_get_mark (__next)) { \
(element) = (type)__cur;

#define MONO_LLS_FOREACH_FILTERED_SAFE(list, element, filter_func, type) {\
MonoThreadHazardPointers *__hp = mono_hazard_pointer_get (); \
MonoLinkedListSetNode *__cur, *__next; \
for (__cur = mono_lls_pointer_unmask (get_hazardous_pointer ((gpointer volatile*)&(list)->head, __hp, 1)); \
for (__cur = (MonoLinkedListSetNode *) mono_lls_pointer_unmask (get_hazardous_pointer ((gpointer volatile*)&(list)->head, __hp, 1)); \
__cur; \
__cur = mono_lls_info_step (__next, __hp)) { \
__next = get_hazardous_pointer_with_mask ((gpointer volatile*)&__cur->next, __hp, 0); \
__cur = (MonoLinkedListSetNode *) mono_lls_info_step (__next, __hp)) { \
__next = (MonoLinkedListSetNode *) get_hazardous_pointer_with_mask ((gpointer volatile*)&__cur->next, __hp, 0); \
if (!mono_lls_pointer_get_mark (__next)) { \
(element) = (type)__cur; \
if (!filter_func (element)) continue;
Expand Down

0 comments on commit 030a43a

Please sign in to comment.