feat: publish Android 1.0.1 candidate source and acceptance evidence
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
============================================================================
|
||||
Name : hev-task-cond.c
|
||||
Author : Heiher <r@hev.cc>
|
||||
Copyright : Copyright (c) 2019 everyone.
|
||||
Description : Condition
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "kern/task/hev-task.h"
|
||||
#include "lib/misc/hev-compiler.h"
|
||||
|
||||
#include "hev-task-cond.h"
|
||||
|
||||
struct _HevTaskCondNode
|
||||
{
|
||||
HevTaskCondNode *prev;
|
||||
HevTaskCondNode *next;
|
||||
|
||||
HevTask *task;
|
||||
};
|
||||
|
||||
EXPORT_SYMBOL int
|
||||
hev_task_cond_init (HevTaskCond *self)
|
||||
{
|
||||
self->waiters = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL int
|
||||
hev_task_cond_wait (HevTaskCond *self, HevTaskMutex *mutex)
|
||||
{
|
||||
HevTaskCondNode node;
|
||||
|
||||
node.prev = NULL;
|
||||
node.next = self->waiters;
|
||||
node.task = hev_task_self ();
|
||||
|
||||
if (self->waiters)
|
||||
self->waiters->prev = &node;
|
||||
self->waiters = &node;
|
||||
|
||||
hev_task_mutex_unlock (mutex);
|
||||
do {
|
||||
hev_task_yield (HEV_TASK_WAITIO);
|
||||
} while (READ_ONCE (node.task));
|
||||
hev_task_mutex_lock (mutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL int
|
||||
hev_task_cond_timedwait (HevTaskCond *self, HevTaskMutex *mutex,
|
||||
unsigned int milliseconds)
|
||||
{
|
||||
HevTaskCondNode node;
|
||||
|
||||
node.prev = NULL;
|
||||
node.next = self->waiters;
|
||||
node.task = hev_task_self ();
|
||||
|
||||
if (self->waiters)
|
||||
self->waiters->prev = &node;
|
||||
self->waiters = &node;
|
||||
|
||||
hev_task_mutex_unlock (mutex);
|
||||
while (milliseconds && READ_ONCE (node.task))
|
||||
milliseconds = hev_task_sleep (milliseconds);
|
||||
hev_task_mutex_lock (mutex);
|
||||
|
||||
if (READ_ONCE (node.task)) {
|
||||
if (node.prev)
|
||||
node.prev->next = node.next;
|
||||
if (node.next)
|
||||
node.next->prev = node.prev;
|
||||
if (self->waiters == &node)
|
||||
self->waiters = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL int
|
||||
hev_task_cond_signal (HevTaskCond *self)
|
||||
{
|
||||
if (self->waiters) {
|
||||
hev_task_wakeup (self->waiters->task);
|
||||
|
||||
self->waiters->task = NULL;
|
||||
self->waiters = self->waiters->next;
|
||||
if (self->waiters)
|
||||
self->waiters->prev = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL int
|
||||
hev_task_cond_broadcast (HevTaskCond *self)
|
||||
{
|
||||
while (self->waiters) {
|
||||
hev_task_wakeup (self->waiters->task);
|
||||
|
||||
self->waiters->task = NULL;
|
||||
self->waiters = self->waiters->next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
============================================================================
|
||||
Name : hev-task-cond.h
|
||||
Author : Heiher <r@hev.cc>
|
||||
Copyright : Copyright (c) 2019 everyone.
|
||||
Description : Condition
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
#ifndef __HEV_TASK_COND_H__
|
||||
#define __HEV_TASK_COND_H__
|
||||
|
||||
#include "hev-task-mutex.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _HevTaskCond HevTaskCond;
|
||||
typedef struct _HevTaskCondNode HevTaskCondNode;
|
||||
|
||||
struct _HevTaskCond
|
||||
{
|
||||
HevTaskCondNode *waiters;
|
||||
};
|
||||
|
||||
/**
|
||||
* hev_task_cond_init:
|
||||
* @self: a #HevTaskCond
|
||||
*
|
||||
* Initialize the task condition.
|
||||
*
|
||||
* Returns: When successful, returns zero. When an error occurs, returns -1.
|
||||
*
|
||||
* Since: 4.4
|
||||
*/
|
||||
int hev_task_cond_init (HevTaskCond *self);
|
||||
|
||||
/**
|
||||
* hev_task_cond_wait:
|
||||
* @self: a #HevTaskCond
|
||||
* @mutex: a #HevTaskMutex
|
||||
*
|
||||
* Wait on the task condition.
|
||||
*
|
||||
* Returns: When successful, returns zero. When an error occurs, returns -1.
|
||||
*
|
||||
* Since: 4.4
|
||||
*/
|
||||
int hev_task_cond_wait (HevTaskCond *self, HevTaskMutex *mutex);
|
||||
|
||||
/**
|
||||
* hev_task_cond_wait:
|
||||
* @self: a #HevTaskCond
|
||||
* @mutex: a #HevTaskMutex
|
||||
* @milliseconds: wait time
|
||||
*
|
||||
* The timedwait function shall be equivalent to condition wait, except that an
|
||||
* error is returned if the time specified by @milliseconds passes.
|
||||
*
|
||||
* Returns: When successful, returns zero. When an error occurs, returns -1.
|
||||
*
|
||||
* Since: 4.4
|
||||
*/
|
||||
int hev_task_cond_timedwait (HevTaskCond *self, HevTaskMutex *mutex,
|
||||
unsigned int milliseconds);
|
||||
|
||||
/**
|
||||
* hev_task_cond_signal:
|
||||
* @self: a #HevTaskCond
|
||||
*
|
||||
* Wake one task that wait on condition.
|
||||
*
|
||||
* Returns: When successful, returns zero. When an error occurs, returns -1.
|
||||
*
|
||||
* Since: 4.4
|
||||
*/
|
||||
int hev_task_cond_signal (HevTaskCond *self);
|
||||
|
||||
/**
|
||||
* hev_task_cond_broadcast:
|
||||
* @self: a #HevTaskCond
|
||||
*
|
||||
* Wake all task that wait on condition.
|
||||
*
|
||||
* Returns: When successful, returns zero. When an error occurs, returns -1.
|
||||
*
|
||||
* Since: 4.4
|
||||
*/
|
||||
int hev_task_cond_broadcast (HevTaskCond *self);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __HEV_TASK_MUTEX_H__ */
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
============================================================================
|
||||
Name : hev-task-mutex.c
|
||||
Author : Heiher <r@hev.cc>
|
||||
Copyright : Copyright (c) 2019 everyone.
|
||||
Description : Mutex
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "kern/task/hev-task.h"
|
||||
#include "lib/misc/hev-compiler.h"
|
||||
|
||||
#include "hev-task-mutex.h"
|
||||
|
||||
struct _HevTaskMutexNode
|
||||
{
|
||||
HevTaskMutexNode *next;
|
||||
|
||||
HevTask *task;
|
||||
};
|
||||
|
||||
EXPORT_SYMBOL int
|
||||
hev_task_mutex_init (HevTaskMutex *self)
|
||||
{
|
||||
self->locker = 0;
|
||||
self->waiters = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL int
|
||||
hev_task_mutex_lock (HevTaskMutex *self)
|
||||
{
|
||||
if (self->locker) {
|
||||
HevTaskMutexNode node;
|
||||
|
||||
node.next = self->waiters;
|
||||
node.task = hev_task_self ();
|
||||
self->waiters = &node;
|
||||
|
||||
do {
|
||||
hev_task_yield (HEV_TASK_WAITIO);
|
||||
} while (READ_ONCE (self->locker) ||
|
||||
READ_ONCE (self->waiters) != &node);
|
||||
|
||||
self->waiters = node.next;
|
||||
}
|
||||
|
||||
barrier ();
|
||||
self->locker = 1;
|
||||
barrier ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL int
|
||||
hev_task_mutex_trylock (HevTaskMutex *self)
|
||||
{
|
||||
if (self->locker)
|
||||
return -1;
|
||||
|
||||
barrier ();
|
||||
self->locker = 1;
|
||||
barrier ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL int
|
||||
hev_task_mutex_unlock (HevTaskMutex *self)
|
||||
{
|
||||
barrier ();
|
||||
self->locker = 0;
|
||||
barrier ();
|
||||
|
||||
if (self->waiters)
|
||||
hev_task_wakeup (self->waiters->task);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
============================================================================
|
||||
Name : hev-task-mutex.h
|
||||
Author : Heiher <r@hev.cc>
|
||||
Copyright : Copyright (c) 2019 everyone.
|
||||
Description : Mutex
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
#ifndef __HEV_TASK_MUTEX_H__
|
||||
#define __HEV_TASK_MUTEX_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _HevTaskMutex HevTaskMutex;
|
||||
typedef struct _HevTaskMutexNode HevTaskMutexNode;
|
||||
|
||||
struct _HevTaskMutex
|
||||
{
|
||||
unsigned int locker;
|
||||
|
||||
HevTaskMutexNode *waiters;
|
||||
};
|
||||
|
||||
/**
|
||||
* hev_task_mutex_init:
|
||||
* @self: a #HevTaskMutex
|
||||
*
|
||||
* Initialize the task mutex.
|
||||
*
|
||||
* Returns: When successful, returns zero. When an error occurs, returns -1.
|
||||
*
|
||||
* Since: 4.3
|
||||
*/
|
||||
int hev_task_mutex_init (HevTaskMutex *self);
|
||||
|
||||
/**
|
||||
* hev_task_mutex_lock:
|
||||
* @self: a #HevTaskMutex
|
||||
*
|
||||
* Lock the task mutex.
|
||||
*
|
||||
* Returns: When successful, returns zero. When an error occurs, returns -1.
|
||||
*
|
||||
* Since: 4.3
|
||||
*/
|
||||
int hev_task_mutex_lock (HevTaskMutex *self);
|
||||
|
||||
/**
|
||||
* hev_task_mutex_trylock:
|
||||
* @self: a #HevTaskMutex
|
||||
*
|
||||
* Try lock the task mutex.
|
||||
*
|
||||
* Returns: When successful, returns zero. When an error occurs, returns -1.
|
||||
*
|
||||
* Since: 4.3
|
||||
*/
|
||||
int hev_task_mutex_trylock (HevTaskMutex *self);
|
||||
|
||||
/**
|
||||
* hev_task_mutex_unlock:
|
||||
* @self: a #HevTaskMutex
|
||||
*
|
||||
* Unlock the task mutex.
|
||||
*
|
||||
* Returns: When successful, returns zero. When an error occurs, returns -1.
|
||||
*
|
||||
* Since: 4.3
|
||||
*/
|
||||
int hev_task_mutex_unlock (HevTaskMutex *self);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __HEV_TASK_MUTEX_H__ */
|
||||
Reference in New Issue
Block a user