home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: diskReceiveQ.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:38 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
- #include "queue_consist.h"
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "disk.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "latch.h"
- #include "link.h"
- #include "bf.h"
- #include "pool.h"
- #include "volume.h"
- #include "threadstate.h"
- #include "disk_funcs.h"
- #include "thread_funcs.h"
- #include "thread_globals.h"
- #include "sharedmem_globals.h"
- #include "queue_globals.h"
- #include "io_globals.h"
-
-
- void
- diskReceiveQ (
- QUEUEPAIR *qp,
- BOOL holdingMutex
- )
- {
- extern int disk_requests_out;
- register DISKMSG *diskMessage;
- register TCB *tcb;
- ShmOffset smindex;
-
- TRACE(TR_MSG|TR_DISK, TR_LEVEL_1);
-
- /* dequeue the index */
- if( !holdingMutex )
- getMutex(&(qp->fromDisk.mutex));
- if (!deq_from(qp, smindex)) {
- giveMutex(&(qp->fromDisk.mutex));
- return;
- }
- giveMutex(&(qp->fromDisk.mutex));
- disk_requests_out--;
-
- /*
- * get a pointer to the message field
- * The message was sent by another thread (another thread->diskMessage)
- * My thread->diskMessage would point to the wrong place, so we
- * just get the proper message index from the queue.
- */
- diskMessage = ShmOffsetToAddress(smindex, DISKMSG);
-
- /*
- * get a pointer to the waiting tcb
- */
- TRPRINT(TR_DISK, TR_LEVEL_1,
- ("reply for thread:%d", diskMessage->body.threadId));
-
- tcb = &Tcbs[diskMessage->body.threadId];
- CHECK_TCB_MAGIC(tcb);
-
- /*
- * check to see that the thread is in wait
- * with state == "waiting for disk results"
- */
- SM_ASSERT(LEVEL_1, tcb->state == THREAD_DISK_WAIT);
-
- SM_ASSERT(LEVEL_1,
- tcb->diskMessage->body.volid == diskMessage->body.volid);
- /*
- * check the message magic number
- */
- if (diskMessage->diskmagic != DISK_MESSAGE_MAGIC) {
-
- /*
- * copy in the result
- */
- tcb->error = esmFAILURE;
- tcb->errno = esmBADMESSAGEMAGIC;
- TRPRINT(TR_DISK, TR_LEVEL_1, ("error:%d errno:%d",
- tcb->error, tcb->errno));
-
- } else {
-
- /*
- * copy in the result
- */
- if (diskMessage->header.params.out.errno == esmNOERROR) {
- tcb->error = esmNOERROR;
- } else {
- tcb->error = esmFAILURE;
- }
- tcb->errno = (int)diskMessage->header.params.out.errno;
- TRPRINT(TR_DISK, TR_LEVEL_1, ("error:%d errno:%d",
- tcb->error, tcb->errno));
- }
-
- /*
- * put the thread on the ready queue
- * like notify(&(diskGivingResults), noerror, noerror)
- * but we move the first thread only.
- */
- listMoveEnq( &ReadyList, &(tcb->controlList) );
-
- /*
- * restart this thread
- */
- threadRestart();
- }
-