mirror of
https://github.com/asticode/go-astiav.git
synced 2025-10-05 08:06:59 +08:00
IOInterrupter actions are now atomic
This commit is contained in:
11
atomic.c
Normal file
11
atomic.c
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include <stdatomic.h>
|
||||||
|
|
||||||
|
int astiavAtomicLoadInt(atomic_int* i)
|
||||||
|
{
|
||||||
|
return atomic_load(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void astiavAtomicStoreInt(atomic_int* i, int v)
|
||||||
|
{
|
||||||
|
return atomic_store(i, v);
|
||||||
|
}
|
4
atomic.h
Normal file
4
atomic.h
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#include <stdatomic.h>
|
||||||
|
|
||||||
|
int astiavAtomicLoadInt(atomic_int* i);
|
||||||
|
void astiavAtomicStoreInt(atomic_int* i, int v);
|
@@ -1,13 +1,14 @@
|
|||||||
#include <libavformat/avio.h>
|
#include <libavformat/avio.h>
|
||||||
#include <libavutil/mem.h>
|
#include <libavutil/mem.h>
|
||||||
|
#include <stdatomic.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
int astiavInterruptCallback(void *ret)
|
int astiavInterruptCallback(void *ret)
|
||||||
{
|
{
|
||||||
return *((int*)ret);
|
return atomic_load((atomic_int*)ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
AVIOInterruptCB* astiavNewInterruptCallback(int *ret)
|
AVIOInterruptCB* astiavNewInterruptCallback(atomic_int *ret)
|
||||||
{
|
{
|
||||||
AVIOInterruptCB* c = av_malloc(sizeof(AVIOInterruptCB));
|
AVIOInterruptCB* c = av_malloc(sizeof(AVIOInterruptCB));
|
||||||
c->callback = astiavInterruptCallback;
|
c->callback = astiavInterruptCallback;
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package astiav
|
package astiav
|
||||||
|
|
||||||
|
//#include "atomic.h"
|
||||||
//#include "io_interrupter.h"
|
//#include "io_interrupter.h"
|
||||||
//#include <libavutil/mem.h>
|
//#include <libavutil/mem.h>
|
||||||
//#include <stdlib.h>
|
//#include <stdlib.h>
|
||||||
@@ -8,7 +9,7 @@ import "unsafe"
|
|||||||
|
|
||||||
type IOInterrupter struct {
|
type IOInterrupter struct {
|
||||||
c *C.AVIOInterruptCB
|
c *C.AVIOInterruptCB
|
||||||
i C.int
|
i C.atomic_int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIOInterrupter() *IOInterrupter {
|
func NewIOInterrupter() *IOInterrupter {
|
||||||
@@ -25,13 +26,13 @@ func (i *IOInterrupter) Free() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *IOInterrupter) Interrupt() {
|
func (i *IOInterrupter) Interrupt() {
|
||||||
i.i = 1
|
C.astiavAtomicStoreInt(&i.i, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IOInterrupter) Interrupted() bool {
|
func (i *IOInterrupter) Interrupted() bool {
|
||||||
return i.i == 1
|
return C.astiavAtomicLoadInt(&i.i) == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IOInterrupter) Resume() {
|
func (i *IOInterrupter) Resume() {
|
||||||
i.i = 0
|
C.astiavAtomicStoreInt(&i.i, 0)
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
#include <libavformat/avio.h>
|
#include <libavformat/avio.h>
|
||||||
|
#include <stdatomic.h>
|
||||||
|
|
||||||
int astiavInterruptCallback(void *ret);
|
int astiavInterruptCallback(void *ret);
|
||||||
AVIOInterruptCB* astiavNewInterruptCallback(int *ret);
|
AVIOInterruptCB* astiavNewInterruptCallback(atomic_int *ret);
|
Reference in New Issue
Block a user