Changeset 888
- Timestamp:
- 04/05/08 19:28:16 (5 months ago)
- Files:
-
- trunk/rebuild/Makefile (modified) (3 diffs)
- trunk/rebuild/deps (modified) (1 diff)
- trunk/rebuild/mars.c (modified) (11 diffs)
- trunk/rebuild/mars.h (modified) (1 diff)
- trunk/rebuild/mem.c (modified) (14 diffs)
- trunk/rebuild/nprocs.c (added)
- trunk/rebuild/nprocs.h (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/rebuild/Makefile
r887 r888 5 5 6 6 GC=-Wl,-Bstatic,-lgc,-Bdynamic 7 THREADS=-pthread 7 8 8 9 EXEEXT= 9 10 10 11 LDFLAGS= 11 LIBS=$(GC) 12 LIBS=$(GC) $(THREADS) 12 13 13 14 PREFIX=/usr … … 59 60 module.o \ 60 61 mtype.o \ 62 nprocs.o \ 61 63 opover.o \ 62 64 optimize.o \ … … 79 81 80 82 rebuild$(EXEEXT): id.c id.h impcnvtab.c $(OBJS) 81 $(CXX) $(CXXFLAGS) $(LDFLAGS) $( LIBS) $(OBJS) -o rebuild$(EXEEXT)83 $(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) -o rebuild$(EXEEXT) 82 84 83 85 id.o: id.c trunk/rebuild/deps
r887 r888 119 119 id.h enum.h import.h aggregate.h hdrgen.h 120 120 choosedc.o: choosedc.c whereami.h 121 nprocs.o: nprocs.c 121 122 whereami.o: whereami.c 122 123 opover.o: opover.c mem.h mtype.h root.h dchar.h gnuc.h stringtable.h \ trunk/rebuild/mars.c
r884 r888 21 21 #include <sys/types.h> 22 22 23 #include <pthread.h> 24 #include "gc/gc.h" 25 23 26 #if _WIN32 24 27 #include <windows.h> … … 41 44 #include "module.h" 42 45 #include "mtype.h" 46 #include "nprocs.h" 43 47 #include "response.h" 44 48 #include "id.h" … … 95 99 this->filename = mod ? mod->srcfile->toChars() : NULL; 96 100 } 101 102 /* 103 * Support for grouped compilation 104 */ 105 class GroupedCompile { 106 public: 107 Array imodules, ofiles; 108 Array origonames, newonames; 109 }; 110 Array GroupedCompiles; 111 unsigned int curcompile = 0; 112 pthread_mutex_t compilemutex; 113 void *compileThread(void *); 114 97 115 98 116 /************************************** … … 250 268 int argcstart = argc; 251 269 270 mem.init(); 271 252 272 // Check for malformed input 253 273 if (argc < 1 || !argv) … … 281 301 global.params.clean = 0; 282 302 global.params.oneatatime = 0; 303 global.params.procs = 0; 283 304 global.params.reflect = 0; 284 305 global.params.candydoc = 0; … … 900 921 global.params.candydoc = 1; 901 922 } 923 else if (p[1] == 'j') 924 { 925 global.params.procs = atoi(p + 2); 926 } 902 927 else if (strncmp(p + 1, "dc=", 3) == 0) {} 903 928 else if (strncmp(p + 1, "CFPATH", 6) == 0 || … … 914 939 compileFlags += " "; 915 940 compileFlags += p; 941 linkFlags += " "; 942 linkFlags += p; 943 shliblinkFlags += " "; 944 shliblinkFlags += p; 916 945 continue; 917 946 … … 1023 1052 masterConfig[sect].find("oneatatime") != masterConfig[sect].end() && 1024 1053 masterConfig[sect]["oneatatime"] != "no") { 1054 global.params.oneatatime = 1; 1055 } 1056 1057 // and how many processes to use 1058 if (global.params.procs == 0) { 1059 global.params.procs = nprocs(); 1060 if (global.params.procs > 1) 1061 global.params.procs *= 2; 1062 } 1063 if (global.params.procs > 1) { 1025 1064 global.params.oneatatime = 1; 1026 1065 } … … 1300 1339 fatal();*/ 1301 1340 1302 class GroupedCompile {1303 public:1304 Array imodules, ofiles;1305 Array origonames, newonames;1306 };1307 Array GroupedCompiles;1308 1341 GroupedCompiles.push((void *) new GroupedCompile); 1309 1342 … … 1627 1660 mem.fullcollect(); 1628 1661 1629 // Now do the actual compilation 1630 for (unsigned int j = 0; global.params.obj && j < GroupedCompiles.dim; j++) { 1631 GroupedCompile *gc = (GroupedCompile *) GroupedCompiles.data[j]; 1632 1633 if (gc->imodules.dim == 0) continue; 1634 1635 // make a string of the file names 1636 std::string infiles; 1637 for (unsigned int k = 0; k < gc->imodules.dim; k++) { 1638 Module *m = (Module *) gc->imodules.data[k]; 1639 infiles += m->srcfile->name->str; 1640 infiles += " "; 1662 // Now do the actual compilation, across any number of processors 1663 if (global.params.procs > 1) { 1664 pthread_t threads[global.params.procs]; 1665 pthread_mutex_init(&compilemutex, NULL); 1666 1667 for (unsigned int j = 0; j < global.params.procs; j++) { 1668 pthread_create(&(threads[j]), NULL, compileThread, NULL); 1641 1669 } 1642 1643 // then compile 1644 runCompile(infiles); 1645 1646 // and rename 1647 for (unsigned int k = 0; k < gc->origonames.dim; k++) { 1648 if (global.params.listonly) { 1649 printf("mv -f %s %s\n", 1650 gc->origonames.data[k], gc->newonames.data[k]); 1651 1652 } else { 1653 if (access((char *) gc->origonames.data[k], F_OK) == 0) { 1654 if (global.params.verbose) 1655 printf("rename %s to %s\n", 1656 (char *) gc->origonames.data[k], 1657 (char *) gc->newonames.data[k]); 1658 1659 remove((char *) gc->newonames.data[k]); // ignore errors 1660 rename((char *) gc->origonames.data[k], 1661 (char *) gc->newonames.data[k]); // ignore errors 1662 } 1663 } 1670 for (unsigned int j = 0; j < global.params.procs; j++) { 1671 pthread_join(threads[j], NULL); 1664 1672 } 1673 } else { 1674 compileThread(NULL); 1665 1675 } 1666 1676 … … 1711 1721 1712 1722 return status; 1723 } 1724 1725 /* 1726 * The thread in which actual compilation is performed 1727 */ 1728 void *compileThread(void *ignore) 1729 { 1730 pthread_mutex_lock(&compilemutex); 1731 int tnum = rand(); 1732 while (curcompile < GroupedCompiles.dim) { 1733 GroupedCompile *gc = (GroupedCompile *) GroupedCompiles.data[curcompile]; 1734 curcompile++; 1735 pthread_mutex_unlock(&compilemutex); 1736 1737 if (gc->imodules.dim == 0) { 1738 pthread_mutex_lock(&compilemutex); 1739 continue; 1740 } 1741 1742 // make a string of the file names 1743 std::string infiles; 1744 for (unsigned int k = 0; k < gc->imodules.dim; k++) { 1745 Module *m = (Module *) gc->imodules.data[k]; 1746 infiles += m->srcfile->name->str; 1747 infiles += " "; 1748 } 1749 1750 // if we only have one file, just rename on the fly 1751 if (gc->imodules.dim == 1) { 1752 infiles += std::string("-of") + ((char *) gc->newonames.data[0]) + " "; 1753 } 1754 1755 // then compile 1756 runCompile(infiles); 1757 1758 // and rename 1759 if (gc->imodules.dim > 1) { 1760 for (unsigned int k = 0; k < gc->origonames.dim; k++) { 1761 if (global.params.listonly) { 1762 printf("mv -f %s %s\n", 1763 gc->origonames.data[k], gc->newonames.data[k]); 1764 1765 } else { 1766 if (access((char *) gc->origonames.data[k], F_OK) == 0) { 1767 if (global.params.verbose) 1768 printf("rename %s to %s\n", 1769 (char *) gc->origonames.data[k], 1770 (char *) gc->newonames.data[k]); 1771 1772 remove((char *) gc->newonames.data[k]); // ignore errors 1773 rename((char *) gc->origonames.data[k], 1774 (char *) gc->newonames.data[k]); // ignore errors 1775 } 1776 } 1777 } 1778 } 1779 1780 pthread_mutex_lock(&compilemutex); 1781 } 1782 pthread_mutex_unlock(&compilemutex); 1713 1783 } 1714 1784 trunk/rebuild/mars.h
r840 r888 54 54 char clean; // clean after building 55 55 char oneatatime; // don't pass multiple files into the compiler 56 unsigned char procs;// number of processes to run concurrently 56 57 char reflect; // use drefgen 57 58 char candydoc; // generate modules.ddoc trunk/rebuild/mem.c
r272 r888 1 1 2 2 /* Copyright (c) 2000 Digital Mars */ 3 /* All Rights Reserved*/3 /* Copyright (c) 2008 Gregor Richards */ 4 4 5 5 #include <stdio.h> … … 7 7 #include <string.h> 8 8 9 #include "gc/gc.h" 10 9 11 #include "mem.h" 10 11 /* This implementation of the storage allocator uses the standard C allocation package.12 */13 12 14 13 Mem mem; … … 16 15 void Mem::init() 17 16 { 17 GC_INIT(); 18 18 } 19 19 … … 24 24 if (s) 25 25 { 26 p = ::strdup(s);26 p = GC_strdup(s); 27 27 if (p) 28 28 return p; … … 39 39 else 40 40 { 41 p = ::malloc(size);41 p = GC_malloc(size); 42 42 if (!p) 43 43 error(); … … 53 53 else 54 54 { 55 p = ::calloc(size, n); 55 //p = ::calloc(size, n); 56 p = GC_malloc(size*n); 57 memset(p, 0, size*n); 56 58 if (!p) 57 59 error(); … … 64 66 if (!size) 65 67 { if (p) 66 { ::free(p);68 { GC_free(p); 67 69 p = NULL; 68 70 } … … 70 72 else if (!p) 71 73 { 72 p = ::malloc(size);74 p = GC_malloc(size); 73 75 if (!p) 74 76 error(); … … 76 78 else 77 79 { 78 p = ::realloc(p, size);80 p = GC_realloc(p, size); 79 81 if (!p) 80 82 error(); … … 86 88 { 87 89 if (p) 88 ::free(p);90 GC_free(p); 89 91 } 90 92 … … 96 98 else 97 99 { 98 p = ::malloc(size);100 p = GC_malloc(size); 99 101 if (!p) 100 102 error(); … … 113 115 void Mem::fullcollect() 114 116 { 117 GC_gcollect(); 115 118 } 116 119 … … 124 127 void * operator new(size_t m_size) 125 128 { 126 void *p = malloc(m_size);129 void *p = GC_malloc(m_size); 127 130 if (p) 128 131 return p; … … 134 137 void operator delete(void *p) 135 138 { 136 free(p);139 GC_free(p); 137 140 } 138 141
