-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit introduces IO multiplexing for read/write operations performed in the SCO thread. From now on, every IO operation is performed only when the corresponding file descriptor is ready for particular IO operation. Also, it covers read/write error checking in a more correct way. For a simplification of a linear FIFO-like buffer usage, there is a separate shared piece of code. Due to simplicity and the usage of the preprocessor, this buffer wrapper should have essentially none performance impact.
- Loading branch information
Showing
10 changed files
with
255 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* BlueALSA - ffb.c | ||
* Copyright (c) 2016-2017 Arkadiusz Bokowy | ||
* | ||
* This file is a part of bluez-alsa. | ||
* | ||
* This project is licensed under the terms of the MIT license. | ||
* | ||
*/ | ||
|
||
#include "shared/ffb.h" | ||
|
||
#include <stdlib.h> | ||
|
||
|
||
/** | ||
* Allocated resources for FIFO-like buffer. | ||
* | ||
* @param ffb Pointer to the buffer structure which should be initialized. | ||
* @param size Size of the buffer in bytes. | ||
* @return On success this function returns 0. Otherwise, -1 is returned and | ||
* errno is set to indicate the error. */ | ||
int ffb_init(struct ffb *ffb, size_t size) { | ||
if ((ffb->data = ffb->tail = malloc(size)) == NULL) | ||
return -1; | ||
ffb->size = size; | ||
return 0; | ||
} | ||
|
||
/** | ||
* Free resources allocated by the ffb_init(). | ||
* | ||
* @param ffb Pointer to initialized buffer structure. */ | ||
void ffb_free(struct ffb *ffb) { | ||
if (ffb->data == NULL) | ||
return; | ||
free(ffb->data); | ||
ffb->data = NULL; | ||
ffb->tail = NULL; | ||
ffb->size = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* BlueALSA - ffb.h | ||
* Copyright (c) 2016-2017 Arkadiusz Bokowy | ||
* | ||
* This file is a part of bluez-alsa. | ||
* | ||
* This project is licensed under the terms of the MIT license. | ||
* | ||
*/ | ||
|
||
#ifndef BLUEALSA_SHARED_FFB_H_ | ||
#define BLUEALSA_SHARED_FFB_H_ | ||
|
||
#include <stddef.h> | ||
#include <string.h> | ||
|
||
/** | ||
* Convenience wrapper for FIFO-like buffer. */ | ||
struct ffb { | ||
/* pointer to the allocated memory block */ | ||
unsigned char *data; | ||
/* pointer to the end of data */ | ||
unsigned char *tail; | ||
/* size of the buffer */ | ||
size_t size; | ||
}; | ||
|
||
int ffb_init(struct ffb *ffb, size_t size); | ||
void ffb_free(struct ffb *ffb); | ||
|
||
#define ffb_len_in(p) ((p)->size - ffb_len_out(p)) | ||
#define ffb_len_out(p) ((size_t)((p)->tail - (p)->data)) | ||
|
||
#define ffb_seek(p, len) ((p)->tail += len) | ||
#define ffb_rewind(p, len) do { \ | ||
memmove((p)->data, (p)->data + (len), ffb_len_out(p) - (len)); \ | ||
(p)->tail -= len; \ | ||
} while (0) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.