Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code style #103

Merged
merged 5 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/containers/qlisttbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ size_t qlisttbl_remove(qlisttbl_t *tbl, const char *name)
qlisttbl_obj_t obj;
memset((void*)&obj, 0, sizeof(obj)); // must be cleared before call
qlisttbl_lock(tbl);
while(qlisttbl_getnext(tbl, &obj, name, false) == true) {
while (qlisttbl_getnext(tbl, &obj, name, false) == true) {
qlisttbl_removeobj(tbl, &obj);
numremoved++;
}
Expand Down
8 changes: 4 additions & 4 deletions src/containers/qvector.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ qvector_t *qvector(size_t max, size_t objsize, int options) {
vector->objsize = objsize;
} else {
void *data = malloc(max * objsize);
if(data == NULL) {
if (data == NULL) {
free(vector);
errno = ENOMEM;
return NULL;
Expand All @@ -148,7 +148,7 @@ qvector_t *qvector(size_t max, size_t objsize, int options) {
//handle options
if (options & QVECTOR_THREADSAFE) {
Q_MUTEX_NEW(vector->qmutex, true);
if(vector->qmutex == NULL) {
if (vector->qmutex == NULL) {
free(vector);
errno = ENOMEM;
return NULL;
Expand Down Expand Up @@ -322,7 +322,7 @@ bool qvector_addat(qvector_t *vector, int index, const void *data) {
newmax = vector->max + 1;
}
bool result = vector->resize(vector, newmax);
if(result == false)
if (result == false)
{
vector->unlock(vector);
errno = ENOMEM;
Expand Down Expand Up @@ -687,7 +687,7 @@ void qvector_free(qvector_t *vector) {
vector->clear(vector);
Q_MUTEX_DESTROY(vector->qmutex);

if(vector->data != NULL) {
if (vector->data != NULL) {
free(vector->data);
}

Expand Down
32 changes: 16 additions & 16 deletions src/internal/qinternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@

#define DYNAMIC_VSPRINTF(s, f) do { \
size_t _strsize; \
for(_strsize = 1024; ; _strsize *= 2) { \
for (_strsize = 1024; ; _strsize *= 2) { \
s = (char*)malloc(_strsize); \
if(s == NULL) { \
if (s == NULL) { \
DEBUG("DYNAMIC_VSPRINTF(): can't allocate memory."); \
break; \
} \
va_list _arglist; \
va_start(_arglist, f); \
int _n = vsnprintf(s, _strsize, f, _arglist); \
va_end(_arglist); \
if(_n >= 0 && _n < _strsize) break; \
if (_n >= 0 && _n < _strsize) break; \
free(s); \
} \
} while(0)
Expand All @@ -76,12 +76,12 @@ struct qmutex_s {
qmutex_t *x = (qmutex_t *)calloc(1, sizeof(qmutex_t)); \
pthread_mutexattr_t _mutexattr; \
pthread_mutexattr_init(&_mutexattr); \
if(r == true) { \
if (r == true) { \
pthread_mutexattr_settype(&_mutexattr, PTHREAD_MUTEX_RECURSIVE); \
} \
int _ret = pthread_mutex_init(&(x->mutex), &_mutexattr); \
pthread_mutexattr_destroy(&_mutexattr); \
if(_ret == 0) { \
if (_ret == 0) { \
m = x; \
} else { \
DEBUG("Q_MUTEX: can't initialize mutex. [%d]", _ret); \
Expand All @@ -91,27 +91,27 @@ struct qmutex_s {
} while(0)

#define Q_MUTEX_LEAVE(m) do { \
if(m == NULL) break; \
if(!pthread_equal(((qmutex_t *)m)->owner, pthread_self())) { \
if (m == NULL) break; \
if (!pthread_equal(((qmutex_t *)m)->owner, pthread_self())) { \
DEBUG("Q_MUTEX: unlock - owner mismatch."); \
} \
if((((qmutex_t *)m)->count--) < 0) ((qmutex_t *)m)->count = 0; \
if ((((qmutex_t *)m)->count--) < 0) ((qmutex_t *)m)->count = 0; \
pthread_mutex_unlock(&(((qmutex_t *)m)->mutex)); \
} while(0)

#define MAX_MUTEX_LOCK_WAIT (5000)
#define Q_MUTEX_ENTER(m) do { \
if(m == NULL) break; \
while(true) { \
if (m == NULL) break; \
while (true) { \
int _ret, i; \
for(i = 0; (_ret = pthread_mutex_trylock(&(((qmutex_t *)m)->mutex))) != 0 \
for (i = 0; (_ret = pthread_mutex_trylock(&(((qmutex_t *)m)->mutex))) != 0 \
&& i < MAX_MUTEX_LOCK_WAIT; i++) { \
if(i == 0) { \
if (i == 0) { \
DEBUG("Q_MUTEX: mutex is already locked - retrying"); \
} \
usleep(1); \
} \
if(_ret == 0) break; \
if (_ret == 0) break; \
DEBUG("Q_MUTEX: can't get lock - force to unlock. [%d]", \
_ret); \
Q_MUTEX_LEAVE(m); \
Expand All @@ -121,10 +121,10 @@ struct qmutex_s {
} while(0)

#define Q_MUTEX_DESTROY(m) do { \
if(m == NULL) break; \
if(((qmutex_t *)m)->count != 0) DEBUG("Q_MUTEX: mutex counter is not 0."); \
if (m == NULL) break; \
if (((qmutex_t *)m)->count != 0) DEBUG("Q_MUTEX: mutex counter is not 0."); \
int _ret; \
while((_ret = pthread_mutex_destroy(&(((qmutex_t *)m)->mutex))) != 0) { \
while ((_ret = pthread_mutex_destroy(&(((qmutex_t *)m)->mutex))) != 0) { \
DEBUG("Q_MUTEX: force to unlock mutex. [%d]", _ret); \
Q_MUTEX_LEAVE(m); \
} \
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/qhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ bool qhashmd5_file(const char *filepath, off_t offset, ssize_t nbytes,
}

// if requested to digest until the end of file, set nbytes to the remaining size
if(nbytes == 0) {
if (nbytes == 0) {
nbytes = size - offset;
}

Expand Down