本文整理汇总了C++中semaphore_destroy函数的典型用法代码示例。如果您正苦于以下问题:C++ semaphore_destroy函数的具体用法?C++ semaphore_destroy怎么用?C++ semaphore_destroy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了semaphore_destroy函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:PSPDFKit-labs,项目名称:libdispatch,代码行数:25,代码来源:semaphore.c
示例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 );
}
开发者ID:NocturnDragon,项目名称:foundation_lib,代码行数:7,代码来源:ringbuffer.c
示例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);
}
开发者ID:DolphinWilly,项目名称:PortOSnix,代码行数:33,代码来源:miniroute.c
示例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);
}
开发者ID:pb376,项目名称:cs4411-p5,代码行数:10,代码来源:miniroute.c
示例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);
}
开发者ID:authentic4269,项目名称:4411P2,代码行数:58,代码来源:minisocket.c
示例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);*/
}
开发者ID:diegohdorta,项目名称:C,代码行数:10,代码来源:main.c
示例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);
}
开发者ID:010001111,项目名称:darling,代码行数:51,代码来源:mach_semaphore.c
示例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);
}
开发者ID:diegohdorta,项目名称:C,代码行数:51,代码来源:server.c
示例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;
}
开发者ID:apprisi,项目名称:foundation_lib,代码行数:49,代码来源:main.c
示例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);
}
开发者ID:Amanjot1507,项目名称:OS-Work,代码行数:15,代码来源:minisocket.c
示例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");
}
开发者ID:kentalabur,项目名称:egs,代码行数:28,代码来源:minisocket.c
示例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 ;
}
开发者ID:DEMONkill,项目名称:Nautilus,代码行数:60,代码来源:blockdevice.c
示例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);
}
}
开发者ID:linux-on-ibm-z,项目名称:swift-corelibs-libdispatch,代码行数:31,代码来源:lock.c
示例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));
}
开发者ID:LionelWang,项目名称:SFBAudioEngine,代码行数:7,代码来源:Semaphore.cpp
示例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;
}
开发者ID:hallundbaek,项目名称:buenos,代码行数:26,代码来源:usr_semaphore.c
示例16: queue_locked_free
void
queue_locked_free(queue_locked_t q)
{
if (q != NULL)
semaphore_destroy(q->lock);
free(q);
}
开发者ID:DolphinWilly,项目名称:PortOSnix,代码行数:7,代码来源:queue_locked.c
示例17: QueueSync
BGM_TaskQueue::~BGM_TaskQueue()
{
// Join the worker threads
QueueSync(kBGMTaskStopWorkerThread, /* inRunOnRealtimeThread = */ true);
QueueSync(kBGMTaskStopWorkerThread, /* inRunOnRealtimeThread = */ false);
// Destroy the semaphores
auto destroySemaphore = [] (semaphore_t inSemaphore) {
kern_return_t theError = semaphore_destroy(mach_task_self(), inSemaphore);
BGM_Utils::ThrowIfMachError("BGM_TaskQueue::~BGM_TaskQueue", "semaphore_destroy", theError);
};
destroySemaphore(mRealTimeThreadWorkQueuedSemaphore);
destroySemaphore(mNonRealTimeThreadWorkQueuedSemaphore);
destroySemaphore(mRealTimeThreadSyncTaskCompletedSemaphore);
destroySemaphore(mNonRealTimeThreadSyncTaskCompletedSemaphore);
BGM_Task* theTask;
// Delete the tasks in the non-realtime tasks free list
while((theTask = mNonRealTimeThreadTasksFreeList.pop_atomic()) != NULL)
{
delete theTask;
}
// Delete any tasks left on the non-realtime queue that need to be
while((theTask = mNonRealTimeThreadTasks.pop_atomic()) != NULL)
{
if(!theTask->IsSync())
{
delete theTask;
}
}
}
开发者ID:PwnArt1st,项目名称:BackgroundMusic,代码行数:35,代码来源:BGM_TaskQueue.cpp
示例18: minithread_sleep_with_timeout
/*
* sleep with timeout in milliseconds
*/
void minithread_sleep_with_timeout(int delay)
{
// Create the sleep semaphore
semaphore_t sleep_sem = semaphore_create();
interrupt_level_t prev_level; // ISO C90...
// Initialize it to a value of 0 so it can act as a way to signal threads
semaphore_initialize(sleep_sem, 0);
// Disable interrupts
prev_level = set_interrupt_level(DISABLED);
// Register the alarm
register_alarm(delay, &minithread_sleep_alarm_wakeup, sleep_sem);
// If, at this point, interrupts were enabled, we could context switch away
// the alarm could be triggered afterwards before the semaphore_P below was
// called (depending on this threads priority level, etc) and then when this
// thread finally calls semaphore_P(), it will hang forever.
// Therefore we have interrupts disabled.
// Wait on the sleep semaphore
semaphore_P(sleep_sem);
// Now that we've awoken, free the sleep semaphore
semaphore_destroy(sleep_sem);
// Restore the previous interrupt level
set_interrupt_level(prev_level); // is this necessary?
}
开发者ID:pb376,项目名称:cs4411-p6-submitted,代码行数:34,代码来源:minithread.c
示例19: main
main()
{
SEMAPHOREP sem ;
int rc ;
int i ;
sem = semaphore_open(1234) ;
if (!sem) {
printf("semaphore_open() failed\n") ;
exit(1) ;
}
for (i = 0; i < 10; i++) {
printf("Releasing semaphore iteration %d\n", i) ;
rc = semaphore_increment(sem) ;
if (! rc) {
printf("semaphore_increment() failed\n") ;
exit(1) ;
}
sleep(1) ;
}
rc = semaphore_destroy(sem, 0) ;
if (! rc) {
printf("semaphore_destroy(sem, 0) failed\n") ;
exit(1) ;
}
exit(0) ;
}
开发者ID:DEMONkill,项目名称:Nautilus,代码行数:31,代码来源:syg_semb.c
示例20: SemaphoreCloseHandle
BOOL SemaphoreCloseHandle(HANDLE handle) {
WINPR_SEMAPHORE *semaphore = (WINPR_SEMAPHORE *) handle;
if (!SemaphoreIsHandled(handle))
return FALSE;
#ifdef WINPR_PIPE_SEMAPHORE
if (semaphore->pipe_fd[0] != -1)
{
close(semaphore->pipe_fd[0]);
semaphore->pipe_fd[0] = -1;
if (semaphore->pipe_fd[1] != -1)
{
close(semaphore->pipe_fd[1]);
semaphore->pipe_fd[1] = -1;
}
}
#else
#if defined __APPLE__
semaphore_destroy(mach_task_self(), *((winpr_sem_t*) semaphore->sem));
#else
sem_destroy((winpr_sem_t*) semaphore->sem);
#endif
#endif
free(semaphore);
return TRUE;
}
开发者ID:JunaidLoonat,项目名称:FreeRDP,代码行数:30,代码来源:semaphore.c
注:本文中的semaphore_destroy函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论