1998Q3/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: [MUD&#45;Dev] Re: META: who are we? -->
<!--X-From-R13: Brgev Hvexxhyn <civexxhyNvxv.sv> -->
<!--X-Date: Tue, 22 Sep 1998 18:19:50 &#45;0700 -->
<!--X-Message-Id: 13832.19623.570964.56394#arioch,tky.hut.fi -->
<!--X-Content-Type: text/plain -->
<!--X-Reference: KaVir#dial,pipex.com -->
<!--X-Reference: 3608983D.756E#dial,pipex.com -->
<!--X-Reference: 199809222302.QAA03904#under,engr.sgi.com -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, [MUD-Dev] Re: META: who are we?</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:pvirkkul#iki,fi">
</head>
<body background="/backgrounds/paperback.gif" bgcolor="#ffffff"
      text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000">

  <font size="+4" color="#804040">
    <strong><em>MUD-Dev<br>mailing list archive</em></strong>
  </font>
      
<br>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
<br clear=all><hr>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->

Date:&nbsp;
[&nbsp;<a href="msg01112.html">Previous</a>
&nbsp;|&nbsp;<a href="msg01114.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg01112.html">Previous</a>
&nbsp;|&nbsp;<a href="msg01380.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#01113">Author</A>
&nbsp;|&nbsp;<A HREF="#01113">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#01113">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>[MUD-Dev] Re: META: who are we?</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
<LI><em>Subject</em>: [MUD-Dev] Re: META: who are we? </LI>
<LI><em>From</em>: Petri Virkkula &lt;<A HREF="mailto:pvirkkul#iki,fi">pvirkkul#iki,fi</A>&gt;</LI>
<LI><em>Date</em>: Wed, 23 Sep 1998 04:19:35 +0300 (EEST)</LI>
<LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
&gt;&gt;&gt;&gt;&gt; "JCL" == J C Lawrence &lt;claw#under,engr.sgi.com&gt; writes:

JCL&gt; Ditto.  I would that I had the time right now.  My old question
JCL&gt; concerning lightweight locking supports is still out there
JCL&gt; (<A  HREF="http://www.kanga.nu/~petidomo/lists/mud-dev/1998Q3/msg00467.html">http://www.kanga.nu/~petidomo/lists/mud-dev/1998Q3/msg00467.html</A>).
JCL&gt; I haven't had time to get much beyond that.

	I don't see why the virtualized semaphore idea wouldn't work
	if the implementation were slightly modified. See code below
	for detail how I suggest to be changed.

	As I see performance of the code below depends on value of
	MAX_LOCKS and implementation of HASH() and both can be
	modified based after you have studied the locking pattern of
	your code.


	Petri

--- cut here ---
typedef struct {
    pthread_mutex_t mutex;
    pthread_cond_t cond;
} lock_entry_t;

typedef struct {
    unsigned short is_locked;
    unsigned short sleeper_count;
} lock_data_t;


typedef struct {
    ...
    lock_data_t lock_data;
    ...
} object_t;


static lock_entry_t lock_table[MAX_LOCKS];


#define HASH(ptr, size, max) \
    ((((unsigned long)(ptr)) / (size)) % (max))

    
void
lock_object (object_t *ob)
{
    unsigned int ix = HASH(ob, sizeof(object_t), MAX_LOCKS);

    pthread_mutex_lock (&amp;lock_table[ix].mutex);
    while (ob-&gt;lock_data.is_locked) {
	ob-&gt;lock_data.sleeper_count++;
	pthread_cond_wait (&amp;lock_table[ix].cond, &amp;lock_table[ix].mutex);
	ob-&gt;lock_data.sleeper_count--;
    }
    ob-&gt;lock_data.is_locked = 1;
    pthread_mutex_unlock (&amp;lock_table[ix].mutex);
}
    

void
unlock_object (object_t *ob)
{
    unsigned int ix = HASH(ob, sizeof(object_t), MAX_LOCKS);

    pthread_mutex_lock (&amp;lock_table[ix].mutex);
    ob-&gt;lock_data.is_locked = 0;
    if (ob-&gt;lock_data.sleeper_count)
	pthread_cond_signal (&amp;lock_table[ix].cond);
    pthread_mutex_unlock (&amp;lock_table[ix].mutex);
}
--- cut here ---

	


</PRE>

<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<HR>
<!--X-Follow-Ups-End-->
<!--X-References-->
<UL><LI><STRONG>References</STRONG>:
<UL>
<LI><STRONG><A NAME="01103" HREF="msg01103.html">[MUD-Dev] Re: META: who are we?</A></STRONG>
<UL><LI><EM>From:</EM> Richard Woolcock &lt;KaVir#dial,pipex.com&gt;</LI></UL></LI>
<LI><STRONG><A NAME="01107" HREF="msg01107.html">[MUD-Dev] Re: META: who are we?</A></STRONG>
<UL><LI><EM>From:</EM> J C Lawrence &lt;claw#under,engr.sgi.com&gt;</LI></UL></LI>
</UL></LI></UL>
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg01112.html">[MUD-Dev] Re: META: who are we?</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg01114.html">[MUD-Dev] Re: META: who are we?</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg01112.html">[MUD-Dev] Re: META: who are we?</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg01380.html">[MUD-Dev] Re: META: who are we?</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#01113"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#01113"><STRONG>Thread</STRONG></A></LI>
</UL>
</LI>
</UL>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
<ul><li>Thread context:
<BLOCKQUOTE><UL>
<LI><STRONG>[MUD-Dev] Re: META: who are we?</STRONG>, <EM>(continued)</EM>
<ul compact>
<ul compact>
<LI><strong><A NAME="01158" HREF="msg01158.html">[MUD-Dev] Re: META: who are we?</A></strong>, 
T. Alexander Popiel <a href="mailto:popiel#snugharbor,com">popiel#snugharbor,com</a>, Wed 23 Sep 1998, 20:44 GMT
</LI>
</ul>
<LI><strong><A NAME="01103" HREF="msg01103.html">[MUD-Dev] Re: META: who are we?</A></strong>, 
Richard Woolcock <a href="mailto:KaVir#dial,pipex.com">KaVir#dial,pipex.com</a>, Tue 22 Sep 1998, 22:38 GMT
<UL>
<LI><strong><A NAME="01107" HREF="msg01107.html">[MUD-Dev] Re: META: who are we?</A></strong>, 
J C Lawrence <a href="mailto:claw#under,engr.sgi.com">claw#under,engr.sgi.com</a>, Tue 22 Sep 1998, 23:02 GMT
<UL>
<LI><strong><A NAME="01112" HREF="msg01112.html">[MUD-Dev] Re: META: who are we?</A></strong>, 
James Wilson <a href="mailto:jwilson#rochester,rr.com">jwilson#rochester,rr.com</a>, Wed 23 Sep 1998, 00:20 GMT
</LI>
<LI><strong><A NAME="01113" HREF="msg01113.html">[MUD-Dev] Re: META: who are we?</A></strong>, 
Petri Virkkula <a href="mailto:pvirkkul#iki,fi">pvirkkul#iki,fi</a>, Wed 23 Sep 1998, 01:19 GMT
</LI>
</UL>
</LI>
<LI><strong><A NAME="01380" HREF="msg01380.html">[MUD-Dev] Re: META: who are we?</A></strong>, 
Matt Chatterley <a href="mailto:chattemp#ee,port.ac.uk">chattemp#ee,port.ac.uk</a>, Wed 30 Sep 1998, 11:44 GMT
</LI>
</UL>
</LI>
<LI><strong><A NAME="01230" HREF="msg01230.html">[MUD-Dev] Re: META: who are we?</A></strong>, 
Marian Griffith <a href="mailto:gryphon#iaehv,nl">gryphon#iaehv,nl</a>, Fri 25 Sep 1998, 19:35 GMT
<UL>
<LI><strong><A NAME="01233" HREF="msg01233.html">[MUD-Dev] Re: META: who are we?</A></strong>, 
Holly Sommer <a href="mailto:hsommer#micro,ti.com">hsommer#micro,ti.com</a>, Fri 25 Sep 1998, 20:32 GMT
</LI>
</UL>
</LI>
<LI><strong><A NAME="01349" HREF="msg01349.html">[MUD-Dev] Re: META: who are we?</A></strong>, 
Marc Hernandez <a href="mailto:marc#jb,com">marc#jb,com</a>, Tue 29 Sep 1998, 05:50 GMT
</LI>
</ul>
</LI>
</UL></BLOCKQUOTE>

</ul>
<hr>
<center>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
</center>
<hr>
</body>
</html>