Minimize external locking

Everything related to the code /
Tout ce qui touche au code
Post Reply
User avatar
chkno
Posts: 9
Joined: Fri Jun 20, 2008 11:49 pm
Location: USA

Minimize external locking

Post by chkno » Sat Jun 28, 2008 3:10 am

<chkno> Question: Why "pMutex.lock()" everywhere instead of "lock()" ?
<milipili> I would like to avoid lock() the most possible. A class should never be locked from outside
<milipili> It is impossible to find out a dead lock in this kind of design
<chkno> So make lock() a protected method?
<milipili> No it is impossible ... :(
<milipili> Without rewriting a lot/lot/lot/lot of code
It wasn't so bad. Here's a patch to make lock()/unlock() methods protected (against mili-branch@618). Also included is an ObjectLocker in the spirit of MutexLocker for auto-unlocking on stack unwind. The few objects that must allow external locking (MAP, INGAME_UNITS, LUA_PROGRAM, etc) are set apart by inheriting from Mutex instead of ObjectSync.

milipili
Posts: 545
Joined: Thu Nov 02, 2006 8:52 am
Location: Paris (France)
Contact:

Post by milipili » Sat Jun 28, 2008 2:31 pm

I don't think it is the real good solution. A protected variable is good enough and I would even say that ObjectSync should be completly removed.
It adds a useless interface from my point of view and it does not fully improve the global code design. Unless I missed something.
Damien Gerard
Ta3d & Yuni Developer

User avatar
zuzuf
Administrateur - Site Admin
Posts: 3281
Joined: Mon Oct 30, 2006 8:49 pm
Location: Toulouse, France
Contact:

Post by zuzuf » Sat Jun 28, 2008 2:33 pm

This isn't a solution and it adds useless steps to the locking mechanism. We shouldn't lock classes from outside, we should rewrite code that works that way to remove those external locks.
=>;-D Penguin Powered

Post Reply

Who is online

Users browsing this forum: No registered users and 38 guests