From fe8befa33305f9b0464c1afd18c832c6c6489077 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 4 Apr 2024 13:55:06 +0800 Subject: [PATCH] 1 --- server/imserver_new/guild/guildmgr.go | 28 +++++++++++++++++++++++---- server/imserver_new/guild/member.go | 9 --------- third_party/f5 | 2 +- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/server/imserver_new/guild/guildmgr.go b/server/imserver_new/guild/guildmgr.go index d714be0c..a0a0a805 100644 --- a/server/imserver_new/guild/guildmgr.go +++ b/server/imserver_new/guild/guildmgr.go @@ -153,17 +153,24 @@ func (this* guildMgr) removeUsingName(name string) { 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)) { if this.internalGetGuildByAccountId(accountId) != nil { + task.SetFail() cb(1, "", 0) return } if this.internalGetGuildByGuildName(name) != nil { + task.SetFail() cb(1, "", 0) return } if this.isUsingName(name) { + task.SetFail() cb(1, "", 0) return } @@ -185,6 +192,7 @@ func (this *guildMgr) AsyncCreateGuild(accountId string, avatar int32, name stri func (err error, lastInsertId int64, rowsAffected int64) { this.removeUsingName(name) if err != nil { + task.SetFail() cb(1, "", 0) return } @@ -208,26 +216,38 @@ func (this *guildMgr) AsyncCreateGuild(accountId string, avatar int32, name stri }, func (err error, lastInsertId int64, rowsAffected int64) { if err != nil { + task.SetFail() cb(1, "", 0) return } guild := newGuild() this.idHash[guild.guildId] = guild this.nameHash[guild.guildName] = guild - //this.accountIdHash[accountId] = guild oldGuild := this.internalGetGuildByAccountId(accountId) if oldGuild != nil { - + task.SetFail() + panic(fmt.Sprintf("asyncCreateGuildTask:%s", "")) } else { m := newMember() m.init(guild, accountId, q5.ToInt32(nowTime)) 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, cb func(int32, string, int64, []string)) { guild := this.GetGuildByAccountId(accountId) diff --git a/server/imserver_new/guild/member.go b/server/imserver_new/guild/member.go index 14cba0de..bc5b9e8a 100644 --- a/server/imserver_new/guild/member.go +++ b/server/imserver_new/guild/member.go @@ -7,7 +7,6 @@ type member struct { guild *guild memberId string joinTime int32 - wLock 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 } -func (this *member) lock() { - this.wLock++ -} - -func (this *member) unlock() { - this.wLock-- -} - func newMember() *member { p := new(member) return p diff --git a/third_party/f5 b/third_party/f5 index 1a19949e..178d811f 160000 --- a/third_party/f5 +++ b/third_party/f5 @@ -1 +1 @@ -Subproject commit 1a19949e6464872e9d54154bc69e13cfc858d106 +Subproject commit 178d811f9a45f33616901861e95f82e1d055bc83