| | |
| | | #include "logger_factory.h" |
| | | #include <set> |
| | | #include <functional> |
| | | #include <limits.h> |
| | | |
| | | |
| | | |
| | | typedef struct tailq_entry_t |
| | | { |
| | |
| | | |
| | | memset(hashtable, 0, sizeof(hashtable_t)); |
| | | hashtable->mutex = svsem_get(IPC_PRIVATE, 1); |
| | | // hashtable->wlock = svsem_get(IPC_PRIVATE, 1); |
| | | // hashtable->cond = svsem_get(IPC_PRIVATE, 1); |
| | | // hashtable->readcnt = 0; |
| | | |
| | | // FILE * semfile = fopen("./sem.txt", "w+"); |
| | | // if(semfile == NULL) { |
| | | // err_exit(errno, "fopen"); |
| | | // } |
| | | // fprintf(semfile, "hashtable->mutex=%d\n", hashtable->mutex); |
| | | // fclose(semfile); |
| | | hashtable->queueCount = 0; |
| | | hashtable->currentKey = START_KEY; |
| | | } |
| | | |
| | | void hashtable_destroy(hashtable_t *hashtable) { |
| | | svsem_remove( hashtable->mutex); |
| | | // svsem_remove( hashtable->wlock); |
| | | // svsem_remove( hashtable->cond); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | /* mm_free the item as we don't need it anymore. */ |
| | | mm_free(item); |
| | | hashtable->queueCount--; |
| | | svsem_post(hashtable->mutex); |
| | | return oldvalue; |
| | | } |
| | |
| | | |
| | | void hashtable_put(hashtable_t *hashtable, int key, void *value) { |
| | | _hashtable_put(hashtable, key, value); |
| | | hashtable->queueCount++; |
| | | } |
| | | |
| | | bool hashtable_check_put(hashtable_t *hashtable, int key, void *value, bool overwrite) { |
| | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | int hashtable_get_queue_count(hashtable_t *hashtable) { |
| | | return hashtable->queueCount; |
| | | } |
| | | |
| | | int hashtable_alloc_key(hashtable_t *hashtable) { |
| | | int rv; |
| | | int key = START_KEY; |
| | | int key = hashtable->currentKey; |
| | | |
| | | if( key == INT_MAX || key < START_KEY) { |
| | | key = START_KEY; |
| | | } |
| | | |
| | | rv = svsem_wait(hashtable->mutex); |
| | | if(rv != 0) { |
| | | LoggerFactory::getLogger()->error(errno, "hashtable_alloc_key\n"); |
| | |
| | | // 占用key |
| | | _hashtable_put(hashtable, key, (void *)1); |
| | | |
| | | hashtable->currentKey = key; |
| | | rv = svsem_post(hashtable->mutex); |
| | | if(rv != 0) { |
| | | LoggerFactory::getLogger()->error(errno, "hashtable_alloc_key\n"); |
| | | } |
| | | |
| | | return key; |
| | | } |
| | | |
| | |
| | | hashtable->array[i] = NULL; |
| | | } |
| | | |
| | | hashtable->queueCount = 0; |
| | | if((rv = svsem_post(hashtable->mutex)) != 0) { |
| | | LoggerFactory::getLogger()->error(errno, "hashtable_removeall\n"); |
| | | } |