mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
Revert "add nested spinlock, see issue #646"
This reverts commit ba59ed2e6c.
This commit is contained in:
@@ -37,9 +37,6 @@
|
||||
#define PRIORITY_HIGH 0
|
||||
#define PRIORITY_LOW 1
|
||||
|
||||
#define DIRECTWRITE_SOCKETTHREAD 1
|
||||
#define DIRECTWRITE_WORKERTHREAD 2
|
||||
|
||||
#define HASH_ID(id) (((unsigned)id) % MAX_SOCKET)
|
||||
|
||||
#define PROTOCOL_TCP 0
|
||||
@@ -91,7 +88,7 @@ struct socket {
|
||||
int size;
|
||||
uint8_t udp_address[UDP_ADDRESS_SIZE];
|
||||
} p;
|
||||
struct spinlock_nested dw_lock;
|
||||
struct spinlock dw_lock;
|
||||
int dw_offset;
|
||||
const void * dw_buffer;
|
||||
size_t dw_size;
|
||||
@@ -365,7 +362,7 @@ force_close(struct socket_server *ss, struct socket *s, struct socket_message *r
|
||||
if (s->type != SOCKET_TYPE_PACCEPT && s->type != SOCKET_TYPE_PLISTEN) {
|
||||
sp_del(ss->event_fd, s->fd);
|
||||
}
|
||||
spinlock_nestedlock(&s->dw_lock, DIRECTWRITE_SOCKETTHREAD);
|
||||
spinlock_lock(&s->dw_lock);
|
||||
if (s->type != SOCKET_TYPE_BIND) {
|
||||
if (close(s->fd) < 0) {
|
||||
perror("close socket:");
|
||||
@@ -376,7 +373,7 @@ force_close(struct socket_server *ss, struct socket *s, struct socket_message *r
|
||||
free_buffer(ss, s->dw_buffer, s->dw_size);
|
||||
s->dw_buffer = NULL;
|
||||
}
|
||||
spinlock_nestedunlock(&s->dw_lock, DIRECTWRITE_SOCKETTHREAD);
|
||||
spinlock_unlock(&s->dw_lock);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -422,7 +419,7 @@ new_fd(struct socket_server *ss, int id, int fd, int protocol, uintptr_t opaque,
|
||||
s->warn_size = 0;
|
||||
check_wb_list(&s->high);
|
||||
check_wb_list(&s->low);
|
||||
spinlock_nestedinit(&s->dw_lock);
|
||||
spinlock_init(&s->dw_lock);
|
||||
s->dw_buffer = NULL;
|
||||
s->dw_size = 0;
|
||||
return s;
|
||||
@@ -685,7 +682,7 @@ send_buffer_(struct socket_server *ss, struct socket *s, struct socket_message *
|
||||
|
||||
static int
|
||||
send_buffer(struct socket_server *ss, struct socket *s, struct socket_message *result) {
|
||||
if (!spinlock_nestedtrylock(&s->dw_lock, DIRECTWRITE_SOCKETTHREAD))
|
||||
if (!spinlock_trylock(&s->dw_lock))
|
||||
return -1; // blocked by direct write, send later.
|
||||
if (s->dw_buffer) {
|
||||
// add direct write buffer before high.head
|
||||
@@ -706,7 +703,7 @@ send_buffer(struct socket_server *ss, struct socket *s, struct socket_message *r
|
||||
s->dw_buffer = NULL;
|
||||
}
|
||||
int r = send_buffer_(ss,s,result);
|
||||
spinlock_nestedunlock(&s->dw_lock, DIRECTWRITE_SOCKETTHREAD);
|
||||
spinlock_unlock(&s->dw_lock);
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -1421,7 +1418,7 @@ socket_server_send(struct socket_server *ss, int id, const void * buffer, int sz
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (can_direct_write(s,id) && spinlock_nestedtrylock(&s->dw_lock, DIRECTWRITE_WORKERTHREAD)) {
|
||||
if (can_direct_write(s,id) && spinlock_trylock(&s->dw_lock)) {
|
||||
// may be we can send directly, double check
|
||||
if (can_direct_write(s,id)) {
|
||||
// send directly
|
||||
@@ -1441,7 +1438,7 @@ socket_server_send(struct socket_server *ss, int id, const void * buffer, int sz
|
||||
}
|
||||
if (n == so.sz) {
|
||||
// write done
|
||||
spinlock_nestedunlock(&s->dw_lock, DIRECTWRITE_WORKERTHREAD);
|
||||
spinlock_unlock(&s->dw_lock);
|
||||
so.free_func((void *)buffer);
|
||||
return 0;
|
||||
}
|
||||
@@ -1449,14 +1446,12 @@ socket_server_send(struct socket_server *ss, int id, const void * buffer, int sz
|
||||
s->dw_buffer = buffer;
|
||||
s->dw_size = sz;
|
||||
s->dw_offset = n;
|
||||
spinlock_unlock(&s->dw_lock);
|
||||
|
||||
sp_write(ss->event_fd, s->fd, s, true);
|
||||
|
||||
spinlock_nestedunlock(&s->dw_lock, DIRECTWRITE_WORKERTHREAD);
|
||||
|
||||
return 0;
|
||||
}
|
||||
spinlock_nestedunlock(&s->dw_lock, DIRECTWRITE_WORKERTHREAD);
|
||||
spinlock_unlock(&s->dw_lock);
|
||||
}
|
||||
|
||||
struct request_package request;
|
||||
@@ -1686,7 +1681,7 @@ socket_server_udp_send(struct socket_server *ss, int id, const struct socket_udp
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (can_direct_write(s,id) && spinlock_nestedtrylock(&s->dw_lock, DIRECTWRITE_WORKERTHREAD)) {
|
||||
if (can_direct_write(s,id) && spinlock_trylock(&s->dw_lock)) {
|
||||
// may be we can send directly, double check
|
||||
if (can_direct_write(s,id)) {
|
||||
// send directly
|
||||
@@ -1697,12 +1692,12 @@ socket_server_udp_send(struct socket_server *ss, int id, const struct socket_udp
|
||||
int n = sendto(s->fd, so.buffer, so.sz, 0, &sa.s, sasz);
|
||||
if (n >= 0) {
|
||||
// sendto succ
|
||||
spinlock_nestedunlock(&s->dw_lock, DIRECTWRITE_WORKERTHREAD);
|
||||
spinlock_unlock(&s->dw_lock);
|
||||
so.free_func((void *)buffer);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
spinlock_nestedunlock(&s->dw_lock, DIRECTWRITE_WORKERTHREAD);
|
||||
spinlock_unlock(&s->dw_lock);
|
||||
// let socket thread try again, udp doesn't care the order
|
||||
}
|
||||
|
||||
@@ -1723,13 +1718,13 @@ socket_server_udp_connect(struct socket_server *ss, int id, const char * addr, i
|
||||
if (s->id != id || s->type == SOCKET_TYPE_INVALID) {
|
||||
return -1;
|
||||
}
|
||||
spinlock_nestedlock(&s->dw_lock, DIRECTWRITE_WORKERTHREAD);
|
||||
spinlock_lock(&s->dw_lock);
|
||||
if (s->id != id || s->type == SOCKET_TYPE_INVALID) {
|
||||
spinlock_nestedunlock(&s->dw_lock, DIRECTWRITE_WORKERTHREAD);
|
||||
spinlock_unlock(&s->dw_lock);
|
||||
return -1;
|
||||
}
|
||||
ATOM_INC(&s->udpconnecting);
|
||||
spinlock_nestedunlock(&s->dw_lock, DIRECTWRITE_WORKERTHREAD);
|
||||
spinlock_unlock(&s->dw_lock);
|
||||
|
||||
int status;
|
||||
struct addrinfo ai_hints;
|
||||
|
||||
Reference in New Issue
Block a user