/** * qhashtbl->free(): De-allocate hash table * * @param tbl qhashtbl_t container pointer. */ void qhashtbl_free(qhashtbl_t *tbl) { qhashtbl_lock(tbl); qhashtbl_clear(tbl); free(tbl->slots); qhashtbl_unlock(tbl); Q_MUTEX_DESTROY(tbl->qmutex); free(tbl); }
/** * qlog->free(): Close ratating-log file & de-allocate resources * * @param log a pointer of qlog_t */ static void free_(qlog_t *log) { if (log == NULL) return; flush_(log); Q_MUTEX_ENTER(log->qmutex); if (log->fp != NULL) { fclose(log->fp); log->fp = NULL; } Q_MUTEX_LEAVE(log->qmutex); Q_MUTEX_DESTROY(log->qmutex); free(log); return; }
/** * Open ratating-log file * * @param filepathfmt filename format. formatting argument is same as * strftime() * @param mode new file mode. 0 for system default * @param rotateinterval rotating interval seconds, set 0 to disable rotation * @param options combination of options. * * @return a pointer of qlog_t structure * * @note * rotateinterval is not relative time. If you set it to 3600, log file will be * rotated at every hour. And filenameformat is same as strftime(). So If you * want to log with hourly rotating, filenameformat must be defined including * hour format like "/somepath/xxx-%Y%m%d%H.log". You can set it to * "/somepath/xxx-%H.log" for daily overrided log file. * * @note * Available options: * - QLOG_OPT_THREADSAFE - make it thread-safe. * - QLOG_OPT_FLUSH - flush out buffer everytime. * * @code * qlog_t *log = qlog("/tmp/qdecoder-%Y%m%d.err", 0644, 86400, QLOG_OPT_THREADSAFE); * log->free(log); * @endcode */ qlog_t *qlog(const char *filepathfmt, mode_t mode, int rotateinterval, int options) { qlog_t *log; // malloc qlog_t structure log = (qlog_t *) calloc(1, sizeof(qlog_t)); if (log == NULL) { errno = ENOMEM; return NULL; } // set up the structure. qstrcpy(log->filepathfmt, sizeof(log->filepathfmt), filepathfmt); log->mode = mode; if (rotateinterval > 0) log->rotateinterval = rotateinterval; // handle options if (options & QLOG_OPT_THREADSAFE) { Q_MUTEX_NEW(log->qmutex, true); if (log->qmutex == NULL) { errno = ENOMEM; free(log); return NULL; } } if (options & QLOG_OPT_FLUSH) { log->logflush = true; } // try to open the log file. if (_real_open(log) == false) { free(log); Q_MUTEX_DESTROY(log->qmutex); return NULL; } // member methods log->write = write_; log->writef = writef; log->duplicate = duplicate; log->flush = flush_; log->free = free_; return log; }
/** * qdb->free(): De-allocate qdb_t structure * * @param db a pointer of qdb_t object */ static void free_(qdb_t *db) { if (db == NULL) return; Q_MUTEX_ENTER(db->qmutex); close_(db); free(db->info.dbtype); free(db->info.addr); free(db->info.username); free(db->info.password); free(db->info.database); free(db); Q_MUTEX_LEAVE(db->qmutex); Q_MUTEX_DESTROY(db->qmutex); return; }
/** * qlist->free(): Free qlist_t. * * @param list qlist_t container pointer. */ void qlist_free(qlist_t *list) { qlist_clear(list); Q_MUTEX_DESTROY(list->qmutex); free(list); }