Skip to content

Commit

Permalink
Switch the default visibility for the main qthreads library to hidden…
Browse files Browse the repository at this point in the history
…. Make sure that API functions are getting properly exported.
  • Loading branch information
insertinterestingnamehere committed Dec 20, 2024
1 parent 8278e86 commit a259b1b
Show file tree
Hide file tree
Showing 19 changed files with 184 additions and 150 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ add_library(qthread SHARED ${QTHREADS_SOURCES})
target_include_directories(qthread
PRIVATE "../include"
)
set_target_properties(qthread PROPERTIES C_VISIBILITY_PRESET hidden)
target_link_libraries(qthread PUBLIC Threads::Threads)
target_include_directories(qthread
PUBLIC
Expand Down
4 changes: 3 additions & 1 deletion src/cacheline.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <stdio.h>
#endif

#include "qt_visibility.h"

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down Expand Up @@ -341,7 +343,7 @@ static void figure_out_cacheline_size(void) { /*{{{ */
} /*}}} */

/* returns the cache line size */
int qthread_cacheline(void) { /*{{{ */
int API_FUNC qthread_cacheline(void) { /*{{{ */
if (cacheline_bytes == 0) {
figure_out_cacheline_size();
if (cacheline_bytes == 0) { /* to cache errors in cacheline detection */
Expand Down
37 changes: 21 additions & 16 deletions src/ds/dictionary/dictionary_shavit.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,13 @@ qt_hash_put(qt_hash h, qt_key_t key, void *value, int put_choice) {
return ret->value;
}

void *qt_dictionary_put(qt_dictionary *dict, void *key, void *value) {
void *API_FUNC qt_dictionary_put(qt_dictionary *dict, void *key, void *value) {
return qt_hash_put(dict, key, value, PUT_ALWAYS);
}

void *qt_dictionary_put_if_absent(qt_dictionary *dict, void *key, void *value) {
void *API_FUNC qt_dictionary_put_if_absent(qt_dictionary *dict,
void *key,
void *value) {
return qt_hash_put(dict, key, value, PUT_IF_ABSENT);
}

Expand All @@ -366,7 +368,7 @@ static inline void *qt_hash_get(qt_hash h, qt_key_t const key) {
&(h->B[bucket]), so_regularkey(lkey), key, NULL, NULL, NULL, h->op_equals);
}

void *qt_dictionary_get(qt_dictionary *dict, void *key) {
void *API_FUNC qt_dictionary_get(qt_dictionary *dict, void *key) {
return qt_hash_get(dict, key);
}

Expand All @@ -390,7 +392,7 @@ static inline int qt_hash_remove(qt_hash h, qt_key_t const key) {
return 1;
}

void *qt_dictionary_delete(qt_dictionary *dict, void *key) {
void *API_FUNC qt_dictionary_delete(qt_dictionary *dict, void *key) {
void *val = qt_hash_get(dict, key); // TODO : this is inefficient!
int ret = qt_hash_remove(dict, key);

Expand Down Expand Up @@ -470,9 +472,9 @@ static inline qt_hash qt_hash_create(qt_dict_key_equals_f eq,
return tmp;
}

qt_dictionary *qt_dictionary_create(qt_dict_key_equals_f eq,
qt_dict_hash_f hash,
qt_dict_cleanup_f cleanup) {
qt_dictionary *API_FUNC qt_dictionary_create(qt_dict_key_equals_f eq,
qt_dict_hash_f hash,
qt_dict_cleanup_f cleanup) {
return qt_hash_create(eq, hash, cleanup);
}

Expand All @@ -497,7 +499,7 @@ static inline void qt_hash_destroy(qt_hash h) {
FREE(h, sizeof(qt_hash));
}

void qt_dictionary_destroy(qt_dictionary *d) { qt_hash_destroy(d); }
void API_FUNC qt_dictionary_destroy(qt_dictionary *d) { qt_hash_destroy(d); }

/*
* void qt_hash_destroy_deallocate(qt_hash h,
Expand Down Expand Up @@ -555,7 +557,8 @@ struct qt_dictionary_iterator {
int bkt; // = -1 if iterator is newly created; =1 otherwise.
};

qt_dictionary_iterator *qt_dictionary_iterator_create(qt_dictionary *dict) {
qt_dictionary_iterator *API_FUNC
qt_dictionary_iterator_create(qt_dictionary *dict) {
if (dict == NULL) { return ERROR; }
qt_dictionary_iterator *it =
(qt_dictionary_iterator *)MALLOC(sizeof(qt_dictionary_iterator));
Expand All @@ -565,7 +568,7 @@ qt_dictionary_iterator *qt_dictionary_iterator_create(qt_dictionary *dict) {
return it;
}

void qt_dictionary_iterator_destroy(qt_dictionary_iterator *it) {
void API_FUNC qt_dictionary_iterator_destroy(qt_dictionary_iterator *it) {
if (it == NULL) { return; }
FREE(it, sizeof(qt_dictionary_iterator));
}
Expand All @@ -592,7 +595,7 @@ qt_dictionary_iterator_next_element(qt_dictionary_iterator *it) {
return it->crt;
}

list_entry *qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
list_entry *API_FUNC qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
list_entry *ret = qt_dictionary_iterator_next_element(it);

while (ret != ERROR && ret != NULL && ret->key == NULL) {
Expand All @@ -601,27 +604,29 @@ list_entry *qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
return ret;
}

list_entry *qt_dictionary_iterator_get(qt_dictionary_iterator const *it) {
list_entry *API_FUNC
qt_dictionary_iterator_get(qt_dictionary_iterator const *it) {
if ((it == NULL) || (it->dict == NULL)) { return ERROR; }
qt_dictionary *h = it->dict;
if ((h->count == 0) || (it->crt == UNINITIALIZED)) { return NULL; }
return it->crt;
}

qt_dictionary_iterator *qt_dictionary_end(qt_dictionary *dict) {
qt_dictionary_iterator *API_FUNC qt_dictionary_end(qt_dictionary *dict) {
qt_dictionary_iterator *ret = qt_dictionary_iterator_create(dict);

ret->bkt = 1;
return ret;
}

int qt_dictionary_iterator_equals(qt_dictionary_iterator *a,
qt_dictionary_iterator *b) {
int API_FUNC qt_dictionary_iterator_equals(qt_dictionary_iterator *a,
qt_dictionary_iterator *b) {
if ((a == NULL) || (b == NULL)) { return a == b; }
return (a->crt == b->crt) && (a->dict == b->dict) && (a->bkt == b->bkt);
}

qt_dictionary_iterator *qt_dictionary_iterator_copy(qt_dictionary_iterator *b) {
qt_dictionary_iterator *API_FUNC
qt_dictionary_iterator_copy(qt_dictionary_iterator *b) {
if (b == NULL) { return NULL; }
qt_dictionary_iterator *ret = qt_dictionary_iterator_create(b->dict);
if ((ret == NULL) || (ret == ERROR)) { return NULL; }
Expand Down
37 changes: 21 additions & 16 deletions src/ds/dictionary/dictionary_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ static int qthread_library_initialized = 1;
extern int qthread_library_initialized;
#endif

qt_dictionary *qt_dictionary_create(qt_dict_key_equals_f eq,
qt_dict_hash_f hash,
qt_dict_cleanup_f cleanup) {
qt_dictionary *API_FUNC qt_dictionary_create(qt_dict_key_equals_f eq,
qt_dict_hash_f hash,
qt_dict_cleanup_f cleanup) {
assert(qthread_library_initialized &&
"Need to initialize qthreads before using the dictionary");
qt_dictionary *ret = (qt_dictionary *)MALLOC(sizeof(qt_dictionary));
Expand All @@ -120,7 +120,7 @@ qt_dictionary *qt_dictionary_create(qt_dict_key_equals_f eq,
return ret;
}

void qt_dictionary_destroy(qt_dictionary *d) {
void API_FUNC qt_dictionary_destroy(qt_dictionary *d) {
int i;

for (i = 0; i < NO_BUCKETS; i++) {
Expand Down Expand Up @@ -256,15 +256,17 @@ void *qt_dictionary_put_helper(qt_dictionary *dict,
}
#endif /* ifdef DICTIONARY_ADD_TO_HEAD */

void *qt_dictionary_put(qt_dictionary *dict, void *key, void *value) {
void *API_FUNC qt_dictionary_put(qt_dictionary *dict, void *key, void *value) {
return qt_dictionary_put_helper(dict, key, value, PUT_ALWAYS);
}

void *qt_dictionary_put_if_absent(qt_dictionary *dict, void *key, void *value) {
void *API_FUNC qt_dictionary_put_if_absent(qt_dictionary *dict,
void *key,
void *value) {
return qt_dictionary_put_helper(dict, key, value, PUT_IF_ABSENT);
}

void *qt_dictionary_get(qt_dictionary *dict, void *key) {
void *API_FUNC qt_dictionary_get(qt_dictionary *dict, void *key) {
int hash = dict->op_hash(key);
int bucket = GET_BUCKET(hash);

Expand All @@ -283,7 +285,7 @@ void *qt_dictionary_get(qt_dictionary *dict, void *key) {
return NULL;
}

void *qt_dictionary_delete(qt_dictionary *dict, void *key) {
void *API_FUNC qt_dictionary_delete(qt_dictionary *dict, void *key) {
void *to_ret = NULL;
list_entry *to_free = NULL;
int hash = dict->op_hash(key);
Expand Down Expand Up @@ -340,7 +342,8 @@ void *qt_dictionary_delete(qt_dictionary *dict, void *key) {
return to_ret;
}

qt_dictionary_iterator *qt_dictionary_iterator_create(qt_dictionary *dict) {
qt_dictionary_iterator *API_FUNC
qt_dictionary_iterator_create(qt_dictionary *dict) {
if ((dict == NULL) || (dict->content == NULL)) { return ERROR; }
qt_dictionary_iterator *it =
(qt_dictionary_iterator *)MALLOC(sizeof(qt_dictionary_iterator));
Expand All @@ -353,12 +356,12 @@ qt_dictionary_iterator *qt_dictionary_iterator_create(qt_dictionary *dict) {
return it;
}

void qt_dictionary_iterator_destroy(qt_dictionary_iterator *it) {
void API_FUNC qt_dictionary_iterator_destroy(qt_dictionary_iterator *it) {
if (it == NULL) { return; }
FREE(it, sizeof(qt_dictionary_iterator));
}

list_entry *qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
list_entry *API_FUNC qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
if ((it == NULL) || (it->dict == NULL) || (it->dict->content == NULL)) {
return ERROR;
}
Expand Down Expand Up @@ -400,7 +403,8 @@ list_entry *qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
return NULL;
}

list_entry *qt_dictionary_iterator_get(qt_dictionary_iterator const *it) {
list_entry *API_FUNC
qt_dictionary_iterator_get(qt_dictionary_iterator const *it) {
if ((it == NULL) || (it->dict == NULL) || (it->dict->content == NULL)) {
printf(" Inside dictionary get, found NULL, will return ERROR\n");
return ERROR;
Expand All @@ -409,7 +413,7 @@ list_entry *qt_dictionary_iterator_get(qt_dictionary_iterator const *it) {
return it->crt;
}

qt_dictionary_iterator *qt_dictionary_end(qt_dictionary *dict) {
qt_dictionary_iterator *API_FUNC qt_dictionary_end(qt_dictionary *dict) {
if ((dict == NULL) || (dict->content == NULL)) { return NULL; }
qt_dictionary_iterator *it = qt_dictionary_iterator_create(dict);
it->crt = NULL;
Expand All @@ -418,13 +422,14 @@ qt_dictionary_iterator *qt_dictionary_end(qt_dictionary *dict) {
return it;
}

int qt_dictionary_iterator_equals(qt_dictionary_iterator *a,
qt_dictionary_iterator *b) {
int API_FUNC qt_dictionary_iterator_equals(qt_dictionary_iterator *a,
qt_dictionary_iterator *b) {
if ((a == NULL) || (b == NULL)) { return a == b; }
return (a->crt == b->crt) && (a->dict == b->dict) && (a->bkt == b->bkt);
}

qt_dictionary_iterator *qt_dictionary_iterator_copy(qt_dictionary_iterator *b) {
qt_dictionary_iterator *API_FUNC
qt_dictionary_iterator_copy(qt_dictionary_iterator *b) {
if (b == NULL) { return NULL; }
qt_dictionary_iterator *ret = qt_dictionary_iterator_create(b->dict);
if ((ret == NULL) || (ret == ERROR)) { return NULL; }
Expand Down
41 changes: 23 additions & 18 deletions src/ds/dictionary/dictionary_trie.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ static inline qt_hash qt_hash_create(qt_dict_key_equals_f eq,
return tmp;
}

qt_dictionary *qt_dictionary_create(qt_dict_key_equals_f eq,
qt_dict_hash_f hash,
qt_dict_cleanup_f cleanup) {
qt_dictionary *API_FUNC qt_dictionary_create(qt_dict_key_equals_f eq,
qt_dict_hash_f hash,
qt_dict_cleanup_f cleanup) {
return qt_hash_create(eq, hash, cleanup);
}

Expand Down Expand Up @@ -227,7 +227,7 @@ static void destroy_element(hash_entry *element, qt_dict_cleanup_f f) {
FREE(element, sizeof(hash_entry));
}

void qt_dictionary_destroy(qt_hash h) {
void API_FUNC qt_dictionary_destroy(qt_hash h) {
assert(h);
assert(h->spines);
for (size_t i = 0; i < BASE_SPINE_LENGTH; ++i) {
Expand Down Expand Up @@ -401,17 +401,19 @@ void *qt_hash_put_helper(qt_dictionary *h,
} while (1);
}

void *qt_dictionary_put(qt_dictionary *dict, void *key, void *value) {
void *API_FUNC qt_dictionary_put(qt_dictionary *dict, void *key, void *value) {
return qt_hash_put_helper(dict, key, value, PUT_ALWAYS);
}

void *qt_dictionary_put_if_absent(qt_dictionary *dict, void *key, void *value) {
void *API_FUNC qt_dictionary_put_if_absent(qt_dictionary *dict,
void *key,
void *value) {
return qt_hash_put_helper(dict, key, value, PUT_IF_ABSENT);
}

int qt_dictionary_remove(qt_dictionary *h, qt_key_t const key);
int API_FUNC qt_dictionary_remove(qt_dictionary *h, qt_key_t const key);

int qt_dictionary_remove(qt_dictionary *h, qt_key_t const key) {
int API_FUNC qt_dictionary_remove(qt_dictionary *h, qt_key_t const key) {
uint64_t lkey = (uint64_t)(uintptr_t)(h->op_hash(key));

HASH_KEY(lkey);
Expand Down Expand Up @@ -493,7 +495,7 @@ int qt_dictionary_remove(qt_dictionary *h, qt_key_t const key) {
} while (1);
}

void *qt_dictionary_delete(qt_dictionary *dict, void *key) {
void *API_FUNC qt_dictionary_delete(qt_dictionary *dict, void *key) {
void *val = qt_dictionary_get(dict, key); // TODO : this is inefficient!
int ret = qt_dictionary_remove(dict, key);

Expand All @@ -504,7 +506,7 @@ void *qt_dictionary_delete(qt_dictionary *dict, void *key) {
}
}

void *qt_dictionary_get(qt_dictionary *h, qt_key_t const key) {
void *API_FUNC qt_dictionary_get(qt_dictionary *h, qt_key_t const key) {
uint64_t lkey = (uint64_t)(uintptr_t)(h->op_hash(key));

HASH_KEY(lkey);
Expand Down Expand Up @@ -612,7 +614,8 @@ struct qt_dictionary_iterator {
int base_index;
};

qt_dictionary_iterator *qt_dictionary_iterator_create(qt_dictionary *dict) {
qt_dictionary_iterator *API_FUNC
qt_dictionary_iterator_create(qt_dictionary *dict) {
if (dict == NULL) { return ERROR; }
qt_dictionary_iterator *it =
(qt_dictionary_iterator *)MALLOC(sizeof(qt_dictionary_iterator));
Expand All @@ -624,12 +627,12 @@ qt_dictionary_iterator *qt_dictionary_iterator_create(qt_dictionary *dict) {
return it;
}

void qt_dictionary_iterator_destroy(qt_dictionary_iterator *it) {
void API_FUNC qt_dictionary_iterator_destroy(qt_dictionary_iterator *it) {
if (it == NULL) { return; }
FREE(it, sizeof(qt_dictionary_iterator));
}

list_entry *qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
list_entry *API_FUNC qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
if ((it == NULL) || (it->dict == NULL)) { return ERROR; }

if ((it->crt != NULL) && (it->crt->next != NULL)) {
Expand Down Expand Up @@ -671,25 +674,27 @@ list_entry *qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
return NULL;
}

list_entry *qt_dictionary_iterator_get(qt_dictionary_iterator const *it) {
list_entry *API_FUNC
qt_dictionary_iterator_get(qt_dictionary_iterator const *it) {
if ((it == NULL) || (it->dict == NULL)) { return ERROR; }
return it->crt;
}

qt_dictionary_iterator *qt_dictionary_end(qt_dictionary *dict) {
qt_dictionary_iterator *API_FUNC qt_dictionary_end(qt_dictionary *dict) {
qt_dictionary_iterator *ret = qt_dictionary_iterator_create(dict);

ret->bkt = ret->dict->maxspines;
return ret;
}

int qt_dictionary_iterator_equals(qt_dictionary_iterator *a,
qt_dictionary_iterator *b) {
int API_FUNC qt_dictionary_iterator_equals(qt_dictionary_iterator *a,
qt_dictionary_iterator *b) {
if ((a == NULL) || (b == NULL)) { return a == b; }
return (a->crt == b->crt) && (a->dict == b->dict) && (a->bkt == b->bkt);
}

qt_dictionary_iterator *qt_dictionary_iterator_copy(qt_dictionary_iterator *b) {
qt_dictionary_iterator *API_FUNC
qt_dictionary_iterator_copy(qt_dictionary_iterator *b) {
if (b == NULL) { return NULL; }
qt_dictionary_iterator *ret = qt_dictionary_iterator_create(b->dict);
if ((ret == NULL) || (ret == ERROR)) { return NULL; }
Expand Down
Loading

0 comments on commit a259b1b

Please sign in to comment.