This commit is contained in:
aozhiwei 2024-04-04 13:55:06 +08:00
parent 28337e69ae
commit fe8befa333
3 changed files with 25 additions and 14 deletions

View File

@ -153,17 +153,24 @@ func (this* guildMgr) removeUsingName(name string) {
delete(this.usingNameHash, name) delete(this.usingNameHash, name)
} }
func (this *guildMgr) AsyncCreateGuild(accountId string, avatar int32, name string, func (this* guildMgr) genMemberLockKey(accountId string) string {
return accountId
}
func (this *guildMgr) asyncCreateGuildTask(task *f5.AsyncTask, accountId string, avatar int32, name string,
cb func(int32, string, int64)) { cb func(int32, string, int64)) {
if this.internalGetGuildByAccountId(accountId) != nil { if this.internalGetGuildByAccountId(accountId) != nil {
task.SetFail()
cb(1, "", 0) cb(1, "", 0)
return return
} }
if this.internalGetGuildByGuildName(name) != nil { if this.internalGetGuildByGuildName(name) != nil {
task.SetFail()
cb(1, "", 0) cb(1, "", 0)
return return
} }
if this.isUsingName(name) { if this.isUsingName(name) {
task.SetFail()
cb(1, "", 0) cb(1, "", 0)
return return
} }
@ -185,6 +192,7 @@ func (this *guildMgr) AsyncCreateGuild(accountId string, avatar int32, name stri
func (err error, lastInsertId int64, rowsAffected int64) { func (err error, lastInsertId int64, rowsAffected int64) {
this.removeUsingName(name) this.removeUsingName(name)
if err != nil { if err != nil {
task.SetFail()
cb(1, "", 0) cb(1, "", 0)
return return
} }
@ -208,26 +216,38 @@ func (this *guildMgr) AsyncCreateGuild(accountId string, avatar int32, name stri
}, },
func (err error, lastInsertId int64, rowsAffected int64) { func (err error, lastInsertId int64, rowsAffected int64) {
if err != nil { if err != nil {
task.SetFail()
cb(1, "", 0) cb(1, "", 0)
return return
} }
guild := newGuild() guild := newGuild()
this.idHash[guild.guildId] = guild this.idHash[guild.guildId] = guild
this.nameHash[guild.guildName] = guild this.nameHash[guild.guildName] = guild
//this.accountIdHash[accountId] = guild
oldGuild := this.internalGetGuildByAccountId(accountId) oldGuild := this.internalGetGuildByAccountId(accountId)
if oldGuild != nil { if oldGuild != nil {
task.SetFail()
panic(fmt.Sprintf("asyncCreateGuildTask:%s", ""))
} else { } else {
m := newMember() m := newMember()
m.init(guild, accountId, q5.ToInt32(nowTime)) m.init(guild, accountId, q5.ToInt32(nowTime))
guild.addMember(m) guild.addMember(m)
//this.accountIdHash[accountId] = guild this.memberIdHash[accountId] = m
task.SetSucc()
} }
}) })
}) })
} }
func (this *guildMgr) AsyncCreateGuild(accountId string, avatar int32, name string,
cb func(int32, string, int64)) {
lockKey := this.genMemberLockKey(accountId)
f5.GetApp().AsyncLock(lockKey,
f5.NewAsyncTask(
func (task *f5.AsyncTask) {
this.asyncCreateGuildTask(task, accountId, avatar, name, cb)
}))
}
func (this *guildMgr) AsyncGetApplyList(lastIdx int64, accountId string, func (this *guildMgr) AsyncGetApplyList(lastIdx int64, accountId string,
cb func(int32, string, int64, []string)) { cb func(int32, string, int64, []string)) {
guild := this.GetGuildByAccountId(accountId) guild := this.GetGuildByAccountId(accountId)

View File

@ -7,7 +7,6 @@ type member struct {
guild *guild guild *guild
memberId string memberId string
joinTime int32 joinTime int32
wLock int32
} }
func (this *member) init(guild *guild, memberId string, joinTime int32) { func (this *member) init(guild *guild, memberId string, joinTime int32) {
@ -16,14 +15,6 @@ func (this *member) init(guild *guild, memberId string, joinTime int32) {
this.joinTime = joinTime this.joinTime = joinTime
} }
func (this *member) lock() {
this.wLock++
}
func (this *member) unlock() {
this.wLock--
}
func newMember() *member { func newMember() *member {
p := new(member) p := new(member)
return p return p

2
third_party/f5 vendored

@ -1 +1 @@
Subproject commit 1a19949e6464872e9d54154bc69e13cfc858d106 Subproject commit 178d811f9a45f33616901861e95f82e1d055bc83