Change field names and introduce the spinlock in the lock structure

This commit is contained in:
Juan Jose Garcia Ripoll 2012-03-29 17:43:27 +02:00
parent 658d1c53ab
commit 5b1007c787
4 changed files with 19 additions and 13 deletions

View file

@ -453,12 +453,14 @@ cl_object_mark_proc(void *addr, struct GC_ms_entry *msp, struct GC_ms_entry *msl
ecl_mark_env(o->process.env);
break;
case t_lock:
MAYBE_MARK(o->lock.waiter);
MAYBE_MARK(o->lock.queue_list);
MAYBE_MARK(o->lock.queue_spinlock);
MAYBE_MARK(o->lock.owner);
MAYBE_MARK(o->lock.name);
break;
case t_condition_variable:
MAYBE_MARK(o->condition_variable.waiter);
MAYBE_MARK(o->condition_variable.queue_spinlock);
MAYBE_MARK(o->condition_variable.queue_list);
MAYBE_MARK(o->condition_variable.lock);
break;
case t_rwlock:
@ -985,7 +987,8 @@ init_alloc(void)
type_info[t_lock].descriptor =
to_bitmap(&o, &(o.lock.name)) |
to_bitmap(&o, &(o.lock.owner)) |
to_bitmap(&o, &(o.lock.waiter));
to_bitmap(&o, &(o.lock.queue_spinlock)) |
to_bitmap(&o, &(o.lock.queue_list));
# ifdef ECL_RWLOCK
type_info[t_rwlock].descriptor =
to_bitmap(&o, &(o.rwlock.name));
@ -996,7 +999,8 @@ init_alloc(void)
# endif
type_info[t_condition_variable].descriptor =
to_bitmap(&o, &(o.condition_variable.lock)) |
to_bitmap(&o, &(o.condition_variable.waiter));
to_bitmap(&o, &(o.condition_variable.queue_list)) |
to_bitmap(&o, &(o.condition_variable.queue_spinlock));
# ifdef ECL_SEMAPHORES
type_info[t_semaphore].descriptor = 0;
# endif

View file

@ -50,7 +50,7 @@ ecl_giveup_spinlock(cl_object *lock)
void
ecl_make_atomic_queue(cl_object q)
{
q->lock.waiter = ecl_list1(Cnil);
q->lock.queue_list = ecl_list1(Cnil);
}
static ECL_INLINE void
@ -140,7 +140,7 @@ ecl_wait_on(cl_object (*condition)(cl_env_ptr, cl_object), cl_object o)
/* 2) Now we add ourselves to the queue. In order to avoid a
* call to the GC, we try to reuse records. */
ecl_atomic_queue_nconc(the_env, o->lock.waiter, record);
ecl_atomic_queue_nconc(the_env, o->lock.queue_list, record);
own_process->process.waiting_for = o;
CL_UNWIND_PROTECT_BEGIN(the_env) {
@ -148,7 +148,7 @@ ecl_wait_on(cl_object (*condition)(cl_env_ptr, cl_object), cl_object o)
* might have missed a wakeup event if that happened
* between 0) and 2), which is why we start with the
* check*/
cl_object queue = ECL_CONS_CDR(o->lock.waiter);
cl_object queue = ECL_CONS_CDR(o->lock.queue_list);
if (ECL_CONS_CAR(queue) != own_process ||
condition(the_env, o) == Cnil)
{
@ -167,7 +167,7 @@ ecl_wait_on(cl_object (*condition)(cl_env_ptr, cl_object), cl_object o)
/* 4) At this point we wrap up. We remove ourselves
from the queue and restore signals, which were */
own_process->process.waiting_for = Cnil;
ecl_atomic_queue_delete(the_env, o->lock.waiter, own_process);
ecl_atomic_queue_delete(the_env, o->lock.queue_list, own_process);
own_process->process.queue_record = record;
ECL_RPLACD(record, Cnil);
pthread_sigmask(SIG_SETMASK, NULL, &original);
@ -214,7 +214,7 @@ wakeup_one(cl_env_ptr the_env, cl_object waiter, int flags)
void
ecl_wakeup_waiters(cl_env_ptr the_env, cl_object o, int flags)
{
cl_object waiter = o->lock.waiter;
cl_object waiter = o->lock.queue_list;
print_lock("releasing\t", o);
if (ECL_CONS_CDR(waiter) != Cnil) {
if (flags & ECL_WAKEUP_ALL) {
@ -240,7 +240,7 @@ print_lock(char *prefix, cl_object l, ...)
printf("\n%d\t", fix(env->own_process->process.name));
vprintf(prefix, args);
if (l != Cnil) {
cl_object p = ECL_CONS_CDR(l->lock.waiter);
cl_object p = ECL_CONS_CDR(l->lock.queue_list);
while (p != Cnil) {
printf(" %d", fix(ECL_CONS_CAR(p)->process.name));
p = ECL_CONS_CDR(p);

View file

@ -468,7 +468,7 @@ extern void ecl_get_spinlock(cl_env_ptr env, cl_object *lock);
extern void ecl_giveup_spinlock(cl_object *lock);
extern void ecl_make_atomic_queue(cl_object);
#define ecl_atomic_queue_list(queue) ECL_CONS_CDR((queue)->lock.waiter)
#define ecl_atomic_queue_list(queue) ECL_CONS_CDR((queue)->lock.queue_list)
extern void ecl_wait_on(cl_object (*condition)(cl_env_ptr, cl_object), cl_object o);
extern void ecl_wakeup_waiters(cl_env_ptr the_env, cl_object o, bool all);

View file

@ -905,7 +905,8 @@ struct ecl_process {
struct ecl_lock {
HEADER1(recursive);
cl_object waiter;
cl_object queue_list;
cl_object queue_spinlock;
cl_object owner; /* thread holding the lock or NIL */
cl_object name;
cl_fixnum counter;
@ -923,7 +924,8 @@ struct ecl_rwlock {
struct ecl_condition_variable {
HEADER;
cl_object waiter;
cl_object queue_list;
cl_object queue_spinlock;
cl_object lock;
};