mirror of
https://github.com/fumiama/simple-dict.git
synced 2026-06-13 06:50:29 +08:00
fix: mutex
This commit is contained in:
4
client.c
4
client.c
@@ -27,8 +27,8 @@ static struct sockaddr_in their_addr;
|
|||||||
static pthread_t thread;
|
static pthread_t thread;
|
||||||
static uint32_t file_size;
|
static uint32_t file_size;
|
||||||
static int recv_bin = 0;
|
static int recv_bin = 0;
|
||||||
static char pwd[64] = "testpwd";
|
static char pwd[64] = "fumiama";
|
||||||
static char sps[64] = "testsps";
|
static char sps[64] = "minamoto";
|
||||||
|
|
||||||
void getMessage(void *p) {
|
void getMessage(void *p) {
|
||||||
int c = 0, offset = 0;
|
int c = 0, offset = 0;
|
||||||
|
|||||||
9
server.c
9
server.c
@@ -241,9 +241,9 @@ static int s1_get(THREADTIMER *timer) {
|
|||||||
|
|
||||||
static int s2_set(THREADTIMER *timer) {
|
static int s2_set(THREADTIMER *timer) {
|
||||||
uint8_t digest[16];
|
uint8_t digest[16];
|
||||||
|
timer->lock_type = DICT_LOCK_EX;
|
||||||
FILE *fp = open_dict(DICT_LOCK_EX, timer->index);
|
FILE *fp = open_dict(DICT_LOCK_EX, timer->index);
|
||||||
if(fp) {
|
if(fp) {
|
||||||
timer->lock_type = DICT_LOCK_EX;
|
|
||||||
md5((uint8_t*)timer->dat, strlen(timer->dat)+1, digest);
|
md5((uint8_t*)timer->dat, strlen(timer->dat)+1, digest);
|
||||||
uint8_t* dp = digest;
|
uint8_t* dp = digest;
|
||||||
int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ;
|
int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ;
|
||||||
@@ -350,10 +350,10 @@ static void del(FILE *fp, char* key, int len, char ret[4]) {
|
|||||||
static int s4_del(THREADTIMER *timer) {
|
static int s4_del(THREADTIMER *timer) {
|
||||||
uint8_t digest[16];
|
uint8_t digest[16];
|
||||||
char ret[4];
|
char ret[4];
|
||||||
|
timer->lock_type = DICT_LOCK_EX;
|
||||||
FILE *fp = open_dict(DICT_LOCK_EX, timer->index);
|
FILE *fp = open_dict(DICT_LOCK_EX, timer->index);
|
||||||
//timer->status = 0;
|
//timer->status = 0;
|
||||||
if(fp) {
|
if(fp) {
|
||||||
timer->lock_type = DICT_LOCK_EX;
|
|
||||||
md5((uint8_t*)timer->dat, strlen(timer->dat)+1, digest);
|
md5((uint8_t*)timer->dat, strlen(timer->dat)+1, digest);
|
||||||
uint8_t* dp = digest;
|
uint8_t* dp = digest;
|
||||||
int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ;
|
int p = ((*((uint32_t*)digest))>>(8*sizeof(uint32_t)-DICTPOOLBIT))&DICTPOOLSZ;
|
||||||
@@ -367,6 +367,7 @@ static int s4_del(THREADTIMER *timer) {
|
|||||||
del(fp, timer->dat, timer->numbytes+1, ret);
|
del(fp, timer->dat, timer->numbytes+1, ret);
|
||||||
return close_and_send(timer, ret, 4);
|
return close_and_send(timer, ret, 4);
|
||||||
}
|
}
|
||||||
|
timer->lock_type = DICT_LOCK_UN;
|
||||||
return close_and_send(timer, "null", 4);
|
return close_and_send(timer, "null", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,7 +393,9 @@ static void accept_timer(void *p) {
|
|||||||
sleep(MAXWAITSEC / 4);
|
sleep(MAXWAITSEC / 4);
|
||||||
time_t waitsec = time(NULL) - timer->touch;
|
time_t waitsec = time(NULL) - timer->touch;
|
||||||
printf("Wait sec: %u, max: %u\n", (unsigned int)waitsec, MAXWAITSEC);
|
printf("Wait sec: %u, max: %u\n", (unsigned int)waitsec, MAXWAITSEC);
|
||||||
if(waitsec > MAXWAITSEC) break;
|
if(timer->lock_type == DICT_LOCK_EX) {
|
||||||
|
if(waitsec > MAXWAITSEC*THREADCNT) break;
|
||||||
|
} else if(waitsec > MAXWAITSEC) break;
|
||||||
}
|
}
|
||||||
pthread_t thread = accept_threads[index];
|
pthread_t thread = accept_threads[index];
|
||||||
if(thread) {
|
if(thread) {
|
||||||
|
|||||||
Reference in New Issue
Block a user