コード例 #1
0
static void rtmp_stream_destroy(void *data)
{
	struct rtmp_stream *stream = data;

	if (stopping(stream) && !connecting(stream)) {
		pthread_join(stream->send_thread, NULL);

	} else if (connecting(stream) || active(stream)) {
		if (stream->connecting)
			pthread_join(stream->connect_thread, NULL);

		os_event_signal(stream->stop_event);

		if (active(stream)) {
			os_sem_post(stream->send_sem);
			obs_output_end_data_capture(stream->output);
			pthread_join(stream->send_thread, NULL);
		}
	}

	if (stream) {
		free_packets(stream);
		dstr_free(&stream->path);
		dstr_free(&stream->key);
		dstr_free(&stream->username);
		dstr_free(&stream->password);
		dstr_free(&stream->encoder_name);
		os_event_destroy(stream->stop_event);
		os_sem_destroy(stream->send_sem);
		pthread_mutex_destroy(&stream->packets_mutex);
		circlebuf_free(&stream->packets);
		bfree(stream);
	}
}
コード例 #2
0
ファイル: log.c プロジェクト: EmuxEvans/sailing
int log_close(LOG_HANDLE ctx)
{
	int ret;

	if(ctx->stream.buf!=NULL) {
		os_sem_post(&ctx->stream.inque);
		os_thread_wait(ctx->stream.thread, NULL);

		os_sem_destroy(&ctx->stream.inque);
		os_sem_destroy(&ctx->stream.ouque);
		os_mutex_destroy(&ctx->stream.mtx);
	}

	ret = map[ctx->type].func_close(ctx);
	free(ctx);
	return ret;
}
コード例 #3
0
static void rtmp_stream_destroy(void *data)
{
	struct rtmp_stream *stream = data;

	if (stopping(stream) && !connecting(stream)) {
		pthread_join(stream->send_thread, NULL);

	} else if (connecting(stream) || active(stream)) {
		if (stream->connecting)
			pthread_join(stream->connect_thread, NULL);

		stream->stop_ts = 0;
		os_event_signal(stream->stop_event);

		if (active(stream)) {
			os_sem_post(stream->send_sem);
			obs_output_end_data_capture(stream->output);
			pthread_join(stream->send_thread, NULL);
		}
	}

	free_packets(stream);
	dstr_free(&stream->path);
	dstr_free(&stream->key);
	dstr_free(&stream->username);
	dstr_free(&stream->password);
	dstr_free(&stream->encoder_name);
	dstr_free(&stream->bind_ip);
	os_event_destroy(stream->stop_event);
	os_sem_destroy(stream->send_sem);
	pthread_mutex_destroy(&stream->packets_mutex);
	circlebuf_free(&stream->packets);
#ifdef TEST_FRAMEDROPS
	circlebuf_free(&stream->droptest_info);
#endif

	os_event_destroy(stream->buffer_space_available_event);
	os_event_destroy(stream->buffer_has_data_event);
	os_event_destroy(stream->socket_available_event);
	os_event_destroy(stream->send_thread_signaled_exit);
	pthread_mutex_destroy(&stream->write_buf_mutex);

	if (stream->write_buf)
		bfree(stream->write_buf);
	bfree(stream);
}
コード例 #4
0
void video_output_close(video_t *video)
{
	if (!video)
		return;

	video_output_stop(video);

	for (size_t i = 0; i < video->inputs.num; i++)
		video_input_free(&video->inputs.array[i]);
	da_free(video->inputs);

	for (size_t i = 0; i < video->info.cache_size; i++)
		video_frame_free((struct video_frame*)&video->cache[i]);

	os_sem_destroy(video->update_semaphore);
	pthread_mutex_destroy(&video->data_mutex);
	pthread_mutex_destroy(&video->input_mutex);
	bfree(video);
}
コード例 #5
0
ファイル: media.c プロジェクト: AmesianX/obs-studio
void mp_media_free(mp_media_t *media)
{
	if (!media)
		return;

	mp_media_stop(media);
	mp_kill_thread(media);
	mp_decode_free(&media->v);
	mp_decode_free(&media->a);
	avformat_close_input(&media->fmt);
	pthread_mutex_destroy(&media->mutex);
	os_sem_destroy(media->sem);
	sws_freeContext(media->swscale);
	av_freep(&media->scale_pic[0]);
	bfree(media->path);
	bfree(media->format_name);
	memset(media, 0, sizeof(*media));
	pthread_mutex_init_value(&media->mutex);
}
コード例 #6
0
ファイル: rtmp-stream.c プロジェクト: Reelapse/obs-studio
static void rtmp_stream_destroy(void *data)
{
	struct rtmp_stream *stream = data;

	if (stream->active)
		rtmp_stream_stop(data);

	if (stream) {
		free_packets(stream);
		dstr_free(&stream->path);
		dstr_free(&stream->key);
		dstr_free(&stream->username);
		dstr_free(&stream->password);
		os_event_destroy(stream->stop_event);
		os_sem_destroy(stream->send_sem);
		pthread_mutex_destroy(&stream->packets_mutex);
		circlebuf_free(&stream->packets);
		bfree(stream);
	}
}
コード例 #7
0
ファイル: ndevs.c プロジェクト: OznOg/OpenExanodes
int unexport_device(const exa_uuid_t *uuid)
{
  device_t *dev = find_device_from_uuid(uuid);
  if (dev == NULL)
    {
      exalog_error("can not remove unknown device with UUID = " UUID_FMT, UUID_VAL(uuid));
      return -CMD_EXP_ERR_UNKNOWN_DEVICE;
    }

  os_thread_mutex_lock(&nbd_server.mutex_edevs);
  /* ask the thread to terminate */
  dev->exit_thread = true;

  /* prevent any new IO to be put in device IO list */
  nbd_server.devices[dev->dev_index] = NULL;
  os_thread_mutex_unlock(&nbd_server.mutex_edevs);

  /* now we can join, because with the nbd_close_list()
   * we can assume was the disk thread will reach a cancelation point */
  os_thread_join(nbd_server.td_pid[dev->dev_index]);

  /* close the list used to disk queue */
  nbd_close_list(&dev->disk_queue);

  /* get back all header in the kernel exa_rdev to the free list and close the device */
  if (dev->handle != NULL)
      exa_rdev_handle_free(dev->handle);

  /* close the semaphore used by the disk */
  os_sem_destroy(&dev->lock_sem_disk);

  /* free used memory for the device */
  os_free(dev);

  return EXA_SUCCESS;
}
コード例 #8
0
static inline bool reset_semaphore(struct rtmp_stream *stream)
{
	os_sem_destroy(stream->send_sem);
	return os_sem_init(&stream->send_sem, 0) == 0;
}
コード例 #9
0
static void unmake_worker(struct worker *q)
{
     os_sem_destroy(&q->done);
     os_sem_destroy(&q->ready);
     X(ifree)(q);
}
コード例 #10
0
ファイル: thread.c プロジェクト: budden/sbcl-ita
static void
undo_init_new_thread(struct thread *th, init_thread_data *scribble)
{
    int lock_ret;

    /* Kludge: Changed the order of some steps between the safepoint/
     * non-safepoint versions of this code.  Can we unify this more?
     */
#ifdef LISP_FEATURE_SB_SAFEPOINT
    block_blockable_signals(0);
    gc_alloc_update_page_tables(BOXED_PAGE_FLAG, &th->alloc_region);
#if defined(LISP_FEATURE_SB_SAFEPOINT_STRICTLY) && !defined(LISP_FEATURE_WIN32)
    gc_alloc_update_page_tables(BOXED_PAGE_FLAG, &th->sprof_alloc_region);
#endif
    pop_gcing_safety(&scribble->safety);
    lock_ret = pthread_mutex_lock(&all_threads_lock);
    gc_assert(lock_ret == 0);
    unlink_thread(th);
    lock_ret = pthread_mutex_unlock(&all_threads_lock);
    gc_assert(lock_ret == 0);
#else
    /* Block GC */
    block_blockable_signals(0);
    set_thread_state(th, STATE_DEAD);

    /* SIG_STOP_FOR_GC is blocked and GC might be waiting for this
     * thread, but since we are already dead it won't wait long. */
    lock_ret = pthread_mutex_lock(&all_threads_lock);
    gc_assert(lock_ret == 0);

    gc_alloc_update_page_tables(BOXED_PAGE_FLAG, &th->alloc_region);
#if defined(LISP_FEATURE_SB_SAFEPOINT_STRICTLY) && !defined(LISP_FEATURE_WIN32)
    gc_alloc_update_page_tables(BOXED_PAGE_FLAG, &th->sprof_alloc_region);
#endif
    unlink_thread(th);
    pthread_mutex_unlock(&all_threads_lock);
    gc_assert(lock_ret == 0);
#endif

    arch_os_thread_cleanup(th);

#ifndef LISP_FEATURE_SB_SAFEPOINT
    os_sem_destroy(th->state_sem);
    os_sem_destroy(th->state_not_running_sem);
    os_sem_destroy(th->state_not_stopped_sem);
#endif


#ifdef LISP_FEATURE_MACH_EXCEPTION_HANDLER
    mach_lisp_thread_destroy(th);
#endif

#if defined(LISP_FEATURE_WIN32)
    int i;
    for (i = 0; i<
             (int) (sizeof(th->private_events.events)/
                    sizeof(th->private_events.events[0])); ++i) {
      CloseHandle(th->private_events.events[i]);
    }
    TlsSetValue(OUR_TLS_INDEX,NULL);
#endif

    /* Undo the association of the current pthread to its `struct thread',
     * such that we can call arch_os_get_current_thread() later in this
     * thread and cleanly get back NULL. */
#ifdef LISP_FEATURE_GCC_TLS
    current_thread = NULL;
#else
    pthread_setspecific(specials, NULL);
#endif
}
コード例 #11
0
ファイル: mbed_usbserial.cpp プロジェクト: kphannan/openmrn
 ~MbedRawUSBSerial()
 {
     os_sem_destroy(&rxSem);
 }
コード例 #12
0
ファイル: os__process.c プロジェクト: osrf/opensplice
os_result
os_procCreate(
    const char *executable_file,
    const char *name,
    const char *arguments,
    os_procAttr *procAttr,
    os_procId *procId)
{
    int procTaskId;
    int sched_policy;
    os_result rv = os_resultSuccess;
    os_procContextData process_procContextData;
    os_int32 startRoutine = 0;
    os_int32 pOptions,privateSet;
    os_int32 len,i=0,n=0;
    char *converted = NULL;

    assert(executable_file != NULL);
    assert(name != NULL);
    assert(arguments != NULL);
    assert(procAttr != NULL);
    assert(procId != NULL);

    len = strlen(arguments);
    converted = (char*)os_malloc(len+1);
    for (; i < len ; i++)
    {
       if (arguments[i] != '\"')
       {
          converted[n] = arguments[i];
          n++;
       }
    }
    converted[n] = '\0';
    pOptions = 0;
    privateSet = 0;
    taskOptionsGet(taskIdSelf(),&pOptions);
    if ((pOptions & VX_PRIVATE_ENV) == 0)
    {
        envPrivateCreate(taskIdSelf(), 0);
        privateSet = 1;
    }
    putenv("SPLICE_NEW_PROCESS=no");

    if (procAttr->schedClass == OS_SCHED_REALTIME) {
        sched_policy = SCHED_FIFO;
    } else if (procAttr->schedClass == OS_SCHED_TIMESHARE) {
        return os_resultInvalid;
    } else if (procAttr->schedClass == OS_SCHED_DEFAULT) {
        sched_policy = SCHED_OTHER;
    } else {
        return os_resultInvalid;
    }

    if ((procAttr->schedPriority > VXWORKS_PRIORITY_MIN) ||
        (procAttr->schedPriority < VXWORKS_PRIORITY_MAX) ) {
        return os_resultInvalid;
    }


    {
      os_library binlib;
      os_libraryAttr attr;

      os_libraryAttrInit(&attr);
      /* Dynamic load of services is a special case, so try just static via
         os_libraryOpen */
      attr.staticLibOnly=1;
      binlib = os_libraryOpen( executable_file, &attr);
      /* FIXME existing use of os_int32 for pointer is CRAZY!! */
      if ( binlib != NULL )
      {
         startRoutine = (os_int32)os_libraryGetSymbol( binlib, executable_file );
      }

      if ( startRoutine == 0 && os_dynamicLibPlugin != NULL )
      {
         startRoutine = (os_uint32)os_dynamicLibPlugin->dlp_loadLib( executable_file );
      }

      if ( startRoutine == 0 )
      {
         OS_REPORT(OS_ERROR, "os_procCreate", 1,
                       "Unable to load %s (%s)",
                       executable_file, name);
     rv = os_resultInvalid;
      }
    }

    if (rv == os_resultSuccess)
    {
        process_procContextData = (os_procContextData )os_malloc((size_t)OS_SIZEOF(os_procContextData));
        if (process_procContextData == (os_procContextData) NULL) {
            OS_REPORT(OS_WARNING, "os_procCreate", 1,
                        "malloc failed with error %d (%s, %s)",
                        os_getErrno(), executable_file, name);
            rv = os_resultInvalid;
        }
        else
        {
#if defined ( _WRS_VXWORKS_MAJOR ) && ( _WRS_VXWORKS_MAJOR > 6 ) || ( _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR > 8 )
        /* the blockParent semaphore is used to prevent this task exiting before the spawned task
           has completed copying its environ. */
        os_sem_t blockParent;
        os_sem_init( &blockParent, 0);
#endif
            os_procInit(process_procContextData, name, executable_file, converted);
            process_procContextData->procAttrPrio = procAttr->schedPriority;
            procTaskId = taskSpawn((char *)name, procAttr->schedPriority,
                                   VX_FP_TASK
#if ! defined ( _WRS_VXWORKS_MAJOR ) || _WRS_VXWORKS_MAJOR < 6 || ( _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR < 9 )
/* VX_PRIVATE_ENV flag is no longer functional in vxworks 6.9 */
                   | VX_PRIVATE_ENV
#endif
#if defined ( VXWORKS_55 ) || defined ( VXWORKS_54 )
                                   | VX_STDIO | VX_DEALLOC_STACK
#endif
                                   ,
                                   VXWORKS_PROC_DEFAULT_STACK,
                                   (FUNCPTR)os_procWrapper,
                                   (int)process_procContextData, (int)process_procContextData->executable,
                                   (int)startRoutine, (int)process_procContextData->arguments, taskIdSelf(),
#if ! defined ( _WRS_VXWORKS_MAJOR ) || _WRS_VXWORKS_MAJOR < 6 || ( _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR < 9 )
                                   0,
#else
                                   &blockParent,
#endif
 0, 0, 0, 0);
#if defined ( _WRS_VXWORKS_MAJOR ) && ( _WRS_VXWORKS_MAJOR > 6 || ( _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR > 8 ) )
            os_sem_wait(&blockParent);
            os_sem_destroy(&blockParent);
#endif
            if (procTaskId == ERROR)
            {
                os_free(process_procContextData);
                rv = os_resultInvalid;
            }
            else
            {
                *procId = *(os_procId *)&process_procContextData;
                rv = os_resultSuccess;
            }
        }
    }

    putenv("SPLICE_NEW_PROCESS=empty");
    if ( privateSet == 1)
    {
        envPrivateDestroy(taskIdSelf());
    }
    os_free(converted);
    return rv;
}
コード例 #13
0
ファイル: ndevs.c プロジェクト: OznOg/OpenExanodes
/* A new device is handled by the server, do the init operations in order to make the device usable */
int export_device(const exa_uuid_t *uuid, char *device_path)
{
    device_t *dev;
    int i, err;

    /* If device was already exported, do nothing */
    if (find_device_from_uuid(uuid) != NULL)
        return EXA_SUCCESS;

    dev = os_malloc(sizeof(struct device));
    if (dev == NULL)
    {
        err = -NBD_ERR_MALLOC_FAILED;
        goto error;
    }

    dev->handle = NULL;
    err = -CMD_EXP_ERR_OPEN_DEVICE;

    dev->handle = exa_rdev_handle_alloc(device_path);
    if (dev->handle == NULL)
        goto error;

    err = get_nb_sectors(device_path, &dev->size_in_sectors);
    if (err != EXA_SUCCESS)
        goto error;

    uuid_copy(&dev->uuid, uuid);
    strlcpy(dev->path, device_path, sizeof(dev->path));

    for (i = 0; i < NBMAX_DISKS_PER_NODE; i++)
        if (nbd_server.devices[i] == NULL)
            break;

    if (i >= NBMAX_DISKS_PER_NODE)
    {
        exalog_error("maximum number of exportable devices exceeded");
        err = -NBD_ERR_NB_RDEVS_CREATED;
    }

    dev->dev_index = i;
    dev->exit_thread = false;

    nbd_init_list(&nbd_server.list_root, &dev->disk_queue);

    /* resource needed to lock/unlock a zone */
    os_sem_init (&dev->lock_sem_disk, 0);

    /* launch disk thread (TD) */
    if (!exathread_create_named(&nbd_server.td_pid[dev->dev_index],
                                NBD_THREAD_STACK_SIZE + MIN_THREAD_STACK_SIZE,
                                exa_td_main, dev, "TD_thread"))
    {
        os_sem_destroy(&dev->lock_sem_disk);
        err = -NBD_ERR_THREAD_CREATION;
        goto error;
    }

    nbd_server.devices[dev->dev_index] = dev;

    return EXA_SUCCESS;

error:
    if (dev != NULL)
    {
        if (dev->handle != NULL)
            exa_rdev_handle_free(dev->handle);
        os_free(dev);
    }
    return err;
}