Skip to content
Snippets Groups Projects
Commit 304f5a1e authored by Henrik (Grubba) Grubbström's avatar Henrik (Grubba) Grubbström
Browse files

The max number of idle farmers is now 16.

Rev: src/threads.c:1.125
parent 83bc4a20
No related branches found
No related tags found
No related merge requests found
#include "global.h" #include "global.h"
RCSID("$Id: threads.c,v 1.124 2000/05/20 13:31:23 grubba Exp $"); RCSID("$Id: threads.c,v 1.125 2000/05/20 18:43:18 grubba Exp $");
int num_threads = 1; int num_threads = 1;
int threads_disabled = 0; int threads_disabled = 0;
...@@ -1387,6 +1387,9 @@ static struct farmer { ...@@ -1387,6 +1387,9 @@ static struct farmer {
static MUTEX_T rosie STATIC_MUTEX_INIT; static MUTEX_T rosie STATIC_MUTEX_INIT;
static int _num_farmers, _num_idle_farmers;
static TH_RETURN_TYPE farm(void *_a) static TH_RETURN_TYPE farm(void *_a)
{ {
struct farmer *me = (struct farmer *)_a; struct farmer *me = (struct farmer *)_a;
...@@ -1399,10 +1402,19 @@ static TH_RETURN_TYPE farm(void *_a) ...@@ -1399,10 +1402,19 @@ static TH_RETURN_TYPE farm(void *_a)
me->harvest = 0; me->harvest = 0;
mt_lock( &rosie ); mt_lock( &rosie );
if( ++_num_idle_farmers > 16 )
{
--_num_idle_farmers;
--_num_farmers;
mt_unlock( &rosie );
free( me );
return NULL;
}
me->neighbour = farmers; me->neighbour = farmers;
farmers = me; farmers = me;
/* fprintf(stderr, "farm_wait %p\n", me); */ /* fprintf(stderr, "farm_wait %p\n", me); */
while(!me->harvest) co_wait( &me->harvest_moon, &rosie ); while(!me->harvest) co_wait( &me->harvest_moon, &rosie );
--_num_idle_farmers;
mt_unlock( &rosie ); mt_unlock( &rosie );
/* fprintf(stderr, "farm_endwait %p\n", me); */ /* fprintf(stderr, "farm_endwait %p\n", me); */
} while(1); } while(1);
...@@ -1412,13 +1424,10 @@ static TH_RETURN_TYPE farm(void *_a) ...@@ -1412,13 +1424,10 @@ static TH_RETURN_TYPE farm(void *_a)
int th_num_idle_farmers(void) int th_num_idle_farmers(void)
{ {
int q = 0; return _num_idle_farmers;
struct farmer *f = farmers;
while(f) { f = f->neighbour; q++; }
return q;
} }
static int _num_farmers;
int th_num_farmers(void) int th_num_farmers(void)
{ {
return _num_farmers; return _num_farmers;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment