From 8fbd574ef065d5d71c933bbb76d8817300fbb487 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 20 Feb 2007 15:48:04 +0000 Subject: * cygwin.din (sem_unlink): Export. * posix_ipc.cc: Include thread.h and semaphore.h. Remove TODO comment. (ipc_names): Add max_len member. Set to maximum length of the path before tacking on the prefix path. Set prefix path for named semaphors to /dev/shm, as on Linux. (enum ipc_type_t): Change sem to semaphore to avoid name conflicts. (check_path): Detect empty paths. Use ipc_names's max_len member. Use __small_sprintf to create full object path name. Special case semaphores. (ipc_cond_init): Drop superfluous strcpy. (class ipc_flock): New class to simplify file locking in subsequent code. (struct mq_hdr): Raise size of mqh_uname to allow adding a unique LUID to the name. (mq_open): Fix formatting. Create unique synchronization object names using AllocateLocallyUniqueId. (struct sem_finfo): New structure defining named semaphore file content. (sem_open): Move here. Rework implementation to allow kernel persistent implementation of POSIX named semaphores. (_sem_close): Implement sem_close. (sem_close): Move here. Just call _sem_close with do_close parameter set to true. (sem_unlink): New function. * pthread.cc (mangle_sem_name): Remove. (sem_open): Move to posix_ipc.cc. (sem_close): Ditto. * syscalls.cc (close_all_files): Call semaphore::terminate here. * thread.cc: Fix formatting. Rearrange semaphore functions so that they are close together. (semaphore::semaphore): Rework to play nicely with new named semaphore implementation. (semaphore::_terminate): Call _sem_close if semaphore is a named semaphore. (semaphore::destroy): Don't destroy named semaphores. Return EINVAL instead. (semaphore::close): Only destroy named semaphores. Return EINVAL otherwise. (semaphore::open): Rework to play nicely with new named semaphore implementation. Loop through existing semaphores to be able to return same sem_t pointer as a former call on the same named semaphore. (semaphore::getinternal): New function called from _sem_close. * thread.h (class List): Make mx and head public. (class semaphore): Fix formatting. Align method declarations with implementation in thread.cc. Add members used for named semaphores. (semaphore::terminate): New static method. * include/semaphore.h: Redefine SEM_FAILED. Fix formatting. (sem_unlink): Add declaration. * include/cygwin/version.h: Bump API minor number. --- winsup/cygwin/thread.h | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'winsup/cygwin/thread.h') diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h index c15ded478..a1dec1ff8 100644 --- a/winsup/cygwin/thread.h +++ b/winsup/cygwin/thread.h @@ -1,6 +1,6 @@ /* thread.h: Locking and threading module definitions - Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Red Hat, Inc. + Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007 Red Hat, Inc. Written by Marco Fuykschot Major update 2001 Robert Collins @@ -208,15 +208,15 @@ template class List mx.unlock (); } + fast_mutex mx; + list_node *head; + protected: void mx_init () { if (!mx.init ()) api_fatal ("Could not create mutex for list synchronisation."); } - - fast_mutex mx; - list_node *head; }; class pthread_key: public verifyable_object @@ -633,23 +633,30 @@ class semaphore: public verifyable_object public: static bool is_good_object(sem_t const *); /* API calls */ - static int init (sem_t * sem, int pshared, unsigned int value); - static int destroy (sem_t * sem); - static sem_t *open (const char *name, int oflag, mode_t mode, - unsigned int value); - static int wait (sem_t * sem); - static int post (sem_t * sem); - static int getvalue (sem_t * sem, int *sval); - static int trywait (sem_t * sem); - static int timedwait (sem_t * sem, const struct timespec *abstime); + static int init (sem_t *sem, int pshared, unsigned int value); + static int destroy (sem_t *sem); + static sem_t *open (unsigned long long hash, LUID luid, int fd, int oflag, + mode_t mode, unsigned int value, bool &wasopen); + static int close (sem_t *sem); + static int wait (sem_t *sem); + static int post (sem_t *sem); + static int getvalue (sem_t *sem, int *sval); + static int trywait (sem_t *sem); + static int timedwait (sem_t *sem, const struct timespec *abstime); + + static int getinternal (sem_t *sem, int *sfd, unsigned long long *shash, + LUID *sluid, unsigned int *sval); HANDLE win32_obj_id; int shared; long currentvalue; - char *name; + int fd; + unsigned long long hash; + LUID luid; + sem_t *sem; semaphore (int, unsigned int); - semaphore (const char *name, int oflag, mode_t mode, unsigned int value); + semaphore (unsigned long long, LUID, int, sem_t *, int, mode_t, unsigned int); ~semaphore (); class semaphore * next; @@ -658,6 +665,10 @@ public: semaphores.fixup_after_fork (); semaphores.for_each (&semaphore::_fixup_after_fork); } + static void terminate () + { + semaphores.for_each (&semaphore::_terminate); + } private: int _wait (); @@ -667,6 +678,7 @@ private: int _timedwait (const struct timespec *abstime); void _fixup_after_fork (); + void _terminate (); static List semaphores; }; -- cgit v1.2.3