⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thread.h

📁 cygwin, 著名的在win32下模拟unix操作系统的东东
💻 H
📖 第 1 页 / 共 2 页
字号:
/* thread.h: Locking and threading module definitions   Copyright 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.   Written by Marco Fuykschot <marco@ddi.nl>   Major update 2001 Robert Collins <rbtcollins@hotmail.com>This file is part of Cygwin.This software is a copyrighted work licensed under the terms of theCygwin license.  Please consult the file "CYGWIN_LICENSE" fordetails. */#ifndef _CYGNUS_THREADS_#define _CYGNUS_THREADS_#define LOCK_FD_LIST     1#define LOCK_MEMORY_LIST 2#define LOCK_MMAP_LIST   3#define LOCK_DLL_LIST    4#define WRITE_LOCK 1#define READ_LOCK  2extern "C"{#if defined (_CYG_THREAD_FAILSAFE) && defined (_MT_SAFE)  void AssertResourceOwner (int, int);#else#define AssertResourceOwner(i,ii)#endif}#ifndef _MT_SAFE#define SetResourceLock(i,n,c)#define ReleaseResourceLock(i,n,c)#else#include <pthread.h>#include <signal.h>#include <pwd.h>#include <grp.h>#define _NOMNTENT_FUNCS#include <mntent.h>extern "C"{struct _winsup_t{  /*     Needed for the group functions   */  struct __group16 _grp;  char *_namearray[2];  int _grp_pos;  /* console.cc */  unsigned _rarg;  /* dlfcn.cc */  int _dl_error;  char _dl_buffer[256];  /* passwd.cc */  struct passwd _res;  char _pass[_PASSWORD_LEN];  int _pw_pos;  /* path.cc */  struct mntent mntbuf;  int _iteration;  DWORD available_drives;  char mnt_type[80];  char mnt_opts[80];  char mnt_fsname[MAX_PATH];  char mnt_dir[MAX_PATH];  /* strerror */  char _strerror_buf[20];  /* sysloc.cc */  char *_process_ident;  int _process_logopt;  int _process_facility;  int _process_logmask;  /* times.cc */  char timezone_buf[20];  struct tm _localtime_buf;  /* uinfo.cc */  char _username[UNLEN + 1];  /* net.cc */  char *_ntoa_buf;  struct protoent *_protoent_buf;  struct servent *_servent_buf;  struct hostent *_hostent_buf;};struct __reent_t{  struct _reent *_clib;  struct _winsup_t *_winsup;};_reent *_reent_clib ();_winsup_t *_reent_winsup ();void SetResourceLock (int, int, const char *) __attribute__ ((regparm (3)));void ReleaseResourceLock (int, int, const char *)  __attribute__ ((regparm (3)));#ifdef _CYG_THREAD_FAILSAFEvoid AssertResourceOwner (int, int);#else#define AssertResourceOwner(i,ii)#endif}class per_process;class pinfo;class ResourceLocks{public:  ResourceLocks ()  {  }  LPCRITICAL_SECTION Lock (int);  void Init ();  void Delete ();#ifdef _CYG_THREAD_FAILSAFE  DWORD owner;  DWORD count;#endifprivate:  CRITICAL_SECTION lock;  bool inited;};#define PTHREAD_MAGIC 0xdf0df045#define PTHREAD_MUTEX_MAGIC PTHREAD_MAGIC+1#define PTHREAD_KEY_MAGIC PTHREAD_MAGIC+2#define PTHREAD_ATTR_MAGIC PTHREAD_MAGIC+3#define PTHREAD_MUTEXATTR_MAGIC PTHREAD_MAGIC+4#define PTHREAD_COND_MAGIC PTHREAD_MAGIC+5#define PTHREAD_CONDATTR_MAGIC PTHREAD_MAGIC+6#define SEM_MAGIC PTHREAD_MAGIC+7#define PTHREAD_ONCE_MAGIC PTHREAD_MAGIC+8;/* verifyable_object should not be defined here - it's a general purpose class */class verifyable_object{public:  long magic;  verifyable_object (long);  virtual ~verifyable_object ();};typedef enum{  VALID_OBJECT,  INVALID_OBJECT,  VALID_STATIC_OBJECT} verifyable_object_state;verifyable_object_state verifyable_object_isvalid (void const *, long);verifyable_object_state verifyable_object_isvalid (void const *, long, void *);/* interface */template <class ListNode> class List {public:  List();  void Insert (ListNode *aNode);  ListNode *Remove ( ListNode *aNode);  ListNode *Pop ();  void forEach (void (*)(ListNode *aNode));protected:  ListNode *head;};class pthread_key:public verifyable_object{public:  static bool isGoodObject (pthread_key_t const *);  static void runAllDestructors ();  DWORD dwTlsIndex;  int set (const void *);  void *get () const;  pthread_key (void (*)(void *));  ~pthread_key ();  static void fixup_before_fork();  static void fixup_after_fork();  /* List support calls */  class pthread_key *next;private:  // lists of objects. USE THREADSAFE INSERTS AND DELETES.  static List<pthread_key> keys;  static void saveAKey (pthread_key *);  static void restoreAKey (pthread_key *);  static void destroyAKey (pthread_key *);  void saveKeyToBuffer ();  void recreateKeyFromBuffer ();  void (*destructor) (void *);  void run_destructor ();  void *fork_buf;};/* implementation */template <class ListNode>List<ListNode>::List<ListNode> () : head(NULL){}template <class ListNode> voidList<ListNode>::Insert (ListNode *aNode){  if (!aNode)  return;  aNode->next = (ListNode *) InterlockedExchangePointer (&head, aNode);}template <class ListNode> ListNode *List<ListNode>::Remove ( ListNode *aNode){  if (!aNode)  return NULL;  if (!head)  return NULL;  if (aNode == head)  return Pop ();  ListNode *resultPrev = head;  while (resultPrev && resultPrev->next && !(aNode == resultPrev->next))  resultPrev = resultPrev->next;  if (resultPrev)  return (ListNode *)InterlockedExchangePointer (&resultPrev->next, resultPrev->next->next);  return NULL;}template <class ListNode> ListNode *List<ListNode>::Pop (){  return (ListNode *) InterlockedExchangePointer (&head, head->next);}/* poor mans generic programming. */template <class ListNode> voidList<ListNode>::forEach (void (*callback)(ListNode *)){  ListNode *aNode = head;  while (aNode)  {    callback (aNode);    aNode = aNode->next;  }}class pthread_attr:public verifyable_object{public:  static bool isGoodObject(pthread_attr_t const *);  int joinable;  int contentionscope;  int inheritsched;  struct sched_param schedparam;  size_t stacksize;  pthread_attr ();  ~pthread_attr ();};class pthread_mutexattr:public verifyable_object{public:  static bool isGoodObject(pthread_mutexattr_t const *);  int pshared;  int mutextype;  pthread_mutexattr ();  ~pthread_mutexattr ();};class pthread_mutex:public verifyable_object{public:  static bool isGoodObject(pthread_mutex_t const *);  static bool isGoodInitializer(pthread_mutex_t const *);  static bool isGoodInitializerOrObject(pthread_mutex_t const *);  static bool isGoodInitializerOrBadObject (pthread_mutex_t const *mutex);  static void initMutex ();  static int init (pthread_mutex_t *, const pthread_mutexattr_t *);  CRITICAL_SECTION criticalsection;  HANDLE win32_obj_id;  LONG condwaits;  int pshared;  class pthread_mutex * next;  int Lock ();  int TryLock ();  int UnLock ();  void fixup_after_fork ();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -