mirror of https://github.com/red-prig/fpPS4.git
fix sema
This commit is contained in:
parent
40ff63760a
commit
592ba98f41
|
@ -6,7 +6,8 @@ interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
windows,
|
windows,
|
||||||
sys_types;
|
sys_types,
|
||||||
|
spinlock;
|
||||||
|
|
||||||
const
|
const
|
||||||
SCE_KERNEL_SEMA_ATTR_TH_FIFO=$01;
|
SCE_KERNEL_SEMA_ATTR_TH_FIFO=$01;
|
||||||
|
@ -31,7 +32,7 @@ type
|
||||||
num:Integer;
|
num:Integer;
|
||||||
value:Integer;
|
value:Integer;
|
||||||
//vlock:pthread_mutex_t;
|
//vlock:pthread_mutex_t;
|
||||||
lock:Pointer;
|
lock:r_spin_lock;
|
||||||
name:array[0..31] of AnsiChar;
|
name:array[0..31] of AnsiChar;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -71,7 +72,6 @@ implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
atomic,
|
atomic,
|
||||||
spinlock,
|
|
||||||
sys_kernel,
|
sys_kernel,
|
||||||
sys_signal,
|
sys_signal,
|
||||||
sys_time,
|
sys_time,
|
||||||
|
@ -408,7 +408,7 @@ begin
|
||||||
|
|
||||||
//if (sv^.name='SuspendSemaphore') or
|
//if (sv^.name='SuspendSemaphore') or
|
||||||
// (sv^.name='ResumeSemaphore') then
|
// (sv^.name='ResumeSemaphore') then
|
||||||
// Writeln('>sem_wait:',sv^.name,' count:',count,' value:',sv^.value);
|
//Writeln('>sem_wait:',sv^.name,' count:',count,' value:',sv^.value);
|
||||||
|
|
||||||
if (count>sv^.max) then
|
if (count>sv^.max) then
|
||||||
begin
|
begin
|
||||||
|
@ -421,17 +421,23 @@ begin
|
||||||
semh :=sv^.s;
|
semh :=sv^.s;
|
||||||
spin_unlock(sv^.lock);
|
spin_unlock(sv^.lock);
|
||||||
|
|
||||||
if (cur_v>=0) then Exit(0);
|
if (cur_v>=0) then
|
||||||
|
begin
|
||||||
|
//Writeln('<sem_wait:',sv^.name,' count:',count,' value:',sv^.value);
|
||||||
|
Exit(0);
|
||||||
|
end;
|
||||||
|
|
||||||
//pthread_cleanup_push (clean_wait_sem, (void *) &arg);
|
//pthread_cleanup_push (clean_wait_sem, (void *) &arg);
|
||||||
|
|
||||||
|
//Writeln('!sem_wait:',sv^.name,' count:',count,' cur_v:',cur_v);
|
||||||
|
|
||||||
System.InterlockedIncrement(sv^.num);
|
System.InterlockedIncrement(sv^.num);
|
||||||
Result:=do_sema_b_wait_intern(semh,pTimeout);
|
Result:=do_sema_b_wait_intern(semh,pTimeout);
|
||||||
System.InterlockedDecrement(sv^.num);
|
System.InterlockedDecrement(sv^.num);
|
||||||
|
|
||||||
//if (sv^.name='SuspendSemaphore') or
|
//if (sv^.name='SuspendSemaphore') or
|
||||||
// (sv^.name='ResumeSemaphore') then
|
// (sv^.name='ResumeSemaphore') then
|
||||||
// Writeln('<sem_wait:',sv^.name,' count:',count,' value:',sv^.value);
|
//Writeln('<sem_wait:',sv^.name,' count:',count,' value:',sv^.value);
|
||||||
|
|
||||||
//pthread_cleanup_pop (ret);
|
//pthread_cleanup_pop (ret);
|
||||||
if (Result=EINVAL) then Result:=0;
|
if (Result=EINVAL) then Result:=0;
|
||||||
|
@ -462,14 +468,22 @@ begin
|
||||||
|
|
||||||
//if (sv^.name='SuspendSemaphore') or
|
//if (sv^.name='SuspendSemaphore') or
|
||||||
// (sv^.name='ResumeSemaphore') then
|
// (sv^.name='ResumeSemaphore') then
|
||||||
// Writeln('>sem_post:',sv^.name,' count:',count,' value:',sv^.value);
|
//Writeln('>sem_post:',sv^.name,' count:',count,' value:',sv^.value);
|
||||||
|
|
||||||
if (count>sv^.max) or (sv^.value>(sv^.max-count)) then
|
if (count>sv^.max) {or (sv^.value>(sv^.max-count))} then
|
||||||
begin
|
begin
|
||||||
|
//Writeln('EINVAL sem_post:',sv^.name,' count:',count,' value:',sv^.value);
|
||||||
spin_unlock(sv^.lock);
|
spin_unlock(sv^.lock);
|
||||||
Exit(EINVAL);
|
Exit(EINVAL);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if (sv^.value>(sv^.max-count)) then
|
||||||
|
begin
|
||||||
|
//Writeln('EOVERFLOW sem_post:',sv^.name,' count:',count,' value:',sv^.value);
|
||||||
|
spin_unlock(sv^.lock);
|
||||||
|
Exit(EOVERFLOW);
|
||||||
|
end;
|
||||||
|
|
||||||
waiters_count:=-sv^.value;
|
waiters_count:=-sv^.value;
|
||||||
Inc(sv^.value,count);
|
Inc(sv^.value,count);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue