static inline void rwlock_wlock(struct rwlock *lock) { atom_spinlock(&lock->write); while(lock->read) { atom_sync(); } }
static inline void rwlock_rlock(struct rwlock *lock) { for (;;) { while(lock->write) { atom_sync(); } atom_inc(&lock->read); if (lock->write) { atom_dec(&lock->read); } else { break; } } }
void skynet_service_delete(struct skynet_service *self, address_t id) { assert_launcher(self); struct skynet_service *svc = skynet_service_grab(id); if (svc == NULL) return; struct service_node *sn = &G->s[id % MAX_SERVICE]; assert(sn->id == id); assert(skynet_service_id(sn->svc) == id); sn->exit = 1; atom_sync(); if (sn->ref == 0) { sn->id = 0; atom_sync(); sn->svc = NULL; skynet_service_destory(svc); } else { // Only close service, the slot will reuse after .ref == 0 when call skynet_service_new skynet_service_close(svc); } }
static address_t alloc_id() { int i; for (i=0;i<MAX_SERVICE;i++) { address_t id = ++G->last_id; if (id == 0) { id = ++G->last_id; } struct service_node *sn = &G->s[id % MAX_SERVICE]; if (sn->id == 0) return id; if (sn->exit && sn->ref == 0) { sn->id = 0; atom_sync(); sn->svc = NULL; skynet_service_destory(sn->svc); return id; } } return 0; }