Changeset 12040
- Timestamp:
- 07/12/09 18:36:47 (14 years ago)
- Location:
- trunk/abcl/src/org/armedbear/lisp
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/src/org/armedbear/lisp/LispThread.java
r12030 r12040 1013 1013 // ### make-thread 1014 1014 private static final Primitive MAKE_THREAD = 1015 new Primitive("make-thread", PACKAGE_ EXT, true, "function &key name")1015 new Primitive("make-thread", PACKAGE_THREADS, true, "function &key name") 1016 1016 { 1017 1017 @Override … … 1039 1039 // ### threadp 1040 1040 private static final Primitive THREADP = 1041 new Primitive("threadp", PACKAGE_ EXT, true, "object",1041 new Primitive("threadp", PACKAGE_THREADS, true, "object", 1042 1042 "Boolean predicate as whether OBJECT is a thread.") 1043 1043 { … … 1051 1051 // ### thread-alive-p 1052 1052 private static final Primitive THREAD_ALIVE_P = 1053 new Primitive("thread-alive-p", PACKAGE_ EXT, true, "thread",1053 new Primitive("thread-alive-p", PACKAGE_THREADS, true, "thread", 1054 1054 "Boolean predicate whether THREAD is alive.") 1055 1055 { … … 1070 1070 // ### thread-name 1071 1071 private static final Primitive THREAD_NAME = 1072 new Primitive("thread-name", PACKAGE_ EXT, true, "thread",1072 new Primitive("thread-name", PACKAGE_THREADS, true, "thread", 1073 1073 "Return the name of THREAD if it has one.") 1074 1074 { … … 1114 1114 // ### mapcar-threads 1115 1115 private static final Primitive MAPCAR_THREADS = 1116 new Primitive("mapcar-threads", PACKAGE_ EXT, true, "function",1116 new Primitive("mapcar-threads", PACKAGE_THREADS, true, "function", 1117 1117 "Applies FUNCTION to all existing threads.") 1118 1118 { … … 1135 1135 // ### destroy-thread 1136 1136 private static final Primitive DESTROY_THREAD = 1137 new Primitive("destroy-thread", PACKAGE_ EXT, true, "thread",1137 new Primitive("destroy-thread", PACKAGE_THREADS, true, "thread", 1138 1138 "Mark THREAD as destroyed.") 1139 1139 { … … 1159 1159 // order is not guaranteed. 1160 1160 private static final Primitive INTERRUPT_THREAD = 1161 new Primitive("interrupt-thread", PACKAGE_ EXT, true,1161 new Primitive("interrupt-thread", PACKAGE_THREADS, true, 1162 1162 "thread function &rest args", 1163 1163 "Interrupts THREAD and forces it to apply FUNCTION to ARGS.\nWhen the function returns, the thread's original computation continues. If multiple interrupts are queued for a thread, they are all run, but the order is not guaranteed.") … … 1186 1186 // ### current-thread 1187 1187 private static final Primitive CURRENT_THREAD = 1188 new Primitive("current-thread", PACKAGE_ EXT, true, "",1188 new Primitive("current-thread", PACKAGE_THREADS, true, "", 1189 1189 "Returns a reference to invoking thread.") 1190 1190 { … … 1212 1212 }; 1213 1213 1214 static { 1215 //FIXME: this block has been added for pre-0.16 compatibility 1216 // and can be removed the latest at release 0.22 1217 try { 1218 PACKAGE_EXT.export(Symbol.intern("MAKE-THREAD", PACKAGE_THREADS)); 1219 PACKAGE_EXT.export(Symbol.intern("THREADP", PACKAGE_THREADS)); 1220 PACKAGE_EXT.export(Symbol.intern("THREAD-ALIVE-P", PACKAGE_THREADS)); 1221 PACKAGE_EXT.export(Symbol.intern("THREAD-NAME", PACKAGE_THREADS)); 1222 PACKAGE_EXT.export(Symbol.intern("MAPCAR-THREADS", PACKAGE_THREADS)); 1223 PACKAGE_EXT.export(Symbol.intern("DESTROY-THREAD", PACKAGE_THREADS)); 1224 PACKAGE_EXT.export(Symbol.intern("INTERRUPT-THREAD", PACKAGE_THREADS)); 1225 PACKAGE_EXT.export(Symbol.intern("CURRENT-THREAD", PACKAGE_THREADS)); 1226 } 1227 catch (ConditionThrowable ct) { } 1228 } 1229 1214 1230 // ### use-fast-calls 1215 1231 private static final Primitive USE_FAST_CALLS = … … 1223 1239 } 1224 1240 }; 1241 1242 // ### synchronized-on 1243 private static final SpecialOperator SYNCHRONIZED_ON = 1244 new SpecialOperator("synchronized-on", PACKAGE_THREADS, true, 1245 "form &body body") 1246 { 1247 @Override 1248 public LispObject execute(LispObject args, Environment env) 1249 throws ConditionThrowable 1250 { 1251 if (args == NIL) 1252 return error(new WrongNumberOfArgumentsException(this)); 1253 1254 LispThread thread = LispThread.currentThread(); 1255 synchronized (eval(args.car(), env, thread).lockableInstance()) { 1256 return progn(args.cdr(), env, thread); 1257 } 1258 } 1259 }; 1260 1261 // ### object-wait 1262 private static final Primitive OBJECT_WAIT = 1263 new Primitive("object-wait", PACKAGE_THREADS, true, 1264 "object &optional timeout") 1265 { 1266 @Override 1267 public LispObject execute(LispObject object) 1268 throws ConditionThrowable 1269 { 1270 try { 1271 object.lockableInstance().wait(); 1272 } 1273 catch (InterruptedException e) { 1274 currentThread().processThreadInterrupts(); 1275 } 1276 catch (IllegalMonitorStateException e) { 1277 return error(new IllegalMonitorState()); 1278 } 1279 return NIL; 1280 } 1281 1282 @Override 1283 public LispObject execute(LispObject object, LispObject timeout) 1284 throws ConditionThrowable 1285 { 1286 try { 1287 object.lockableInstance().wait(javaSleepInterval(timeout)); 1288 } 1289 catch (InterruptedException e) { 1290 currentThread().processThreadInterrupts(); 1291 } 1292 catch (IllegalMonitorStateException e) { 1293 return error(new IllegalMonitorState()); 1294 } 1295 return NIL; 1296 } 1297 }; 1298 1299 // ### object-notify 1300 private static final Primitive OBJECT_NOTIFY = 1301 new Primitive("object-notify", PACKAGE_THREADS, true, 1302 "object") 1303 { 1304 @Override 1305 public LispObject execute(LispObject object) 1306 throws ConditionThrowable 1307 { 1308 try { 1309 object.lockableInstance().notify(); 1310 } 1311 catch (IllegalMonitorStateException e) { 1312 return error(new IllegalMonitorState()); 1313 } 1314 return NIL; 1315 } 1316 }; 1317 1318 // ### object-notify-all 1319 private static final Primitive OBJECT_NOTIFY_ALL = 1320 new Primitive("object-notify-all", PACKAGE_THREADS, true, 1321 "object") 1322 { 1323 @Override 1324 public LispObject execute(LispObject object) 1325 throws ConditionThrowable 1326 { 1327 try { 1328 object.lockableInstance().notifyAll(); 1329 } 1330 catch (IllegalMonitorStateException e) { 1331 return error(new IllegalMonitorState()); 1332 } 1333 return NIL; 1334 } 1335 }; 1336 1337 1225 1338 } -
trunk/abcl/src/org/armedbear/lisp/compiler-pass1.lisp
r11923 r12040 303 303 (push 'CATCH result) 304 304 (setf (block-form block) result) 305 block)) 306 307 (defun p1-threads-synchronized-on (form) 308 (let* ((synchronized-object (p1 (cadr form))) 309 (body (cddr form)) 310 (block (make-block-node '(THREADS:SYNCHRONIZED-ON))) 311 (*blocks* (cons block *blocks*)) 312 result) 313 (dolist (subform body) 314 (let ((op (and (consp subform) (%car subform)))) 315 (push (p1 subform) result) 316 (when (memq op '(GO RETURN-FROM THROW)) 317 (return)))) 318 (setf (block-form block) 319 (list* 'threads:synchronized-on synchronized-object 320 (nreverse result))) 305 321 block)) 306 322 … … 1041 1057 (THROW p1-throw) 1042 1058 (TRULY-THE p1-truly-the) 1043 (UNWIND-PROTECT p1-unwind-protect))) 1059 (UNWIND-PROTECT p1-unwind-protect) 1060 (THREADS:SYNCHRONIZED-ON 1061 p1-threads-synchronized-on))) 1044 1062 (install-p1-handler (%car pair) (%cadr pair)))) 1045 1063 -
trunk/abcl/src/org/armedbear/lisp/compiler-pass2.lisp
r11962 r12040 1132 1132 190 ; arraylength 1133 1133 191 ; athrow 1134 194 ; monitorenter 1135 195 ; monitorexit 1134 1136 198 ; ifnull 1135 1137 202 ; label … … 7681 7683 (emit-move-from-stack target representation))))) 7682 7684 7685 (defknown p2-threads-synchronized-on (t t) t) 7686 (defun p2-threads-synchronized-on (block target) 7687 (let* ((form (block-form block)) 7688 (*register* *register*) 7689 (object-register (allocate-register)) 7690 (BEGIN-PROTECTED-RANGE (gensym)) 7691 (END-PROTECTED-RANGE (gensym)) 7692 (EXIT (gensym))) 7693 (compile-form (cadr form) 'stack nil) 7694 (emit-invokevirtual +lisp-object-class+ "lockableInstance" nil 7695 +java-object+) ; value to synchronize 7696 (emit 'dup) 7697 (astore object-register) 7698 (emit 'monitorenter) 7699 (label BEGIN-PROTECTED-RANGE) 7700 (compile-progn-body (cddr form) target) 7701 (emit 'goto EXIT) 7702 (label END-PROTECTED-RANGE) 7703 (aload object-register) 7704 (emit 'monitorexit) 7705 (emit 'athrow) 7706 7707 (label EXIT) 7708 (aload object-register) 7709 (emit 'monitorexit) 7710 (push (make-handler :from BEGIN-PROTECTED-RANGE 7711 :to END-PROTECTED-RANGE 7712 :code END-PROTECTED-RANGE 7713 :catch-type 0) *handlers*))) 7714 7715 7683 7716 (defknown p2-catch-node (t t) t) 7684 7717 (defun p2-catch-node (block target) … … 7886 7919 ((equal (block-name form) '(PROGV)) 7887 7920 (p2-progv-node form target representation)) 7921 ((equal (block-name form) '(THREADS:SYNCHRONIZED-ON)) 7922 (p2-threads-synchronized-on form target) 7923 (fix-boxing representation nil)) 7888 7924 (t 7889 7925 (p2-block-node form target representation)))) -
trunk/abcl/src/org/armedbear/lisp/jvm.lisp
r11990 r12040 421 421 (let ((name (block-name object))) 422 422 (or (equal name '(CATCH)) 423 (equal name '(UNWIND-PROTECT))))) 423 (equal name '(UNWIND-PROTECT)) 424 (equal name '(THREADS:SYNCHRONIZED-ON))))) 424 425 425 426 -
trunk/abcl/src/org/armedbear/lisp/precompiler.lisp
r11996 r12040 489 489 (cons 'PROGN (mapcar #'precompile1 body))))) 490 490 491 (defun precompile-threads-synchronized-on (form) 492 (cons 'threads:synchronized-on (mapcar #'precompile1 (cdr form)))) 493 491 494 (defun precompile-progv (form) 492 495 (if (< (length form) 3) … … 994 997 (THE precompile-the) 995 998 (THROW precompile-cons) 996 (TRULY-THE precompile-truly-the))) 999 (TRULY-THE precompile-truly-the) 1000 1001 (THREADS:SYNCHRONIZED-ON 1002 precompile-threads-synchronized-on))) 997 1003 (install-handler (first pair) (second pair)))) 998 1004
Note: See TracChangeset
for help on using the changeset viewer.