minix/lib/libblockdriver/event.c
David van Moolenbroek b4d909d415 Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.

The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.

After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
  in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
  reintroduced

As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.

Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-23 14:06:37 +01:00

72 lines
2.4 KiB
C

/* This file contains a simple thread event implementation.
*/
#include <minix/mthread.h>
#include <minix/sysutil.h>
#include "event.h"
/*===========================================================================*
* event_init *
*===========================================================================*/
PUBLIC void event_init(event_t *event)
{
/* Initialize an event object.
*/
int r;
if ((r = mthread_mutex_init(&event->mutex, NULL)) != 0)
panic("libblockdriver: error initializing mutex (%d)", r);
if ((r = mthread_cond_init(&event->cond, NULL)) != 0)
panic("libblockdriver: error initializing condvar (%d)", r);
}
/*===========================================================================*
* event_destroy *
*===========================================================================*/
PUBLIC void event_destroy(event_t *event)
{
/* Destroy an event object.
*/
int r;
if ((r = mthread_cond_destroy(&event->cond)) != 0)
panic("libblockdriver: error destroying condvar (%d)", r);
if ((r = mthread_mutex_destroy(&event->mutex)) != 0)
panic("libblockdriver: error destroying mutex (%d)", r);
}
/*===========================================================================*
* event_wait *
*===========================================================================*/
PUBLIC void event_wait(event_t *event)
{
/* Wait for an event, blocking the current thread in the process.
*/
int r;
if ((r = mthread_mutex_lock(&event->mutex)) != 0)
panic("libblockdriver: error locking mutex (%d)", r);
if ((r = mthread_cond_wait(&event->cond, &event->mutex)) != 0)
panic("libblockdriver: error waiting for condvar (%d)", r);
if ((r = mthread_mutex_unlock(&event->mutex)) != 0)
panic("libblockdriver: error unlocking mutex (%d)", r);
}
/*===========================================================================*
* event_fire *
*===========================================================================*/
PUBLIC void event_fire(event_t *event)
{
/* Fire an event, waking up any thread blocked on it without scheduling it.
*/
int r;
if ((r = mthread_mutex_lock(&event->mutex)) != 0)
panic("libblockdriver: error locking mutex (%d)", r);
if ((r = mthread_cond_signal(&event->cond)) != 0)
panic("libblockdriver: error signaling condvar (%d)", r);
if ((r = mthread_mutex_unlock(&event->mutex)) != 0)
panic("libblockdriver: error unlocking mutex (%d)", r);
}