Commit 38dd5b05 authored by claes's avatar claes

New synchronization mechanism for qcom

parent 427bccf7
/* rt_futex.c -- Futex operations
PROVIEW/R
Contains functions that are heavily os-dependant.
Author: Robert Karlsson 21 Apr 2004
Description:
This module provides an interface to futexes - "fast user level
locking in Linux". This is achieved through the multiplexing
system call sys_futex(). As implemented below this interface provides
a synchronization mechanism that can be used both between threads
in one process as well as between threads in different processes */
#if !defined(OS_LINUX)
# error "This file is valid only for OS_LINUX"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/syscall.h>
#include <unistd.h>
#define FUTEX_WAIT (0)
#define FUTEX_WAKE (1)
#define FUTEX_FD (2)
#define FUTEX_REQUEUE (3)
int
futex_wait (
int *futex,
int val
)
{
int ok;
ok = syscall(SYS_futex, futex, FUTEX_WAIT, val, NULL);
if (ok == -1) {
return errno;
}
else {
return ok;
}
}
int
futex_timed_wait (
int *futex,
int val,
const struct timespec * timespec
)
{
int ok;
ok = syscall(SYS_futex, futex, FUTEX_WAIT, val, timespec);
if (ok == -1) {
return errno;
}
else {
return ok;
}
}
int
futex_wake (
int *futex,
int nr
)
{
int ok;
ok = syscall(SYS_futex, futex, FUTEX_WAKE, nr, NULL);
if (ok == -1) {
return errno;
}
else {
return ok;
}
}
/* rt_futex.h */
#ifndef rt_futex_h
#define rt_futex_h
#ifdef __cplusplus
extern "C" {
#endif
int futex_wait(int *futex, int val);
int futex_timed_wait(int *futex, int val, const struct timespec * timespec);
int futex_wake(int *futex,int nr);
#ifdef __cplusplus
}
#endif
#endif
......@@ -26,10 +26,11 @@
#include "rt_qdb.h"
#include "rt_pool.h"
#include "rt_hash.h"
#include "rt_futex.h"
pwr_tBoolean
qos_WaitQue (
qos_WaitQueOld (
pwr_tStatus *status,
qdb_sQue *qp,
int tmo
......@@ -88,8 +89,57 @@ qos_WaitQue (
return signal;
}
pwr_tBoolean
qos_WaitQue (
pwr_tStatus *status,
qdb_sQue *qp,
int tmo
)
{
pwr_tDeltaTime dtime;
int ok;
pwr_tBoolean signal = FALSE;
pwr_dStatus (sts, status, QCOM__SUCCESS);
qdb_AssumeLocked;
if (tmo == qcom_cTmoNone)
return FALSE;
qp->lock.waiting = TRUE;
qp->lock.pid = 0;
qdb_Unlock;
if (tmo != qcom_cTmoEternal) {
ok = futex_timed_wait(&(qp->lock.pid), 0, (struct timespec *) time_MsToD(&dtime, tmo));
} else {
for (;;) {
ok = futex_wait(&(qp->lock.pid), 0);
if (ok == EINTR)
continue;
break;
}
}
if (ok == EWOULDBLOCK) {
errh_Error("waitQue - Deadlock would occur");
}
qdb_Lock;
if ((qp->lock.waiting) || (ok == ETIMEDOUT)) {
*sts = QCOM__TMO;
qp->lock.waiting = FALSE;
} else {
signal = TRUE;
}
return signal;
}
pwr_tStatus
qos_SignalQue (
qos_SignalQueOld (
pwr_tStatus *status,
qdb_sQue *qp
)
......@@ -114,7 +164,27 @@ qos_SignalQue (
return TRUE;
}
pwr_tStatus
qos_SignalQue (
pwr_tStatus *status,
qdb_sQue *qp
)
{
int ok;
pwr_dStatus (sts, status, QCOM__SUCCESS);
qdb_AssumeLocked;
if (qp->lock.waiting) {
qp->lock.waiting = FALSE;
ok = futex_wake(&(qp->lock.pid), INT_MAX);
}
return TRUE;
}
qdb_sQlock *
qos_CreateQlock (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment