Calling mCoreThreadJoin to avoid crash.
This commit is contained in:
parent
976cf3d92f
commit
05fff066ef
@ -15,6 +15,7 @@ struct msClientConnectionData {
|
||||
int clientFd;
|
||||
struct msCoreController *coreController;
|
||||
pthread_mutex_t *mutexSendPacket;
|
||||
struct timespec *lastFrameDate;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -28,4 +29,6 @@ msClientConnectionDataNew(size_t numberOfThread, int clientFd);
|
||||
|
||||
void
|
||||
msClientConnectionDataDestroy(struct msClientConnectionData **data);
|
||||
|
||||
extern pthread_mutex_t mutexClientConnection;
|
||||
#endif
|
||||
|
@ -2,6 +2,9 @@
|
||||
|
||||
#include <msgba/core_controller.h>
|
||||
#include <msgba/client_connection_data.h>
|
||||
|
||||
pthread_mutex_t mutexClientConnection = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
struct msClientConnectionData *
|
||||
msClientConnectionDataNew(size_t numberOfThread, int clientFd) {
|
||||
struct msClientConnectionData *data = malloc (sizeof *data);
|
||||
@ -9,6 +12,7 @@ msClientConnectionDataNew(size_t numberOfThread, int clientFd) {
|
||||
data->clientFd = clientFd;
|
||||
data->coreController = NULL;
|
||||
data->mutexSendPacket = malloc(sizeof *data->mutexSendPacket);
|
||||
data->lastFrameDate = calloc(sizeof *data->lastFrameDate, 1);
|
||||
pthread_mutex_init(data->mutexSendPacket, NULL);
|
||||
return data;
|
||||
}
|
||||
|
@ -76,10 +76,8 @@ msCoreControllerDestroy(struct msCoreController **controller_ptr) {
|
||||
if (controller_ptr && *controller_ptr) {
|
||||
struct msCoreController *controller = *controller_ptr;
|
||||
|
||||
if (mCoreThreadHasStarted(&controller->threadContext)
|
||||
&& !mCoreThreadHasExited(&controller->threadContext)) {
|
||||
mCoreThreadEnd(&controller->threadContext);
|
||||
}
|
||||
mCoreThreadEnd(&controller->threadContext);
|
||||
mCoreThreadJoin(&controller->threadContext);
|
||||
if (controller->threadContext.core) {
|
||||
struct mCore *core = controller->threadContext.core;
|
||||
core->deinit(core);
|
||||
|
@ -96,10 +96,11 @@ int main(int argc, char **argv) {
|
||||
while (connected_clients == MAX_NUMBER_OF_THREADS) {
|
||||
pthread_cond_wait(&cond_client_number_decreased, &mutex_number_connections);
|
||||
}
|
||||
connected_clients++;
|
||||
pthread_mutex_unlock(&mutex_number_connections);
|
||||
struct msClientConnectionData *data = msClientConnectionDataNew(number_of_threads, client_fd);
|
||||
|
||||
pthread_create(&pthread_client_connections[connected_clients++], &attributes,
|
||||
pthread_create(&pthread_client_connections[connected_clients], &attributes,
|
||||
&handleClientConnection, (void *)data);
|
||||
pthread_mutex_unlock(&mutex_number_connections);
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ return_ms_packet_write:
|
||||
|
||||
bool
|
||||
msPacketSend(const struct msPacket *const packet, struct msClientConnectionData *const data) {
|
||||
if (!data->mutexSendPacket) {
|
||||
if (!data) {
|
||||
return false;
|
||||
}
|
||||
pthread_mutex_lock(data->mutexSendPacket);
|
||||
|
@ -1,3 +1,6 @@
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/signal.h>
|
||||
|
||||
#include <msgba/packet/send_frame.h>
|
||||
@ -28,14 +31,33 @@ msThreadCallbackStart(struct mCoreThread *threadContext) {
|
||||
}
|
||||
void
|
||||
msThreadCallbackSetFrame(struct mCoreThread *threadContext) {
|
||||
#define SEC_TO_NANO(sec) \
|
||||
(((uint64_t)sec) * 1000 * 1000 * 1000)
|
||||
struct msClientConnectionData *data = (struct msClientConnectionData *)threadContext->userData;
|
||||
unsigned int stride = data->coreController->stride;
|
||||
color_t *outputBuffer = data->coreController->outputBuffer;
|
||||
unsigned int stride;
|
||||
color_t *outputBuffer;
|
||||
unsigned width, height;
|
||||
unsigned char *raw_data = NULL;
|
||||
size_t raw_data_len = 0;
|
||||
struct msPacketSendFrame *send_frame = NULL;
|
||||
struct msPacket *packet = NULL;
|
||||
struct timespec current_date;
|
||||
timespec_get(¤t_date, TIME_UTC);
|
||||
uint64_t nano_current = SEC_TO_NANO(current_date.tv_sec % 1000) + current_date.tv_nsec;
|
||||
uint64_t nano_last = SEC_TO_NANO(data->lastFrameDate->tv_sec % 1000) + data->lastFrameDate->tv_nsec + (SEC_TO_NANO(1) / 60);
|
||||
|
||||
if (!data || !data->coreController) {
|
||||
goto return_ms_thread_callback_set_frame;
|
||||
}
|
||||
stride = data->coreController->stride;
|
||||
outputBuffer = data->coreController->outputBuffer;
|
||||
|
||||
while (nano_current < nano_last && nano_last != 0 && nano_last - nano_current < SEC_TO_NANO(10)) {
|
||||
usleep(500);
|
||||
timespec_get(¤t_date, TIME_UTC);
|
||||
nano_current = SEC_TO_NANO(current_date.tv_sec % 1000) + current_date.tv_nsec;
|
||||
}
|
||||
*data->lastFrameDate = current_date;
|
||||
|
||||
data->coreController->threadContext.core->desiredVideoDimensions(data->coreController->threadContext.core, &width, &height);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user