mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 10:11:27 +01:00
The latter is GPL which makes the whole of mini-os GPL rather than BSD as intended. In tree users are all GPL or GPL-compatible but we should fix this so that mini-os is BSD. Do so by using the same BSD sys/queue.h as we use in libxl. Tested with the builtin mini-os test app and qemu stubdomain, both of which appear to still function as expected. Move tools/libxl/external and the associated sed script to tools/include/xen-external to allow more sensible access from mini-os. Also add s/NULL/0/ in the sed script due to NULL not always being defined in stubdom code when mini-os/wait.h is included. As well as the obvious ABI changes there are a few API updates associated with the change: - struct rw_semaphore.wait_list is unused - remove_waiter needs to take the wait_queue_head The latter requires a qemu update, so there is also a QEMU_TAG update in this changeset. I sprinkled some extra-emacs local variables around the files I edited which didn't have them. I think this should be backported to the stable branches since external users of mini-os may have been mislead into thinking they could safely link mini-os against GPL-incompatible code. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
111 lines
2.3 KiB
C
111 lines
2.3 KiB
C
#ifndef _SEMAPHORE_H_
|
|
#define _SEMAPHORE_H_
|
|
|
|
#include <mini-os/wait.h>
|
|
#include <mini-os/spinlock.h>
|
|
|
|
/*
|
|
* Implementation of semaphore in Mini-os is simple, because
|
|
* there are no preemptive threads, the atomicity is guaranteed.
|
|
*/
|
|
|
|
struct semaphore
|
|
{
|
|
int count;
|
|
struct wait_queue_head wait;
|
|
};
|
|
|
|
/*
|
|
* the semaphore definition
|
|
*/
|
|
struct rw_semaphore {
|
|
signed long count;
|
|
spinlock_t wait_lock;
|
|
int debug;
|
|
};
|
|
|
|
#define __SEMAPHORE_INITIALIZER(name, n) \
|
|
{ \
|
|
.count = n, \
|
|
.wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
|
|
}
|
|
|
|
#define __MUTEX_INITIALIZER(name) \
|
|
__SEMAPHORE_INITIALIZER(name,1)
|
|
|
|
#define __DECLARE_SEMAPHORE_GENERIC(name,count) \
|
|
struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
|
|
|
|
#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
|
|
|
|
#define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
|
|
|
|
static inline void init_SEMAPHORE(struct semaphore *sem, int count)
|
|
{
|
|
sem->count = count;
|
|
init_waitqueue_head(&sem->wait);
|
|
}
|
|
|
|
#define init_MUTEX(sem) init_SEMAPHORE(sem, 1)
|
|
|
|
static inline int trydown(struct semaphore *sem)
|
|
{
|
|
unsigned long flags;
|
|
int ret = 0;
|
|
local_irq_save(flags);
|
|
if (sem->count > 0) {
|
|
ret = 1;
|
|
sem->count--;
|
|
}
|
|
local_irq_restore(flags);
|
|
return ret;
|
|
}
|
|
|
|
static void inline down(struct semaphore *sem)
|
|
{
|
|
unsigned long flags;
|
|
while (1) {
|
|
wait_event(sem->wait, sem->count > 0);
|
|
local_irq_save(flags);
|
|
if (sem->count > 0)
|
|
break;
|
|
local_irq_restore(flags);
|
|
}
|
|
sem->count--;
|
|
local_irq_restore(flags);
|
|
}
|
|
|
|
static void inline up(struct semaphore *sem)
|
|
{
|
|
unsigned long flags;
|
|
local_irq_save(flags);
|
|
sem->count++;
|
|
wake_up(&sem->wait);
|
|
local_irq_restore(flags);
|
|
}
|
|
|
|
/* FIXME! Thre read/write semaphores are unimplemented! */
|
|
static inline void init_rwsem(struct rw_semaphore *sem)
|
|
{
|
|
sem->count = 1;
|
|
}
|
|
|
|
static inline void down_read(struct rw_semaphore *sem)
|
|
{
|
|
}
|
|
|
|
|
|
static inline void up_read(struct rw_semaphore *sem)
|
|
{
|
|
}
|
|
|
|
static inline void up_write(struct rw_semaphore *sem)
|
|
{
|
|
}
|
|
|
|
static inline void down_write(struct rw_semaphore *sem)
|
|
{
|
|
}
|
|
|
|
#endif /* _SEMAPHORE_H */
|