本文整理汇总了C++中semaphore_destroy函数的典型用法代码示例。如果您正苦于以下问题:C++ semaphore_destroy函数的具体用法?C++ semaphore_destroy怎么用?C++ semaphore_destroy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了semaphore_destroy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _dispatch_semaphore_dispose
void
_dispatch_semaphore_dispose(dispatch_object_t dou)
{
dispatch_semaphore_t dsema = dou._dsema;
if (dsema->dsema_value < dsema->dsema_orig) {
DISPATCH_CLIENT_CRASH(
"Semaphore/group object deallocated while in use");
}
#if USE_MACH_SEM
kern_return_t kr;
if (dsema->dsema_port) {
kr = semaphore_destroy(mach_task_self(), dsema->dsema_port);
DISPATCH_SEMAPHORE_VERIFY_KR(kr);
}
if (dsema->dsema_waiter_port) {
kr = semaphore_destroy(mach_task_self(), dsema->dsema_waiter_port);
DISPATCH_SEMAPHORE_VERIFY_KR(kr);
}
#elif USE_POSIX_SEM
int ret = sem_destroy(&dsema->dsema_sem);
DISPATCH_SEMAPHORE_VERIFY_RET(ret);
#endif
}
示例2: _ringbuffer_stream_deallocate
static void _ringbuffer_stream_deallocate( stream_t* stream )
{
ringbuffer_stream_t* buffer = (ringbuffer_stream_t*)stream;
semaphore_destroy( &buffer->signal_read );
semaphore_destroy( &buffer->signal_write );
}
示例3: miniroute_initialize
/* Performs any initialization of the miniroute layer, if required. */
void
miniroute_initialize()
{
network_get_my_address(hostaddr);
discovery_alarm = -1;
intrpt_buffer = queue_new();
intrpt_sig = semaphore_create();
discovery_mutex = semaphore_create();
discovery_sig = semaphore_create();
route_cache = miniroute_cache_new(65536, SIZE_OF_ROUTE_CACHE, MINIROUTE_CACHED_ROUTE_EXPIRE);
disc_cache = miniroute_cache_new(65536, SIZE_OF_ROUTE_CACHE, MINIROUTE_CACHED_ROUTE_EXPIRE * 10);
if (NULL == intrpt_buffer || NULL == intrpt_sig || NULL == route_cache
|| NULL == discovery_mutex || NULL == discovery_sig) {
queue_free(intrpt_buffer);
semaphore_destroy(intrpt_sig);
semaphore_destroy(discovery_mutex);
semaphore_destroy(discovery_sig);
miniroute_cache_destroy(route_cache);
return;
}
semaphore_initialize(intrpt_sig, 0);
semaphore_initialize(discovery_mutex, 1);
semaphore_initialize(discovery_sig, 0);
network_get_my_address(hostaddr);
minithread_fork(miniroute_control, NULL);
}
示例4: delete_route_request
/* Delete the route request struct */
void delete_route_request(route_request_t route_request)
{
if (route_request->interrupt_arg != NULL)
free(route_request->interrupt_arg);
semaphore_destroy(route_request->initiator_sem);
semaphore_destroy(route_request->waiting_sem);
free(route_request);
}
示例5: minisocket_destroy
//Destroys minisockets
void minisocket_destroy(minisocket_t minisocket, int FIN) {
int portNumber;
int i, threads;
interrupt_level_t prev_level;
minisocket_error error;
if (minisocket == NULL)
return;
portNumber = minisocket->port_number;
semaphore_P(destroy_semaphore);
minisocket->waiting = TCP_PORT_WAITING_TO_CLOSE;
if (minisockets[portNumber] == NULL)
return;
semaphore_V(minisocket->packet_ready);
semaphore_P(minisocket->mutex);
if (minisockets[portNumber] == NULL)
return;
if (FIN == 1) {
transmit_packet(minisocket, minisocket->destination_addr, minisocket->destination_port,
1, MSG_FIN, 0, NULL, &error);
}
minisocket->status = TCP_PORT_CLOSING;
prev_level = set_interrupt_level(DISABLED);
threads = minisocket->num_waiting_on_mutex;
for (i = 0; i < threads; i++)
{
semaphore_V(minisocket->mutex);
i++;
}
set_interrupt_level(prev_level);
minisockets[portNumber] = NULL;
semaphore_destroy(minisocket->wait_for_ack_semaphore);
semaphore_destroy(minisocket->mutex);
semaphore_destroy(minisocket->packet_ready);
if (minisocket->data_length != 0)
free(minisocket->data_buffer);
queue_free(minisocket->waiting_packets);
free(minisocket);
semaphore_V(destroy_semaphore);
}
示例6: end
static void end(void)
{
shared_memory_destroy(shm_id);
semaphore_destroy(semaphore_1);
semaphore_destroy(semaphore_2);
/*semaphore_destroy(consumer_lock);
semaphore_destroy(producer_lock);
semaphore_destroy(free_id);
semaphore_destroy(busy_id);*/
}
示例7: main
int
main(void)
{
pthread_t pthread1, pthread2, pthread3;
semaphore_t* sem = g_sem;
kern_return_t kr;
setbuf(stdout, NULL);
kr = semaphore_create(mach_task_self(), &sem[0], SYNC_POLICY_FIFO, 0);
OUT_ON_MACH_ERROR("semaphore_create", kr);
kr = semaphore_create(mach_task_self(), &sem[1], SYNC_POLICY_FIFO, 0);
OUT_ON_MACH_ERROR("semaphore_create", kr);
(void)pthread_create(&pthread1, (const pthread_attr_t *)0,
start_routine, (void *) 0);
printf("created thread1=%lx\n", 0);
(void)pthread_create(&pthread2, (const pthread_attr_t *)0,
start_routine, (void *) 1);
printf("created thread2=%lx\n", 1);
(void)pthread_create(&pthread3, (const pthread_attr_t *)0,
start_routine, (void *) 2);
printf("created thread3=%lx\n", 2);
// wait until all three threads are ready
SEMAPHORE_WAIT(sem[1], 3);
// printf("main: about to signal thread3\n");
// semaphore_signal_thread(sem[0], pthread_mach_thread_np(pthread3));
// wait for thread3 to sem_signal()
// semaphore_wait(sem[1]);
sleep(1);
printf("main: about to signal all threads\n");
semaphore_signal_all(sem[0]);
// wait for thread1 and thread2 to sem_signal()
SEMAPHORE_WAIT(sem[1], 3);
out:
if (sem[0])
semaphore_destroy(mach_task_self(), sem[0]);
if (sem[1])
semaphore_destroy(mach_task_self(), sem[1]);
exit(kr);
}
示例8: main
int main(int argc, char *argv[])
{
int s, ns;
int semaphore_id;
int shared_memory_id = 0;
uint16_t port;
pid_t pid;
struct sockaddr_in client;
char *tmp_shm_addr;
shm_t *g_shm;
check_args(&argc, argv, 0);
port = (uint16_t) atoi(argv[1]);
create_tcp_socket(&s, port);
semaphore_id = semaphore_new(SEM_KEY);
v(semaphore_id, 1);
shared_memory_id = create_shared_memory(SHM_KEY);
tmp_shm_addr = associate_shared_memory(shared_memory_id);
g_shm = (shm_t *) tmp_shm_addr;
while (true) {
accept_new_connection(&s, &ns, &client);
if ((pid = fork()) == 0)
shandler(&ns, semaphore_id, client, g_shm);
else {
if (pid > 0)
fprintf(stderr, "#%d# Father - Created child process: %d\n", getpid(), pid);
else {
fprintf(stderr, "The fork() function has failed: %s!\n", strerror(errno));
shared_memory_destroy(shared_memory_id);
semaphore_destroy(semaphore_id);
exit(EXIT_FAILURE);
}
}
}
shared_memory_destroy(shared_memory_id);
semaphore_destroy(semaphore_id);
exit(EXIT_SUCCESS);
}
示例9: DECLARE_TEST
DECLARE_TEST( semaphore, threaded )
{
object_t thread[32];
int ith;
int failed_waits;
semaphore_test_t test;
semaphore_initialize( &test.read, 0 );
semaphore_initialize( &test.write, 0 );
test.loopcount = 128;
test.counter = 0;
for( ith = 0; ith < 32; ++ith )
{
thread[ith] = thread_create( semaphore_waiter, "semaphore_waiter", THREAD_PRIORITY_NORMAL, 0 );
thread_start( thread[ith], &test );
}
test_wait_for_threads_startup( thread, 32 );
failed_waits = 0;
for( ith = 0; ith < test.loopcount * 32; ++ith )
{
semaphore_post( &test.read );
thread_yield();
if( !semaphore_try_wait( &test.write, 200 ) )
{
failed_waits++;
EXPECT_TRUE( semaphore_wait( &test.write ) );
}
}
for( ith = 0; ith < 32; ++ith )
{
thread_terminate( thread[ith] );
thread_destroy( thread[ith] );
thread_yield();
}
test_wait_for_threads_exit( thread, 32 );
EXPECT_EQ( test.counter, test.loopcount * 32 );
EXPECT_EQ( failed_waits, 0 );
semaphore_destroy( &test.read );
semaphore_destroy( &test.write );
return 0;
}
示例10: minisocket_free
static void minisocket_free (minisocket_t * socket) {
network_interrupt_arg_t *packet = NULL;
while (queue_dequeue(socket->data, (void **)&packet) != -1) {
free(packet);
}
queue_free(socket->data);
socket->data = NULL;
semaphore_destroy(socket->data_ready);
semaphore_destroy(socket->wait_for_ack);
semaphore_destroy(socket->send_receive_mutex);
semaphore_P(ports_mutex);
ports[socket->local_port] = NULL;
semaphore_V(ports_mutex);
free(socket);
}
示例11: minisocket_initialize
/* Initializes the minisocket layer. */
void minisocket_initialize()
{
int i;
sock_array = (minisocket_t*)malloc(sizeof(struct minisocket)*NUM_SOCKETS);
if (!sock_array) {
return;
}
for (i = 0; i < NUM_SOCKETS; i++) {
sock_array[i] = NULL;
}
client_lock = semaphore_create();
if (!client_lock) {
free(sock_array);
return;
}
server_lock = semaphore_create();
if (!server_lock) {
free(sock_array);
semaphore_destroy(client_lock);
return;
}
semaphore_initialize(client_lock, 1);
semaphore_initialize(server_lock, 1);
network_get_my_address(my_addr);
curr_client_idx = CLIENT_START;
//printf("minisocket_initialize complete\n");
}
示例12: blockdevice_create
BLOCKDEVICEP
blockdevice_create(char *name, int blocksize, int numblocks)
{
BLOCKDEVICEP devp ;
int rc ;
if (blocksize != REAL_BLOCK_LENGTH) {
/*
** For now we simplify things and just force
** all blockdevices to have 1k block sizes.
** We can fix this assumption up later.
*/
return NULL ;
}
if (strlen(name) >= BLOCK_DEV_MAX_NAME_LEN) {
return NULL ;
}
devp = malloc(sizeof(BLOCKDEVICE)) ;
if (NULL == devp) {
return NULL ;
}
devp->name = malloc(strlen(name)+1) ;
if (NULL == devp->name) {
free(devp) ;
return NULL ;
}
devp->sem = semaphore_create(1234, 0) ;
devp->dirtysem = semaphore_create(1235, 0) ;
/*if (! devp->sem) {
free(devp) ;
return NULL ;
}*/
strcpy(devp->name, name) ;
devp->blocksize = blocksize ;
devp->numblocks = numblocks ;
devp->lastblockchecked = 0 ;
rc = shmem_open() ;
if (0 == rc) {
semaphore_destroy(devp->sem, 1) ;
free(devp->name) ;
free(devp) ;
return NULL ;
}
devp->bd = (struct SHMEM_BLOCK_OVERLAY *) shmem_get_memptr() ;
initialize_block_dev_shmem(devp->bd, blocksize, numblocks, name) ;
return devp ;
}
示例13: _dispatch_sema4_create_slow
void
_dispatch_sema4_create_slow(_dispatch_sema4_t *s4, int policy)
{
semaphore_t tmp = MACH_PORT_NULL;
_dispatch_fork_becomes_unsafe();
// lazily allocate the semaphore port
// Someday:
// 1) Switch to a doubly-linked FIFO in user-space.
// 2) User-space timers for the timeout.
#if DISPATCH_USE_OS_SEMAPHORE_CACHE
if (policy == _DSEMA4_POLICY_FIFO) {
tmp = (_dispatch_sema4_t)os_get_cached_semaphore();
if (!os_atomic_cmpxchg(s4, MACH_PORT_NULL, tmp, relaxed)) {
os_put_cached_semaphore((os_semaphore_t)tmp);
}
return;
}
#endif
kern_return_t kr = semaphore_create(mach_task_self(), &tmp, policy, 0);
DISPATCH_SEMAPHORE_VERIFY_KR(kr);
if (!os_atomic_cmpxchg(s4, MACH_PORT_NULL, tmp, relaxed)) {
kr = semaphore_destroy(mach_task_self(), tmp);
DISPATCH_SEMAPHORE_VERIFY_KR(kr);
}
}
示例14: semaphore_destroy
Semaphore::~Semaphore()
{
kern_return_t result = semaphore_destroy(mach_task_self(), mSemaphore);
if(KERN_SUCCESS != result)
LOGGER_ERR("org.sbooth.AudioEngine.Semaphore", "semaphore_destroy failed: " << mach_error_string(result));
}
示例15: syscall_sem_destroy
int syscall_sem_destroy(usr_sem_t* handle)
{
int i;
interrupt_status_t intr_status;
intr_status = _interrupt_disable();
spinlock_acquire(&usr_semaphore_table_slock);
/* Look through the user semaphore table for
* a usr_sem_t address matching the handle */
for(i = 0; i < MAX_USR_SEMAPHORES; i++) {
if(&usr_semaphore_table[i] == handle) {
/* Invalidate the kernel semaphore and set the entry
* in the userland semaphore table to empty */
semaphore_destroy(handle->sem);
usr_semaphore_table[i].sem = NULL;
spinlock_release(&usr_semaphore_table_slock);
_interrupt_set_state(intr_status);
return 0;
}
}
// If no match is found, return an error
spinlock_release(&usr_semaphore_table_slock);
_interrupt_set_state(intr_status);
return 1;
}